deeputil
deeputil
is a tiny node.js module that provides a few recursive functions for dealing with keys/values of deeply nested objects.
Install
npm i deeputil
Docs
deeputil.key(obj)
obj
{Object}
@return
{String}
the property name ofobj
const du = var someobj = username: 'foo'console// result -> 'username'
deeputil.keys(obj)
obj
{Object}
@return
{Array<String>}
returns an array of all the keys of obj
no matter how deeply nested!
const du = var someobj = ...consoledirdu
deeputil.vals(obj)
obj
{Object}
@return
{Array<Object>}
returns an array of all the key/value pairs of obj
.
const du = var someobj = ...consoledirdu
deeputil.readStream(obj)
-
obj
{Object}
-
@return
{stream.Readable} a readable stream -
data
{Object}
{key:'', val: }
streams all key/value pairs of obj
const du = var someobj = ... du
deeputil.find(obj, key)
-
obj
{Object}
-
key
{String}
the key to find its corresponding value -
@return
{typeof found value | Array<typeof found value>}
-
if only one item found, returns the found value
-
if more than one item with the same key found (like in an array), returns an array of found values
const du = var someobj = data: username:'plugh' id: 17 username: 'thud' id: 92 baz: qux: garply: 'waldo' quux: 'corge' 'grault' console// result -> { garply: 'waldo', quux: [ 'corge', 'grault' ] } console// result -> waldo console// result -> [ 'corge', 'grault' ] console// result -> [ 'plugh', 'thud' ]