dot-properties
Get, set, or delete a property from a nested object using a dot path. The module is optimized and extremly fast.
Install
$ npm install dot-properties
Usage
const dp = ; // Getterdp;//=> 'lea' dp;//=> undefined dp;//=> 'default value' // Setterconst obj = foo: bar: 'a';dp;console;//=> {name: {first: 'lea'}} const person = dp;console;//=> {name: {first: 'name.first'}} dp;console;//=> {name: {first: 'lea', middle: 'marie'}} // Hasdp;//=> true // Deleterconst obj = name: first: 'lea';dotProp;console;//=> {name: {}} objname = first: 'lea' middle: 'marie';dotProp;console;//=> {name: {middle: 'marie'}}
API
get(obj, path, [defaultValue])
set(obj, path, value)
Returns the object or false on error.
has(obj, path)
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, using .
to separate each nested key.
Do not use a .
in the key (name).
value
Type: any
Value to set at path
.
defaultValue
Type: any
Default value.
License
MIT © Thor Sedeke