Install
object-property-extensions
Installation
$ npm install object-property-extensions --save
Usage
import {safeGet, safeSet, hasOwnProperty} from 'object-property-extensions'
const obj = {
a: 1,
b: [{
c: 'd',
e: ['f']
}]
}
hasOwnProperty(obj, 'b.0.c') // true
hasOwnProperty(obj, 'a.1.2') // false
safeGet(obj, 'b.0.c') // 'd'
safeGet(obj, 'a.1.2') // undefined
safeSet(obj, 'b.0.c', 1) // true
safeSet(obj, 'a.1.2', 1) // true
API
hasOwnProperty
Determines whether the ctx contains deeply nested property of the path description
Parameters
ctx
{Object}path
{string|Array}
Returns boolean
safeGet
Safely retrieve the deep nested property of ctx that describe in the path
Parameters
ctx
{Object}path
{string}
Returns any
safeSet
Safely set deeply nested property of ctx that describe in path
Parameters
ctx
path
value
Returns boolean
License
This project is licensed under the MIT license.