Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

versatile-tree

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

versatile-tree

A highly versatile tree structure for JavaScript.

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
93
increased by304.35%
Maintainers
1
Weekly downloads
 
Created
Source

🌴 Versatile Tree

A highly versatile tree structure for JavaScript.

npm Version  View project on GitHub  Deploy Status  Sponsor

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!

Buy me a coffee Buy me 3 coffees Buy me 5 coffees

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})

// Convert entire tree to JSON
const treeJson = node.getRoot().toJSON();

// Build tree from JSON
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.

Keywords

FAQs

Package last updated on 18 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc