Created
October 5, 2016 20:20
-
-
Save vsemozhetbyt/3ad0378d79b68ea6dd7ebb4144b5137d to your computer and use it in GitHub Desktop.
nomenclature.jsdom.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /******************************************************************************/ | |
| 'use strict'; | |
| /******************************************************************************/ | |
| const jsdom = require('jsdom').jsdom; | |
| const window = jsdom('').defaultView; | |
| const nomenclatureTerms = new Set(); | |
| const nomenclatureChains = new Set(); | |
| const globs = new Map(); | |
| const processedObjects = new Set(); | |
| /******************************************************************************/ | |
| globs.set('window', window); | |
| /******************************************************************************/ | |
| globs.forEach((value, key) => { processKeys(key, value, false); }); | |
| ouput(nomenclatureTerms, 'terms'); | |
| ouput(nomenclatureChains, 'chains'); | |
| console.log(` | |
| Terms: ${nomenclatureTerms.size.toLocaleString()} | |
| Chains: ${nomenclatureChains.size.toLocaleString()} | |
| `); | |
| /******************************************************************************/ | |
| function processKeys(name, obj, hasParent) { | |
| if (!hasParent) { | |
| nomenclatureTerms.add(name); | |
| nomenclatureChains.add(name); | |
| } | |
| processedObjects.add(obj); | |
| Object.getOwnPropertyNames(obj).forEach(prop => { | |
| nomenclatureTerms.add(prop); | |
| const depthName = `${name}[${JSON.stringify(prop)}]`; | |
| nomenclatureChains.add(depthName); | |
| try { | |
| const value = obj[prop]; | |
| if ((value instanceof Object || | |
| typeof value === 'object' && value !== null | |
| ) && | |
| !processedObjects.has(value) | |
| ) { | |
| processKeys(depthName, value, true); | |
| } | |
| } catch (err) { | |
| console.error(err.message); | |
| } | |
| }); | |
| } | |
| /******************************************************************************/ | |
| function ouput(data, type) { | |
| const dataOutput = `${ | |
| [...data] | |
| .sort((a, b) => a.localeCompare(b, 'en', { numeric: true, caseFirst: 'upper' })) | |
| .join('\n') | |
| }\n`; | |
| require('fs').writeFileSync( | |
| `js.nomenclature.jsdom.${type}.txt`, dataOutput, 'utf8' | |
| ); | |
| } | |
| /******************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment