Tree operation util functions
- Source language is TypeScript
- Unit tests
- Async traversal
traverse(rootNodeOrList, visit, options)
: Traverse all the tree node, likeforEach
method.removeOnce(rootNodeOrList, predict, options): bool
: Find a node, remove it, and stop finding. Returns if found.clone(rootNodeOrList)
: Deep clone a whole tree.pick(rootNodeOrList, [props])
: Deep clone a whole tree.
buildFromList(list, options)
: Convert a list to an tree structure byid
andparentId
props.flatToList(rootNodeOrList, options)
: Convert a tree to an list withid
andparentId
props.wrapListToNode
: Wrap a list to a tree node by assigning it as node children.config(options)
: Returns an object which is the same with initialtreeOp
but with options setting.
childrenKey
: The children prop key, default ischildren
.idKey
: The node id key, default isid
.parentIdKey
: The parent node id prop key, default isparentId
.
MIT