Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ranfdev/deepobj
get, set, delete deep objects in javascript. Get the last object reference (~130 bytes)
https://github.com/ranfdev/deepobj
Last synced: 24 days ago
JSON representation
get, set, delete deep objects in javascript. Get the last object reference (~130 bytes)
- Host: GitHub
- URL: https://github.com/ranfdev/deepobj
- Owner: ranfdev
- Created: 2018-04-03T12:23:18.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-03T12:32:11.000Z (almost 7 years ago)
- Last Synced: 2024-10-31T14:06:12.540Z (2 months ago)
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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](https://github.com/developit/dlv) and [dset](https://github.com/lukeed/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