1.0.22 • Published 7 months ago
i-like-bonsai v1.0.22
Manipulating hierarchical BST tree
Installation
npm install i-like-bonsai
Usage
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.children
toLinearList
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.
License
1.0.22
7 months ago
1.0.21
7 months ago
1.0.20
7 months ago
1.0.19
7 months ago
1.0.18
7 months ago
1.0.17
7 months ago
1.0.16
7 months ago
1.0.15
7 months ago
1.0.14
7 months ago
1.0.13
7 months ago
1.0.12
7 months ago
1.0.11
7 months ago
1.0.10
7 months ago
1.0.9
7 months ago
1.0.8
7 months ago
1.0.7
7 months ago
1.0.6
7 months ago
1.0.5
7 months ago
1.0.4
7 months ago
1.0.3
7 months ago
1.0.2
7 months ago
1.0.1
7 months ago
1.0.0
7 months ago