1.0.0 • Published 9 years ago

object-substitute v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

object-substitute

NPM Version NPM Downloads Build Status Test Coverage

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).