
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
trees-array-based
Advanced tools
The objective of this module is to provide a basic and generic Tree data structure and some of its derivatives.
This module is made using common js.
You can use this module in the following environments:
What you get from this module
The nodes of the tree. You can use this class to create your own Tree structure based on arrays. Its also possible to use objects of this class in the Tree datastructure.
The complexity of dealing with this class is mostly abstracted.
A generic Tree structure. This is the more typical type of trees.
A Tree data structure that provides a hierarchy to the way that nodes are inserted based on the name of the nodes. Example: "father" "father.child" Here father.child is the child of the father and will be inserted as a child of the father node. This Tree does'nt accepts repeated names.
CommonJS
const TreeNode = require("trees-array-based").TreeNode;
const Tree = require("trees-array-based").Tree;
const NameHierarchicalTree = require("trees-array-based").NameHierarchicalTree;
ES6 module syntax
import {TreeNode, Tree, NameHierarchicalTree} from "trees-array-based"
Browser import the min.js file.
<script type="text/javascript" src="trees-array-based.min.js">
TreeNode is a perfectly independent class that can be use to create your own datastructure. TreeNode has mainly tree things:
Methods:
Example:
const TreeNode = require("trees-array-based").TreeNode;
let node1 = new TreeNode("testValue1");
let node2 = new TreeNode("testValue2",1);
let node3 = new TreeNode("testValue3",[1,2,3]);
let node4 = new TreeNode("testValue4");
node1.addChild(node2);
node2.addChild(node3);
node3.addChild(node4);
node2.removeChild(node3);
Tree is the most generic part of this module. It abstracts the work with TreeNodes. Nodes can be repeated.
Methods:
You can use directly TreeNode objects.
const Tree = require("trees-array-based").Tree;
const TreeNode = require("trees-array-based").TreeNode;
let tree = new Tree();
let node1 = new TreeNode("testValue1");
let node2 = new TreeNode("testValue2");
let node3 = new TreeNode("testValue3");
let node4 = new TreeNode("testValue4");
tree.addChild(node1);
tree.addChild(node2);
tree.addChild(node3, node2);
tree.addChild(node4, node2);
tree.addChild(node4, node3);
tree.removeChild(node3);
tree.removeChild("testValue4");
Is also posible to create the children using addChild without importing the TreeNode class. Using names.
const Tree = require("trees-array-based").Tree;
let tree = new Tree();
tree.addChild("node1");
tree.addChild("node2");
tree.addChild("node3", "node2");
tree.addChild("node4", "node2");
tree.addChild("node4", "node3");
tree.removeChild("node3");
tree.removeChild("testValue4");
Avoid using both aproaches as it has not been tested.
NameHierarchicalTree creates a tree based on a hierarchical name structure using a separator of choice. The default separators are dots.
Example
const NameHierarchicalTree = require("trees-array-based").NameHierarchicalTree;
let nameTree = new NameHierarchicalTree("@");
nameTree.addChild("parent");
nameTree.addChild("parent@child1");
Example
parent
This are the children:
parent.child1 parent.child2
Methods:
Example:
const NameHierarchicalTree = require("trees-array-based").NameHierarchicalTree;
let nameTree = new NameHierarchicalTree();
nameTree.addChild("parent");
nameTree.addChild("parent.child1");
nameTree.addChild("parent.child2");
nameTree.removeChild("parent.child1");
nameTree.getChildrenOf("parent");
let treeNode = nameTree.getNode("parent");
FAQs
A trees datastructure based on arrays
We found that trees-array-based demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.