1.0.22 • Published 7 months ago

i-like-bonsai v1.0.22

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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)

Back to TOC

import

tree.import(nodeCollection)

Back to TOC

moveTo

tree.moveTo(nodeId, parentId, adjacentId)

Back to TOC

delete

const errMsg = tree.delete(nodeId)

Back to TOC

getNode

const node = tree.getNode(nodeId)

Back to TOC

getRootNode

const node = tree.getRootNode()

Back to TOC

getPrevNode

const node = tree.getPrevNode(nodeId)

Back to TOC

getNodeByParentIndex

const { nodeId } = tree.getNodeByParentIndex(parentId, parentIndex)

Back to TOC

getPaths

const nodeCollection = tree.getPaths(nodeId)

Back to TOC

getLevel

const level = tree.getLevel(nodeId)

Back to TOC

getDepth

const depth = tree.getDepth(nodeId)

Back to TOC

getIndexNumber

const nodeIndex = tree.getIndexOf(nodeId)

nodeIndex -1 on none exist Back to TOC

getChildren

const nodeCollection = tree.getChildren(nodeId)

Back to TOC

getDescendants

const nodeCollection = tree.getDescendants(nodeId)

Back to TOC

countChilds

const count = tree.countChilds(nodeId)

Back to TOC

toAdjacencyList

const nestedNode = tree.toAdjacencyList(nodeId)
const childNodeCollection = nestedNode.children

Back to TOC

toLinearList

const nodeCollection = tree.toLinearList(nodeId)

Back to TOC

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

MIT

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