Package Exports
- @ranfdev/deepobj
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ranfdev/deepobj) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
deepobj(action, obj, path)
Get, set, delete or do what you want with a deep object (it keeps the object reference). inspired from dlv and dset
Install:
npm i @ranfdev/deepobj
Examples:
import deepobj from "@ranfdev/deepobj"
const objectToTest = {a: {b: {c: {d: 2}}}}
// define some basic actions
const get = (obj, prop) => obj[prop];
const set = n => (obj, prop) => (obj[prop] = n);
// You can do what you want, even deleting the nested object
const del = (obj, prop) => delete obj[prop];
// use them
deepobj(get, objectToTest, 'a.b.c.d') // 2
deepobj(set(10), objectToTest, 'e.f.g')
console.log(objectToTest.e.f.g) //10
Why i made this
dlv only returns the value of the nested object. I needed a way to get the reference of the nested object