Socket
Socket
Sign inDemoInstall

@ranfdev/deepobj

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ranfdev/deepobj

get, set, delete deep objects in javascript. Get the last object reference


Version published
Maintainers
1
Install size
3.44 kB
Created

Readme

Source

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

FAQs

Last updated on 07 May 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc