The HierarchyNode
class represents a node in a hierarchical structure.
npm i hierarchical-node-structure
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);
Creates an instance of HierarchyNode
.
new HierarchyNode(metadata?: T)
metadata
(T, optional): The metadata associated with the node.
Adds a child node to the current node.
addNode(node: HierarchyNode<B>): void
node
(HierarchyNode): The child node to add.
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.