environment-configuration-resolver
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -0,0 +0,0 @@ { |
@@ -9,2 +9,3 @@ // | ||
const objectPath = require('object-path'); | ||
const url = require('url'); | ||
@@ -22,4 +23,17 @@ // Configuration Assumptions: | ||
const envProtocol = 'env://'; | ||
const envProtocol = 'env:'; | ||
function getUrlIfEnvironmentVariable(value) { | ||
try { | ||
const u = url.parse(value, true /* parse query string */); | ||
if (u.protocol === envProtocol) { | ||
return u; | ||
} | ||
} | ||
catch (typeError) { | ||
/* ignore */ | ||
} | ||
return undefined; | ||
} | ||
function identifyPaths(node, prefix) { | ||
@@ -37,6 +51,7 @@ prefix = prefix !== undefined ? prefix + '.' : ''; | ||
} | ||
if (!value.startsWith(envProtocol)) { | ||
const envUrl = getUrlIfEnvironmentVariable(value); | ||
if (!envUrl) { | ||
continue; | ||
} | ||
paths[prefix + property] = value.substr(envProtocol.length); | ||
paths[prefix + property] = envUrl; | ||
} | ||
@@ -68,4 +83,17 @@ return paths; | ||
const path = names[i]; | ||
const variableName = paths[path]; | ||
objectPath.set(object, path, provider.get(variableName)); | ||
const parsed = paths[path]; | ||
const variableName = parsed.hostname; | ||
let variableValue = provider.get(variableName); | ||
// Support for default variables | ||
if (variableValue === undefined && parsed.query && parsed.query.default) { | ||
variableValue = parsed.query.default; | ||
} | ||
// Loose equality "true" for boolean values | ||
if (parsed.query && parsed.query.trueIf) { | ||
variableValue = parsed.query.trueIf == /* loose */ variableValue; | ||
} | ||
objectPath.set(object, path, variableValue); | ||
} | ||
@@ -72,0 +100,0 @@ return callback(); |
@@ -0,0 +0,0 @@ MIT License |
{ | ||
"name": "environment-configuration-resolver", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Helpful environment variable resolver for Node.js objects that performs a deep walk looking for a custom env:// scheme", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
# environment-configuration-resolver-node | ||
Helpful environment variable resolver for Node.js objects that performs a deep walk looking for a custom env:// scheme |
Sorry, the diff of this file is not supported yet
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
5898
110