New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

deep-object

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-object

A CRUD API to manipulate objects in depth. Get, Set, Update and Delete functions available.

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
9
-30.77%
Maintainers
1
Weekly downloads
 
Created
Source

deep-object

A CRUD API to manipulate objects in depth. Get, Set, Update and Delete functions available.

Installation

With npm

npm install deep-object

Example

var deepObj = require('deep-object');
var obj = {
  level1:{
    level2:{
      level3:{
        name: "Foo"
      }
    },
    anotherLevel2: "bar"
  }
};

deepObj.get(obj, ["level1", "level2"]); //returns {level3: {name: "Foo"}}

deepObj.set(obj, ["level1", "level2"], "FooBar"); //Sets level2 to "FooBar"

deepObj.remove(obj, ["level1", "level2"]); //Object now becomes, {level1: {}}

API

deepObj.get(object, path);

Gets the value at the given path

  • object is a JS object
  • path is a string array containing keys from outermost to innermost.

deepObj.set(object, path, value);

Sets/updates given value at the path.

  • object is a JS object
  • path is a string array containing keys from outermost to innermost.
  • value is any valid JS variable.

deepObj.remove(object, path);

Removes the given path element.

  • object is a JS object
  • path is a string array containing keys from outermost to innermost.

Note

I needed this for a project. Didn't look through NPM for this. Here is my implementation.

Keywords

Object

FAQs

Package last updated on 24 Jun 2016

Did you know?

Socket

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