unbox

1.2.0 • Public • Published

unbox

Get or set values on an object from an array of keys.

Usage

has(object, pathArray/dotNotation)

var has = require('unbox/has');
 
var myObject = {
    a: {
        b: 1
    }
};
 
has(myObject, 'a.b'); // true
// OR
has(myObject, ['a', 'b']); // true
 
has(myObject, 'a.b.c'); // false

get(object, pathArray/dotNotation)

var get = require('unbox/get');
 
var myObject = {
    a: {
        b: 1
    }
};
 
get(myObject, 'a.b'); // 1
// OR
get(myObject, ['a', 'b']); // 1

set(object, pathArray/dotNotation, value)

var set = require('unbox/set');
 
set(myObject, 'a.b.c', 2);
// OR
set(myObject, ['a', 'b', 'c'], 2);

myObject will now be:

{
    a: {
        b: {
            c: 2
        }
    }
}
 

Readme

Keywords

none

Package Sidebar

Install

npm i unbox

Weekly Downloads

447

Version

1.2.0

License

MIT

Unpacked Size

7.85 kB

Total Files

8

Last publish

Collaborators

  • korynunn
  • mattlarner
  • mauricebutler