object-funcs
A very limited subset of object functions I use every day
Install
npm i object-funcs
Package on npm
API
defined([arg], [arg], [...])
Return the first defined arg
arg
is considered not defined when
arg
isnull
arg
isundefined
arg
isNaN
const defined = var opts = y:false w:4 // false // 'yes'
merge([obj], [obj], [...])
Merge properties of a Plain Object or a serie of Plain Objects into a new one
const merge = var ref = a:'foo' // {a:'foo', b:'bar'}var obj = // {a:'foo'}ref
Always overwrite properties
const merge = // {a:'foo', b:'baz', c:'quux'}
No deep merge, only first level of properties are injected
const merge = var ref = foo:bar:'baz' // {foo:{bar:'baz'}, a:1} // {foo:{b:2}}
only(obj, keys)
Return a new Plain Object with filtered properties
keys
can be a String or an Array of targeted keys
keys
can also be a RegExp
const only = // {a:1, b:2} // {b:2, c:3} // {bar:1, baz:2}
similar(obj, search)
Partial comparison of two objects
Check if the keys / values in search
are equals in obj
const similar = // true // false // true
Thanks
Mainly forked / inspired on
License
MIT