Natural Pacifist Manatees
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

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

install

npm i rogain-tree-utils

Downloadsweekly downloads

0

version

0.2.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability