Last active
October 7, 2020 14:16
-
-
Save dkarmalita/7bdc3f20aa269bd918b90709e48285e4 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
@example | |
const { getNodeOptionValue } = require('nodeOptions'); | |
const maxOldSpaceSize = getNodeOptionValue('max_old_space_size'); | |
*/ | |
const parseNodeOptions = () => (!process.env.NODE_OPTIONS ? [] : process.env.NODE_OPTIONS.split(/[=:]/)); | |
const _optionsArr = parseNodeOptions(); | |
const _getOptionsCount = () => (_optionsArr.length ? _optionsArr.length / 2 : 0); | |
const _getOptionName = i => _optionsArr[i * 2]; | |
const _getOptionValue = i => _optionsArr[(i * 2) + 1]; | |
const nodeOptionsCount = _getOptionsCount(); | |
const getOptionsObject = () => { | |
const acc = {}; | |
for (let i = nodeOptionsCount - 1; i >= 0; i--) { | |
acc[_getOptionName(i)] = _getOptionValue(i); | |
} | |
return acc; | |
}; | |
const nodeOptions = getOptionsObject(); | |
const getNodeOptionValue = id => nodeOptions[id] || nodeOptions[`--${id}`]; | |
module.exports = { | |
nodeOptions, | |
nodeOptionsCount, | |
getNodeOptionValue, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment