rogain-tree-utils

0.2.1 • Public • Published

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

Dependents (1)

Package Sidebar

Install

npm i rogain-tree-utils

Weekly Downloads

5

Version

0.2.1

License

MIT

Last publish

Collaborators

  • krambuhl