0.2.2 • Published 9 years ago

@californian/get-leaf-nodes v0.2.2

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

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' }