rogain-tree-utils
v0.2.1
Published
Rogain tree utilities
Downloads
16
Maintainers
Readme
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