
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
tree-data-structure
Advanced tools
javascript library for build tree data structure
npm i tree-data-structure
Browser
import Tree from "tree-data-structure";
const tree = new Tree('root')
tree.add() - add item in treetree.add(data, parent, addAllByOne)
| Argument | Type | Description | Required | Default |
|---|---|---|---|---|
| data | any | Data that the tree node will store | true | - |
| parent | Node | Parent node that will store the new node | true | - |
| addAllByOne | Boolean | If the array is passed and it is true, all items of the array are added as separate nodes | false | false |
The first argument is the data that the tree node will store The second argument is the parent node that will store the new node
import Tree from "tree-data-structure";
const tree = new Tree('root')
tree.add('child', tree.root)
/*
output tree root node
{
data: 'root',
children: [{
data: 'child',
children: []
}]
}
*/
Third argument is optional. If you pass an array of data as the first argument and pass true as the third argument, each element of the array will be added as a separate node
import Tree from "tree-data-structure";
const tree = new Tree('root')
tree.add(['one', 'two', 'three'], tree.root, true)
/*
output tree root node
{
data: 'root',
children: [
{
data: 'one',
children: []
},
{
data: 'two',
children: []
},
{
data: 'three',
children: []
}
]
}
*/
You can pass any type of data.
If you pass Object, his properties overwrite in node
import Tree from "tree-data-structure";
const tree = new Tree('root')
tree.add({ one: 1, two: 2, three: 3 }, tree.root)
/*
output tree root node
{
data: 'root',
children: [
{
one: 1,
two: 2,
three: 3,
children: []
}
]
}
*/
tree.remove() - remove item from treeimport Tree from "tree-data-structure";
const tree = new Tree('root')
const node = tree.add({ one: 1, two: 2, three: 3 }, tree.root)
tree.remove(node)
/*
output tree root node
{
data: 'root',
children: []
}
*/
tree.search() - search in treetree.search(data, options)
| Argument | Type | Description | Required | Default |
|---|---|---|---|---|
| data | any | Data to be found | true | - |
| options | Object | Options for search | false | - |
| Argument | Type | Description | Required | Default |
|---|---|---|---|---|
| key | String | Property key that stores the data to be searched | false | id |
| isDeepSearch | Boolean | use deep search, if true, or breadth search algorithm | false | true |
| onlyFirst | Boolean | search only first match | false | false |
FAQs
build tree data structure for javascript
We found that tree-data-structure 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.