node-object-field-resolver
v1.0.3
Published
allows overwrite object fields with value
Downloads
6
Maintainers
Readme
node.js-object-field-resolver
allows overwrite object field value using abstract path, works like Object.assign or object spread into object, but with more complex logic, when the 'path' can be more than one level deep, it do not overwrite arrays in path, it will overwrite primitives and extend objects
how to install
$ npm i node-object-field-resolver
or $ yarn add node-object-field-resolver
software requirements
used technologies
- jest - only for tests
used services
how to execute tests
$ npm test
- to execute tests with coverage
npm test -- --coverage
how to use
/** ES6 */
import resolve from "node-object-field-resolver";
/** commmonjs */
const resolve = require("node-object-field-resolver");
const obj = resolve(
'x.y' /** absolute path */,
{} /** object */,
1 /** value */,
'.' /** delimeter for path [.] is default */
);
/** result: obj ~ {x: { y: 1 } } */
const obj = resolve(
'x.y' /** absolute path */,
{ x: { z: 2 } } /** object */,
1 /** value */,
'.' /** delimeter for path [.] is default */
);
/** result: obj ~ {x: { y: 1, z: 2 } } */
can be used as well as:
const obj = { x: { z: 2 } }
resolve('x.y', obj, 1)
-> as objects are passed as references
-> result: 'obj' will look like { z: { y: 1, z: 2 } }