@basekits/kit-object

1.0.1 • Public • Published

@basekits/kit-object

Object type helpers kit for basekits.

Install

npm i @basekits/kit-type @basekits/kit-object

Usage

const kit = require('@basekits/core')
const type = require('@basekits/kit-type')
const object = require('@basekits/kit-object')
kit.addKit(type)
kit.addKit(object)

Available Items

The following methods will be available after adding this kit:

.getProp(obj, path, defaultValue = undefined)

Returns the value of the property specified in path inside an object obj. The defaultValue will be returned if obj doesn't have a such path.

const obj = {
  name: 'Murat',
  address: {
    country: 'TR'
  }
}
kit.getProp(obj, 'name') // returns 'Murat'
kit.getProp(obj, ['address', 'country']) // returns 'TR'
kit.getProp(obj, 'nonExistingProp', 'none') // returns 'none'

.removeProp(obj, prop)

Returns a new object by removing its prop property. Returns input object if it doesn't have a prop or returns undefined if obj is not an object.


Readme

Keywords

Package Sidebar

Install

npm i @basekits/kit-object

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

7.06 kB

Total Files

9

Last publish

Collaborators

  • npm-support