Tree namespace

Work with trees

This is a collection of functions for working with asynchronous trees.

For example, Tree exposes a method isTreelike that tests whether a given object is a tree or can be coerced to one. You can invoke this method via Tree.isTreelike:

$ ori Tree.isTreelike 5
false
$ ori Tree.isTreelike { name: "Alice" }
true

Commands by name #

Tree.addNextPrevious(tree)
Add next/previous fields to the tree’s values
Tree.assign(target, source)
Apply key/values from source to target
Tree.cache(tree, [cache])
Caches values from the tree
Tree.clear(tree)
Remove all values from the tree
Tree.concat(…objs)
Concatenate text and/or trees of text
Tree.constant(value)
Return a deep tree with a single constant value
Tree.deepMap(tree, options)
Map the keys and values of a deep tree
Tree.deepMerge(…trees)
Return a deeply-merged tree
Tree.deepReverse(tree)
Reverse order of keys at all levels of the tree
Tree.deepTake(tree, n)
The first n values from the deep tree
Tree.deepValues(tree)
The in-order leaf values of the tree
Tree.defineds(tree)
Only the defined values of the tree
Tree.entries(tree)
The tree’s [key, value] pairs
Tree.filter(source, options)
Filter the source tree
Tree.first(tree)
The first value in the tree
Tree.forEach(tree, fn)
Apply fn to each (value, key)
Tree.from(object, options)
Create a tree from an object
Tree.fromFn(fn, [keys])
A tree defined by a value function
Tree.globKeys(patterns)
A tree whose keys can include glob wildcard patterns
Tree.group(tree, fn)
A new tree with values grouped by the function
Tree.has(tree, key)
True if key exists in tree
Tree.indent
Tagged template literal for normalizing indentation
Tree.inners(tree)
The tree’s interior nodes
Tree.isAsyncMutableTree(object)
True if object is an async mutable tree
Tree.isAsyncTree(object)
True if object is an async tree
Tree.isTraversable(object)
True if object is traversable
Tree.isTreelike(object)
True if object can be coerced to a tree
Tree.json(obj)
Render the object in JSON format
Tree.keys(tree)
The keys of the tree
Tree.length(tree)
The tree’s size (number of keys)
Tree.map(tree, options)
Create a new tree by mapping keys and/or values
Tree.mapReduce(tree, valueFn, reduceFn)
Map values and reduce them
Tree.mask(source, mask)
Return the source tree with only the keys in the mask
Tree.match(pattern, fn, [keys])
Matches simple patterns or regular expressions
Tree.merge(…trees)
Return a new tree merging the given trees
Tree.paginate(tree, [n])
Group the tree’s values into fixed-size sets
Tree.parent(tree)
The parent of the given tree node
Tree.paths(tree)
Slash-separated paths for the tree’s values
Tree.plain(tree)
Render the tree as a plain JavaScript object
Tree.regExpKeys(tree)
A tree whose keys are regular expression strings
Tree.remove(tree, key)
Remove the value for the key from tree
Tree.reverse(tree)
Reverse the order of the tree’s keys
Tree.root(tree)
The root node of the given tree
Tree.setDeep(target, source)
Applies the source tree to the target
Tree.shuffle(tree)
Shuffle the keys of the tree
Tree.sort(tree, options)
A new tree with its keys sorted
Tree.take(tree, n)
The first n values in the tree
Tree.traverse(tree, …keys)
Return the value at the path of keys
Tree.traverseOrThrow(tree, …keys)
Return the value at the path of keys or throw
Tree.traversePath(tree, path)
Traverse a slash-separated path
Tree.values(tree)
The tree’s values