0.2.1 • Published 8 years ago

rogain-tree-utils v0.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

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

0.2.1

8 years ago

0.2.0

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago