bury

0.1.0 • Public • Published

bury(obj, keypath, value)

Safely set a dot-notated path within a nested object, return undefined if the full key path does not exist, otherwise return the value set.

Usage

bury(object, keypath, value)

import bury from 'bury';
 
let obj = {
    a: {
        b: {
            c: 1
            d: undefined
            e: null
        }
    }
};
 
//use string dot notation for keys
bury(obj, 'a.b.c', 2) === 2;
 
//or use an array key
bury(obj, ['a', 'b', 'c'], 2) === 2;
 
//returns undefined if the full key path does not exist
bury(obj, 'a.b.c.f', "foo") === undefined;

Tests

https://github.com/kalmbach/bury/blob/master/test.js

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i bury

Weekly Downloads

3

Version

0.1.0

License

MIT

Last publish

Collaborators

  • kalmbach