Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lodash-flatkeystree

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash-flatkeystree

Recusively get the keys for an object.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Install

npm install lodash-flatkeystree

Purpose

Need a way to get all the key paths in an object? Look no further.

Also ignores circular references in an object.

_.keysDeep(object, [depth = 1])

Arguments
  • object: The object to get keys from
  • depth: The number of circular objects to traverse/include. (default 1)

Use

var _ = require('lodash'), keysDeep = require('lodash-flatkeystree');

_.mixin(keysDeep);

var obj = {
  a: {tree: ['that', 'goes', {deep: '!'}]},
  b: [1,2,3,5,8,13, {another: {key: [13,8,5,3,2,1]}}]
};

_.keysDeep(obj);

[ 'a.tree.0',
  'a.tree.1',
  'a.tree.2.deep',
  'b.0',
  'b.1',
  'b.2',
  'b.3',
  'b.4',
  'b.5',
  'b.6.another.key.0',
  'b.6.another.key.1',
  'b.6.another.key.2',
  'b.6.another.key.3',
  'b.6.another.key.4',
  'b.6.another.key.5' ];

Circular with depth > 1
var circularObj = {
  a: {tree: ['that', 'goes', {deep: '!'}]},
  b: [1,2,3,5,8,13, {another: {key: [13,8,5,3,2,1]}}]
};

circularObj.c = {
  cir: circularObj.a,
  something: 'else'
};

_.keysDeep(circularObj, 2);

[ 'a.tree.0',
  'a.tree.1',
  'a.tree.2.deep',
  'b.0',
  'b.1',
  'b.2',
  'b.3',
  'b.4',
  'b.5',
  'b.6.another.key.0',
  'b.6.another.key.1',
  'b.6.another.key.2',
  'b.6.another.key.3',
  'b.6.another.key.4',
  'b.6.another.key.5',
  'c.cir.tree.0',
  'c.cir.tree.1',
  'c.cir.tree.2.deep',
  'c.something' ]

FAQs

Package last updated on 27 Oct 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