dotenv-expand
Advanced tools
Comparing version 0.1.0 to 4.0.0
'use strict' | ||
function expandValue (obj, value) { | ||
var possible = value.substring(1) | ||
// process.env value 'wins' over .env file's value | ||
value = process.env[possible] || obj[possible] || '' | ||
var dotenvExpand = function (config) { | ||
var interpolate = function (env) { | ||
var matches = env.match(/\$([a-zA-Z0-9_]+)|\${([a-zA-Z0-9_]+)}/g) || [] | ||
return value | ||
} | ||
matches.forEach(function (match) { | ||
var key = match.replace(/\$|{|}/g, '') | ||
var expand = function (obj) { | ||
Object.keys(obj).forEach(function (key) { | ||
var value = obj[key] | ||
// process.env value 'wins' over .env file's value | ||
var variable = process.env[key] || config.parsed[key] || '' | ||
if (value.charAt(0) === '$') { | ||
value = expandValue(obj, value) | ||
} | ||
// Resolve recursive interpolations | ||
variable = interpolate(variable) | ||
if (value.substring(0, 2) === '\\$') { | ||
value = value.substring(1) | ||
env = env.replace(match, variable) | ||
}) | ||
return env | ||
} | ||
for (var configKey in config.parsed) { | ||
if (config.parsed[configKey].substring(0, 2) === '\\$') { | ||
config.parsed[configKey] = config.parsed[configKey].substring(1) | ||
} else { | ||
config.parsed[configKey] = interpolate(config.parsed[configKey]) | ||
} | ||
} | ||
obj[key] = value | ||
}) | ||
for (var processKey in config.parsed) { | ||
process.env[processKey] = config.parsed[processKey] | ||
} | ||
Object.keys(obj).forEach(function (key) { | ||
process.env[key] = obj[key] | ||
}) | ||
return obj | ||
return config | ||
} | ||
module.exports = expand | ||
module.exports = dotenvExpand |
{ | ||
"name": "dotenv-expand", | ||
"version": "0.1.0", | ||
"version": "4.0.0", | ||
"description": "Expand environment variables using dotenv", | ||
@@ -19,7 +19,7 @@ "main": "lib/main.js", | ||
"devDependencies": { | ||
"dotenv": "^2.0.0", | ||
"lab": "^7.3.0", | ||
"should": "^7.1.1", | ||
"standard": "^5.4.1" | ||
"dotenv": "^4.0.0", | ||
"lab": "^13.0.1", | ||
"should": "^11.2.1", | ||
"standard": "^9.0.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15974
27
1