Skip to content
Utilities for manipulating and traversing Rogain trees.
Branch: master
Clone or download
Latest commit 02c69be Feb 21, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.babelrc
.gitignore
.npmignore
LICENSE
README.md
package.json

README.md

rogain-tree-utils

Utilities for manipulating and traversing Rogain trees.

splitTree(treeList, match)

Splits an array of trees at matching tree.

treeList

Array of trees.

match

Object.

match is used to segment the input array between each matching tree.

var branches = splitTree(tree.children, {
    type: 'helper',
    name: 'Else'
});

var passing = branches[0];
var failing = branches[1];

note will return an array of tree branches in the format [ [ trees ], [ trees ] ] even on a single tree result like, [ [ tree ] ]

find(treeList, match)

Finds the first tree matching the match object in treeList.

treeList

Array of trees. Haystack of trees.

match

Object. Needle tree.

var res = find(tree.children, { type: 'helper', name: 'Else' });

findAll(treeList, match)

Finds all trees matching the match object in treeList.

treeList

Array of trees. Haystack of trees.

match

Object. Needle tree.

var res = findAll(tree.children, { type: 'tag', tagName: 'a' });

hasChildren(tree)

Predicate, returns true when tree has children.

tree

Tree.

if (hasChildren(tree)) {
    // do children stuff
}

Install

With npm do:

npm install rogain-tree-utils

License

MIT

You can’t perform that action at this time.