Socket
Socket
Sign inDemoInstall

do-deep

Package Overview
Dependencies
8
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    do-deep

Functions to access properties of nested objects


Version published
Maintainers
1
Created

Readme

Source

do-deep Build Status Dependency Status

Functions to access properties of nested objects. Reading and modifying values work very similar to what how things normally work. Things work differently if a property along the path does not exist:

  • dd.get will return undefined
  • dd.set will create the objects it needs to assign the value to the final property

There are two ways to address a property:

  1. By a string, similar to what you'd write in JavaScript. Here, camel-casing is enforced
  2. With an array of property names. Here you can use any kind of strings.

Usage

var dd = require("do-deep")

var someObject = {} // you probably want some data here, but do-deep can live without
var nestedValue = dd.get(someObject, "a.a.a")
var otherNestedValue = dd.get(someObject, ["b"]["b"]["b"])

dd.set(someObject, "a.b.b", "c")
// returns 3, because 3 properties were changed (two objects created, one string assigned)

var nextLetter = {"a":"b"}
dd.set(nextLetter, "a", "b")
// returns 0, to inform that no change was made to the object at all.

There's also increment, decrement.

dd.increment(object, "c.c", 2) increases the value in object.c.c by 2.

License

do-deep is released under the MIT License. Copyright (c) 2017 Braveg1rl

FAQs

Last updated on 16 Feb 2017

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