Follow key-paths through nested objects.
var pathway = require('pathway');
var xs = [
{ x : { y : { z : 555 } } },
{ beep : 'boop' },
{ x : { y : { z : 444 } }, w : 4 },
{ x : { y : 'zzz' } },
{ x : { y : { z : 333 } } },
{ X : { y : { z : 222 } } }
];
var ys = pathway(xs, [ true, /x/i, 'y', 'z' ]);
console.dir(ys);
[ 555, 444, 333, 222 ]
var pathway = require('pathway')
Return an array of all the matching paths through the nested object obj
that
match the key path route path
.
Key paths determine how to proceed deeper into the object for each element. Key paths may contain these kinds of elements:
- string, number - used as raw keys
- RegExp - match keys
- boolean - match all or no keys
- function - match keys with
f(key, value)
, return truthiness - array - match any of these strings or regexes
Some types may select multiple matching results at a given node, in which case all the matching nodes at that level will be followed forward into the result until a later condition isn't satisfied.
This behavior is heavily inspired by how
JSONStream's .parse()
function
works.
With npm do:
npm install pathway
This module was written high up in a tree at Mosswood Park.