object-substitute
v1.0.0
Published
Substitute the values of object properties based on prefixes
Downloads
3
Readme
object-substitute
Recursively performs substitution of object properties where the value is a string with a prefix in the form env:
. Environment variables are recognized automatically, but custom substitution families can also be defined.
Installation
npm install object-substitute
Usage
var substitute = require('object-substitute');
var source = {
key1: 'env:SOME_VAR',
key2: {
nested1: false,
nested2: 'user:name'
},
key3: 4
};
process.env.SOME_VAR = 'hello';
var substitutes = {
user: req.user
};
substitute(source, substitutes);
Returns:
{
key1: 'hello',
key2: {
nested1: false,
nested2: 'Bob'
},
key3: 4
}
License
Licensed under the MIT license. See (http://opensource.org/licenses/MIT).