Manipulating hierarchical BST tree
npm install i-like-bonsai
import bonsai from 'i-like-bonsai'
const tree = await bonsai(rootNodeId)
// or
bonsai(rootNodeId).then((tree) => { /**/ })
const nodeId = bonsai.getNewID()
{
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
}
const { nodeId } = tree.create(parentId)
tree.import(nodeCollection)
tree.moveTo(nodeId, parentId, adjacentId)
const errMsg = tree.delete(nodeId)
const node = tree.getNode(nodeId)
const node = tree.getRootNode()
const node = tree.getPrevNode(nodeId)
const { nodeId } = tree.getNodeByParentIndex(parentId, parentIndex)
const nodeCollection = tree.getPaths(nodeId)
const level = tree.getLevel(nodeId)
const depth = tree.getDepth(nodeId)
const nodeIndex = tree.getIndexOf(nodeId)
nodeIndex -1 on none exist Back to TOC
const nodeCollection = tree.getChildren(nodeId)
const nodeCollection = tree.getDescendants(nodeId)
const count = tree.countChilds(nodeId)
const nestedNode = tree.toAdjacencyList(nodeId)
const childNodeCollection = nestedNode.children
const nodeCollection = tree.toLinearList(nodeId)
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.