Skip to content

explore-node-js/node.js-object-field-resolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

build coverage coverage

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 } }