i-like-bonsai
v1.0.22
Published
Manipulating hierarchical BST tree structures.
Downloads
15
Maintainers
Readme
Manipulating hierarchical BST tree
Installation
npm install i-like-bonsaiUsage
Instantiate
import bonsai from 'i-like-bonsai'
const tree = await bonsai(rootNodeId)
// or
bonsai(rootNodeId).then((tree) => { /**/ })Generate node ID
const nodeId = bonsai.getNewID()Node object structural
{
id varchar(24) NOT NULL,
root varchar(24) NOT NULL,
parent varchar(24),
left int(11) NOT NULL,
right int(11) NOT NULL,
level int(11) NOT NULL
}API References
create
const { nodeId } = tree.create(parentId)import
tree.import(nodeCollection)moveTo
tree.moveTo(nodeId, parentId, adjacentId)delete
const errMsg = tree.delete(nodeId)getNode
const node = tree.getNode(nodeId)getRootNode
const node = tree.getRootNode()getPrevNode
const node = tree.getPrevNode(nodeId)getNodeByParentIndex
const { nodeId } = tree.getNodeByParentIndex(parentId, parentIndex)getPaths
const nodeCollection = tree.getPaths(nodeId)getLevel
const level = tree.getLevel(nodeId)getDepth
const depth = tree.getDepth(nodeId)getIndexNumber
const nodeIndex = tree.getIndexOf(nodeId)nodeIndex -1 on none exist Back to TOC
getChildren
const nodeCollection = tree.getChildren(nodeId)getDescendants
const nodeCollection = tree.getDescendants(nodeId)countChilds
const count = tree.countChilds(nodeId)toAdjacencyList
const nestedNode = tree.toAdjacencyList(nodeId)
const childNodeCollection = nestedNode.childrentoLinearList
const nodeCollection = tree.toLinearList(nodeId)Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
