npm

rogain-utils

0.2.3 • Public • Published

rogain-utils

Utilities for Rogain.

createFrame(tree, locals)

Creates a tree node of the frame type with locals as scope data and tree as children. This represents a new scope, no variables fall through by default – all locals should be manually defined from outside scopes.

var frame = createFrame(tree, locals);
// { type: 'frame', children: tree, locals: locals }

splitTrees(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: 'component',
    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: 'component', 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' });

findPath(tree, match, initialPath)

Returns object path for first tree matching match object. Will treverse deep.

tree

Rogain tree. Haystack.

match

Object. Needle.

initialPath

String. starting path used when building path.

//<Box><div><Block /><Children /></div></Box>
var path = findPath(Box, { name: 'Children' });
// children.0.children.1

hasChildren(tree)

Predicate, returns true when tree has children.

tree

Tree.

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

Install

With npm do:

npm install rogain-utils

License

MIT

Package Sidebar

Install

npm i rogain-utils

Weekly Downloads

0

Version

0.2.3

License

MIT

Last publish

Collaborators

  • krambuhl