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

symbol-tree

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

symbol-tree

Turn any collection of objects into its own efficient tree or linked list using Symbol

  • 3.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is symbol-tree?

The symbol-tree package is a utility library for managing an ordered tree structure with symbols, allowing you to efficiently traverse and manipulate the tree without polluting the objects that make up the nodes of the tree. It is particularly useful when you need to maintain a tree of objects in memory and perform various operations on it without exposing the tree metadata on the objects themselves.

What are symbol-tree's main functionalities?

Creating and managing a tree structure

This feature allows you to create a tree and manage its structure by appending children to parent nodes. The tree structure is maintained internally using symbols.

{"const SymbolTree = require('symbol-tree');\nconst tree = new SymbolTree();\nconst parent = {};\nconst child1 = {};\nconst child2 = {};\ntree.appendChild(parent, child1);\ntree.appendChild(parent, child2);\nconsole.log(tree.firstChild(parent) === child1); // true\nconsole.log(tree.lastChild(parent) === child2); // true"}

Traversing the tree

This feature provides methods to traverse the tree, such as iterating over the children of a node. It allows for efficient tree traversal without exposing the internal structure.

{"const SymbolTree = require('symbol-tree');\nconst tree = new SymbolTree();\nconst parent = {};\nconst child = {};\ntree.appendChild(parent, child);\nfor(const node of tree.childrenIterator(parent)) {\n  console.log(node); // logs the `child` object\n}"}

Manipulating the tree

This feature includes methods to manipulate the tree, such as inserting nodes before or after a given node, which allows for dynamic changes to the tree structure.

{"const SymbolTree = require('symbol-tree');\nconst tree = new SymbolTree();\nconst parent = {};\nconst child = {};\nconst newParent = {};\ntree.appendChild(parent, child);\ntree.insertAfter(child, newParent);\nconsole.log(tree.nextSibling(child) === newParent); // true"}

Other packages similar to symbol-tree

Keywords

FAQs

Package last updated on 12 Jun 2019

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