JSPM

deep-object

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14
  • Score
    100M100P100Q66451F
  • License ISC

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

Package Exports

  • deep-object

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 (deep-object) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.