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.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

#deeputil

travis build 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

deeputil.key(obj)

  • obj {Object}
  • @return {String} the property name of obj
const du = require('deeputil')

var someobj = {username: 'foo'}
console.log(du.key(someobj))
// 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 = require('deeputil')

var someobj = {
  ...
}
console.dir(du.keys(someobj))

deeputil.vals(obj)

  • obj {Object}
  • @return {Array<Object>}

returns an array of all the key/value pairs of obj.

const du = require('deeputil')

var someobj = {
  ...
}
console.dir(du.vals(someobj))

deeputil.readStream(obj)

  • obj {Object}

  • @return {stream.Readable} a readable stream

  • data {Object} {key:'', val: }

streams all key/value pairs of obj

const du = require('deeputil')

var someobj = {
  ...
}

du.readStream(someobj).on('error', (err) => {
  console.error(err)
}).on('data', (dat) => {
  console.log('key:', dat.key)
  console.log('value:', dat.val)
}).on('end', () => {
  console.log('finished successfully.')
})

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 = require('deeputil')

var someobj = {
  data: [{username:'plugh', id: 17}, {username: 'thud', id: 92}],
  baz: {
    qux: {
      garply: 'waldo',
      quux: ['corge', 'grault']
    }
  }
}

console.log(du.find(someobj, 'qux'))
// result -> { garply: 'waldo', quux: [ 'corge', 'grault' ] }

console.log(du.find(someobj, 'garply'))
// result -> waldo

console.log(du.find(someobj, 'quux'))
// result -> [ 'corge', 'grault' ]

console.log(du.find(someobj, 'username'))
// result -> [ 'plugh', 'thud' ]

Keywords

FAQs

Package last updated on 17 Jan 2017

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