replace-path

0.1.1 • Public • Published

replace-path

Replaces nested values in an object.

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

/replace-path/

    Package Sidebar

    Install

    npm i replace-path

    Weekly Downloads

    2

    Version

    0.1.1

    License

    MIT

    Last publish

    Collaborators

    • maliciousintent