0.1.1 • Published 8 years ago

replace-path v0.1.1

Weekly downloads
2
License
MIT
Repository
-
Last release
8 years ago

replace-path

Replaces nested values in an object.

npm.io

npm.io

Examples:

var source = {
  a: '123',
  b: {
    m: '456',
    n: '789'
  },
  d: [{
    x: 'aaa',
    y: 'z'
  }, {
    x: 'bbb',
    y: 'w'
  }]
};
var next1 = replacePath(source, 'a', 'BAR');
var next2 = replacePath(source, 'b.n', 'BAR');
var next3 = replacePath(source, 'd..x', 'BAR');
var next4 = replacePath(source, 'd.1.x', 'BAR');
var next5 = replacePath(source, 'd..x', (source, key, oldValue) => {
  source[key + 'Bar'] = oldValue.toUpperCase();
});

Check index.spec.js for detailed usage.

License

See LICENSE.md

0.1.1

8 years ago

0.0.1

8 years ago