Created
October 5, 2016 21:54
-
-
Save vsemozhetbyt/49ff6e7caea73edd14b3c7c5d42e09b8 to your computer and use it in GitHub Desktop.
nomenclature.jsdom.js (env variant)
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.defaultDocumentFeatures = { | |
| FetchExternalResources: false, | |
| ProcessExternalResources: false | |
| }; | |
| const window = jsdom.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.2.${type}.txt`, dataOutput, 'utf8' | |
| ); | |
| } | |
| /******************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment