Skip to content

The HierarchyNode class represents a node in a hierarchical data structure. Each node can have child nodes and a reference to its parent node. The class provides methods to manipulate and traverse the hierarchy, such as adding nodes, finding nodes by their identifiers, removing nodes, and executing custom functions on nodes.

Alkhioz/hierarchical-node-structure

Repository files navigation

HierarchyNode

The HierarchyNode class represents a node in a hierarchical structure.

Installation

npm i hierarchical-node-structure

Usage

const { HierarchyNode } = require('hierarchy-node');

// Create a root node
const rootNode = new HierarchyNode('Root');

// Add child nodes
const child1 = new HierarchyNode('Child 1');
const child2 = new HierarchyNode('Child 2');
rootNode.addNode(child1);
rootNode.addNode(child2);

API

Constructor

Creates an instance of HierarchyNode.

new HierarchyNode(metadata?: T)
  • metadata (T, optional): The metadata associated with the node.

addNode

Adds a child node to the current node.

addNode(node: HierarchyNode<B>): void
  • node (HierarchyNode): The child node to add.

removeNode

Removes a child node from the current node.

removeNodeById(targetId: string): boolean
  • targetId (string): The internal identifier of the child node to remove.```

Returns:

  • true if the child node was successfully removed.
  • false if the child node was not found.

About

The HierarchyNode class represents a node in a hierarchical data structure. Each node can have child nodes and a reference to its parent node. The class provides methods to manipulate and traverse the hierarchy, such as adding nodes, finding nodes by their identifiers, removing nodes, and executing custom functions on nodes.

Resources

Stars

Watchers

Forks

Packages

No packages published