#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
a dummy object for use in examples below
var testobj = {
"rname": "gonzo",
"rid": 274,
"rdata": [
{
"username": "",
"email": "",
"msgs": []
},
{
"username": "gonzo",
"email": "gonzoemail",
"msgs": [
{
"msgid": 19,
"msg": "explore your mind",
"sen": "anonym",
"time": ""
}
]
}
],
"complx": {
"somearr": ["wolf", "octopus", "epsilon"],
"langs": {
"js": {
"jsobj": {
"djsobj": {
"ddjsobj": {
"dddjsobj": "alright"
}
}
},
"fun": "for sure"
},
"shell": {
"shellobj": {
"dshellobj": "nice"
}
},
"go": {
"gobj": {
"dgobj": ["pretty", "cool"]
}
}
}
}
}
deeputil.keys(obj)
obj
{Object}
@return
{Array<String>}
returns an array of all the keys of the given object no matter what!
const du = require('deeputil')
console.log(du.keys(testobj))
deeputil.vals(obj)
obj
{Object}
@return
{Array<Object>}
returns an array of all the key/value pairs of the given object.
const du = require('deeputil')
console.log(du.vals(testobj))
deeputil.find(obj, key)
obj
{Object}
object to find items inkey
{String}
the key to find@return
{Array<Object>}
returns an array of results if any, otherwise returns an empty array. If more than one item with the same key found (like in an array), the result array contains all of them.
const du = require('deeputil')
console.log('%j', du.find(testobj, 'djsobj'))
const du = require('deeputil')
console.log(du.find(testobj, 'dgobj'))
const du = require('deeputil')
console.log(du.find(testobj, 'username'))