1.0.1 • Published 6 years ago
@basekits/kit-object v1.0.1
@basekits/kit-object
Object type helpers kit for basekits.
Install
npm i @basekits/kit-type @basekits/kit-objectUsage
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.
1.0.1
6 years ago