
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
tree-node-utils
Advanced tools
A set of functions for accessing, searching, filtering data nodes in a tree data structure.
A set of functions for accessing, searching, filtering data nodes in a tree data structure.
It works on tree data structures like this:
const tree = [
{
text: 'Computer',
key: 'a',
children: [
{
text: 'Desktop',
key: 'd',
},
{
text: 'Laptop',
key: 'l',
},
{
text: 'Mobile',
key: 'm',
children: [
{
text: 'Smart Phone',
key: 's',
},
{
text: 'Tablet',
key: 't',
children: [
{
text: 'Ipad',
key: 'ip',
},
...
],
},
...
],
},
...
],
},
...
];
And provides the following util functions:
| Name | Description |
|---|---|
hasChildren(node) | Returns if the node has children node. |
isBranch(node) | Returns if the node has children field. This field could be empty; |
getNodeByKey(treeNodes, key) | Returns the data node having the matching 'key' value. |
findNodes(treeNodes, predicate) | Returns a flat array of nodes that pass the predicate(test) function. |
filterNodes(treeNodes, predicate) | Filters the tree data structure with the predicate function. i.e. Return a copy of the data tree with unmatching nodes removed. |
sortNodes(treeNodes, compareFunction) | Sort the treeNodes and children of every data node using the given compare function. |
mapNodes(treeNodes, mapFunction) | Return a new tree after applying a function to every nodes in the original tree. This function is useful for transforming nodes in a tree. mapFunction has the signature of mapFunction(currentNode, parentNode) and should return a new node object. |
renameChildrenFieldForNodes(treeNodes, newChildrenFieldName) | Rename the 'childrenField' (e.g. 'children') to something else; |
Note:
treeNodes parameter is deliberately designed to be an array of nodes, instead of a single node, to provide more flexibility. The process a single root node tree, wrap the root node in an array.predicate is a callback function to test each node, including any children nodes of the tree. Return true to keep the node, false otherwise;compareFunction is the same function used by Array.sort;All the callback functions (predicate, compareFunction and mapFunction) will receive the parents as the last parameters, containing the ancestors as an array.
npm install tree-node-utils --save
import TreeNodeUtils from 'tree-node-utils';
const config = {
childrenField: 'children', // e.g. customise the field for children nodes. e.g. 'subItems', default 'children'
keyField: 'key', // e.g. customise the field for node key. e.g. 'id', default 'key'
};
const treeNodeUtils = new TreeNodeUtils(config);
const node = treeNodeUtils.getNodeByKey(treeNodes, 'ip');
...
FAQs
A set of functions for accessing, searching, filtering data nodes in a tree data structure.
The npm package tree-node-utils receives a total of 21 weekly downloads. As such, tree-node-utils popularity was classified as not popular.
We found that tree-node-utils 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.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.