Get, set, or delete a property from a nested object using a dot path MAIN DIFFERENCE FROM sindresorhus/dot-prop is that it will not throw errors when you do get({ a: null }, 'a.b.c')
Install
$ npm install --save dot-prop
Usage
const dotProp = ; // getterdotProp;//=> 'unicorn' dotProp;//=> undefined dotProp;//=> 'unicorn' // setterconst obj = foo: bar: 'a';dotProp;console;//=> {foo: {bar: 'b'}} dotProp;console;//=> {foo: {bar: 'b', baz: 'x'}} // deleterconst obj = foo: bar: 'a';dotProp;console;//=> {foo: {}} objfoobar = x: 'y' y: 'x';dotProp;console;//=> {foo: {bar: {y: 'x'}}}
API
get(obj, path)
set(obj, path, value)
delete(obj, path)
obj
Type: object
Object to get, set, or delete the path
value.
path
Type: string
Path of the property in the object. Use .
for nested objects or \\.
to add a .
in a key.
value
Type: any
Value to set at path
.
License
MIT © Sindre Sorhus