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
$ npm i node-object-field-resolver
or $ yarn add node-object-field-resolver
- jest - only for tests
$ npm test
- to execute tests with coverage
npm test -- --coverage
/** 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 } }