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