🌴 Versatile Tree
A highly versatile tree structure for JavaScript.
Documentation
Read the official documentation.
Overview
This library contains a highly versatile tree structure for JavaScript.
The TreeNode
class is simple yet highly versatile:
- It can store arbitrary
data
and children
and can be constructed from an object. - When not at the root, it can access its siblings, children, and root, and can be searched.
- It can be converted to an object, to JSON, and from JSON easily.
See the Quick Start section below for examples.
Note: A Tree
alias exists for TreeNode
-- in this library, they are interchangeable.
Features include:
- 🌴 Tree structure in JS
- Construct and use tree structures in JavaScript easily.
Donate
If this project helped you, please consider buying me a coffee. Your support is much appreciated!
Table of Contents
Installation
npm i versatile-tree
Quick Start
import { TreeNode, Tree } from 'versatile-tree';
const tree = new Tree();
const node = tree.addChildData({id: 1});
node.addChildData({id: 2});
node.addSiblingData({id: 3})
const treeJson = node.getRoot().toJSON();
const builtTree = TreeNode.fromJSON(treeJson);
TypeScript
Type definitions have been included for TypeScript support.
Icon Attribution
Favicon by Twemoji.
Contributing
Open source software is awesome and so are you. 😎
Feel free to submit a pull request for bugs or additions, and make sure to update tests as appropriate. If you find a mistake in the docs, send a PR! Even the smallest changes help.
For major changes, open an issue first to discuss what you'd like to change.
⭐ Found It Helpful? Star It!
If you found this project helpful, let the community know by giving it a star: 👉⭐
License
See LICENSE.md.