Git Product home page Git Product logo

deep-keys's Introduction

deep-keys

NPM version Build status Test coverage Dependency Status License Downloads

Creates an array composed of the own enumerable property names(including nested) of an object.

Note: This kit works great with obj-parse (get and set object properties in a fast and elegant way).

Install

$ npm install --save deep-keys

Usage

deepKeys(obj, intermediate[optional])
var deepKeys = require('deep-keys');

var obj1 = {
  a: 1,
  b: { c: 1 },
  c: { d: { e: 1 }, f: 1 },
  d: { e: { f: { g: 1, h: 2 } } },
  e: 2,
  f: { g: [] }
};
deepKeys(obj1);
//=> ['a', 'b.c', 'c.d.e', 'c.f', 'd.e.f.g', 'd.e.f.h', 'e', 'f.g']

var obj2 = {
  type: 'customer',
  details: {
    name: 'Ariel', age: 26, address: { city: 'Tel Aviv', country: 'Israel' }
  },
  isActive: true
};
deepKeys(obj2);
//=> ['type', 'details.name', 'details.age', 'details.address.city', 'details.address.country', 'isActive']

// intermediate example
var obj3 = {a:{b:{c:1}}};
deepKeys(obj3);       //=> [ 'a.b.c' ]
deepKeys(obj3, true); //=> [ 'a', 'a.b', 'a.b.c' ]

// Dots in key names get escaped
var obj4 = { 'a.': { b: 1} };
deepKeys(obj4) //=> [ 'a\\..b' ]

License

MIT © Ariel Mashraki

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.