put-value
Update only existing values from an object, works with dot notation paths like
a.b.c
and support deep nesting.
Features
- updates value of
key
only ifkey
exists - updates only existing values of
obj
when object is given tokey
- because
set-value
update values if exist and add if not exist - returns original object if
key
is not an object or string - returns empty object if
obj
is not an object - returns modified object otherwise
Install
npm i put-value --save
npm test
Usage
For more use-cases see the tests
var put = var obj = a: foo: 'bar' b: bb: 'bbb' //=> empty object {} //=> original `obj`//=> {// a: 'foo',// b: {// bb: 'bbb'// }// } //=> original `obj` //=> original `obj` //=> original `obj`//=> {// a: {// foo: 123// },// b: {// bb: 'bbb'// }// } //=> {// a: {// foo: {// baz: 'aaa'// }// },// b: {// bb: 'bbb'// }// }
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.