node package manager

@californian/get-leaf-nodes

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