Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var isValid = ('undefined'!==typeof currVal && null!==currVal);
// invalid value found and no default value, then we throw an error
if (!isValid && typeof defaultValue === 'undefined' && !fromEnv) {
debug('Var statuses ','!isValid',!isValid,'typeof defaultValue',
typeof defaultValue, '!fromEnv',!fromEnv);
throw new Error('No config value found for: '+propertyName);
}
// either return found value or default
if (!fromEnv) {
debug('Propery '+envPropName+' gotten from config file: ',(isValid ? currVal : defaultValue));
return isValid ? currVal : defaultValue;
} else {
debug('Attempting to coercion checks.');
if (is.num(currVal)) {
debug('Coercing env '+envPropName+' to a numeric.');
return Number(envStr);
} else if (is.array(currVal)) {
debug('Coercing env '+envPropName+' to an array.');
if (/^\[(.)*\]$/.match(envStr)) {
envStr = envStr.substr(1); // remove '['
envStr = envStr.substring(0, envStr.length-1);
var elems = envStr.split(',');
for (var i=0; i