ntree.js

1.0.1 • Public • Published

NTree

NTree is a JavaScript library for creating and traversing n-ary tree structures.

Installation

Node

NTree is available as an npm module so you can install it with npm install ntree.js and use it in your code:

const ntree = require('ntree.js')

Usage

By importing ntree, you get access to the following classes:

  • Node - For creating and manipulating node objects to be added to a tree
  • TreeUtil - For utility functions necessary to do something to a tree
const {Node, TreeUtil} = require('ntree.js')
:
let aNode = new Node("A")
let bNode = new Node("B")
:
aNode.addChild(bNode)
:

To traverse a tree, get an iterable property of a root node and consume the iterator:

:
let iteratable = TreeUtil.getPreOrderIterable(aNode)
let iterator = iterable[Symbol.iterator]()

console.log(iterator.next())
console.log(iterator.next())
:

Or simply use for of

:
let iterable = TreeUtil.getPreOrderIterable(aNode)
for (node of iterable) {
  console.log(node)
}

As of this version, only getPreOrderIterable() and getDepthFirstIterable() is supported.
Other API add-ons to this library are currently under development.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i ntree.js

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

8.21 kB

Total Files

7

Last publish

Collaborators

  • nitoygo