@itpropro/tree-structure-ts
v0.5.7
Published
[](https://www.npmjs.com/package/@itpropro/tree-structure-ts)  [
const root = tree.rootTo add a child node to a TreeNode, use the addChild method:
const child1 = root.addChild('child1')
const child2 = root.addChild('child2')To get all nodes in the tree below a TreeNode, use the all method:
const nodes = root.all()To traverse a tree, use the traverse method:
root.traverse((node) => {
// This function is called for each node in the tree
})You can specify the traversal order by passing one of the following values to the traverse method:
- breadthFirst (the default): visits nodes in breadth-first order
- depthFirst: visits nodes in depth-first order
- preOrder: visits the current node, then traverses the left subtree, then traverses the right subtree
- postOrder: traverses the left subtree, then traverses the right subtree, then visits the current node
for all avalaible methods and fields, please read the detailed documentation of the Tree and TreeNode class: Class docs.
Contribution
See Contributing Guide.
License
Made with :heart:
Published under MIT License.
