Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
trace key-paths through nested objects
JavaScript
Tree: b52f5a6e89

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example
test
.travis.yml
README.markdown
index.js
package.json

README.markdown

pathway

Follow key-paths through nested objects.

build status

example

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 ]

methods

var pathway = require('pathway')

pathway(obj, path)

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

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.

install

With npm do:

npm install pathway

notes

This module was written high up in a tree at Mosswood Park.

Something went wrong with that request. Please try again.