@californian/get-leaf-nodes

0.2.2 • Public • Published

get-leaf-nodes

get-leaf-nodes takes in an object or array and, optionally, a parent node and returns an object with a mapping from the leaf nodes to their dot-separated keys.

usage

var getLeafNodes = require("@californian/get-leaf-nodes");

var testObject = {
  a: {
    b: [
      "c", "d", {
        e: ["n", "o"]
      }
    ],
    f: "g"
  },
  h: "i",
  j: {
    k: {
      l: "m"
    }
  }
};

var leafNodes = getLeafNodes(testObject);

console.log(leafNodes);

output

{ c: 'a.b',
  d: 'a.b',
  n: 'a.b.e',
  o: 'a.b.e',
  g: 'a.f',
  i: 'h',
  m: 'j.k.l' }

Readme

Keywords

Package Sidebar

Install

npm i @californian/get-leaf-nodes

Weekly Downloads

1

Version

0.2.2

License

MIT

Last publish

Collaborators

  • californian