Skip to content
Utilities for Rogain.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.babelrc
.gitignore
.npmignore
LICENSE
README.md
package.json

README.md

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

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.