1.0.1 • Published 4 years ago

object-property-extensions v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

object-property-extensions

Travis (.com) Codecov NPM npm npm npm bundle size GitHub last commit

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

src/index.js:16-28

Determines whether the ctx contains deeply nested property of the path description

Parameters

  • ctx {Object}
  • path {string|Array}

Returns boolean

safeGet

src/index.js:38-44

Safely retrieve the deep nested property of ctx that describe in the path

Parameters

  • ctx {Object}
  • path {string}

Returns any

safeSet

src/index.js:55-67

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.