New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

deeputil

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deeputil

tiny recursive utility to deal with keys/values of deeply nested objects

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

#deeputil

travis npm

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))
/* will return
	["rname","rid","rdata","username","email","msgs","msgid",
   "msg","sen","time","complx","somearr","langs","js","jsobj",
   "djsobj","ddjsobj","dddjsobj","fun","shell","shellobj",
   "dshellobj","go","gobj","dgobj"]
*/

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 in
  • key {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')

// find 'ddjsobj'
console.log('%j', du.find(testobj, 'djsobj'))
/* will return 
  [{"djsobj":{"ddjsobj":{"dddjsobj":"alright"}}}]
*/
const du = require('deeputil')

// find 'dgobj'
console.log(du.find(testobj, 'dgobj'))
/* will return 
  [ { dgobj: [ 'pretty', 'cool' ] } ]
*/
const du = require('deeputil')

// find 'username'
console.log(du.find(testobj, 'username'))
/* will return 
  [ { username: '' }, { username: 'gonzo' } ]
*/

Keywords

FAQs

Package last updated on 07 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc