object-substitute

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i object-substitute

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • dvonlehman