
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-tools
Advanced tools
Tools to manage deeply nested collection tree structures.
See the API reference for a full list of functionality.
Goals:
Install via
npm install tree-tools
Then just use as
var treeTools = require('tree-tools');
treeTools.flatten(treeTools.find(tree, {path: '/bar/baz'}));
dist/ngTreeTools.js somewhere in your build chainngTreeTools as a module in your main angular.module('app', [modules]) listTreeTools in your controller e.g. app.controller('myController', function($scope, TreeTools) { // Controller // })In all the examples below the example tree structure is similar to the main test case.
Find a single node deeply within a tree structure. Query can be any valid Lodash matching object or a function.
treeTools.find(tree, {path: '/bar/baz'});
Since this function is really just a convenience wrapper around parents() see that function definition for available options.
Return a copy of a tree while filtering nodes. Query can be any valid Lodash matching object or a function.
treeTools.find(tree, (node, index) => matchingExpression);
Options are:
| Option | Type | Default | Description |
|---|---|---|---|
childNode | String or Array | "children" | How to discover child nodes, can be a single key or an array of keys to check |
Return all branches of a tree as a flat array.
The array is returned as a shallow copy, allowing mutation via forEach or map iterators.
treeTools.flatten(treeTools.find(tree, {path: '/bar/baz'}));
Options are:
| Option | Type | Default | Description |
|---|---|---|---|
childNode | String or Array | "children" | How to discover child nodes, can be a single key or an array of keys to check |
Utility function to deep search a tree structure for a matching query and find parents up to the given query. If found this function will return an array of all generations with the found branch as the last element of the array.
treeTools.parents(tree, {path: '/bar/baz'})
Options are:
| Option | Type | Default | Description |
|---|---|---|---|
childNode | String or Array | "children" | How to discover child nodes, can be a single key or an array of keys to check |
Utility function to deep search a tree structure for a matching query and find all children after the given query. If found this function will return an array of all child elements NOT including the query element.
treeTools.children(tree, {path: '/foo'});
Options are:
| Option | Type | Default | Description |
|---|---|---|---|
childNode | String or Array | "children" | How to discover child nodes, can be a single key or an array of keys to check |
Utility function to determines whether a given node has children.
treeTools.hasChildren(someBranch); // Returns a boolean
Options are:
| Option | Type | Default | Description |
|---|---|---|---|
childNode | String or Array | "children" | How to discover child nodes, can be a single key or an array of keys to check |
Utility function to determine if an item matching query exists deep within a given tree.
treeTools.hasSome(tree, {someKey: someValue});
treeTools.hasSome(tree, (v, k) => { ... });
Recursively walk a tree evaluating all functions (promise compatible) and inserting their values. Should a node return a promise it will be waited on before evaluating it along with its children, recursively.
treeTools.resolve(complexTreeWithPromises)
.then(tree => {...})
Options are:
| Option | Type | Default | Description |
|---|---|---|---|
childNode | String or Array | "children" | How to discover child nodes, can be a single key or an array of keys to check |
clone | Boolean | false | Clone the tree before resolving it, this keeps the original intact but costs some time while cloning, without this the input will be mutated |
attempts | Number | 5 | How many times to recurse when resolving promises-within-promises |
isPromise | Function | _.isFunction | Function used to recognise a promise-like return when recursing into promises |
isSplice | Function | See code | Support splicing arrays (arrays are collapsed into their parents rather than returned as is) |
wrapper | Function | Promise.resolve | Wrap the promise in this function before resolving. Called as (nodeFunction, path, tree) |
Utility function to sort tree by specific property or an array of properties.
propertyName can be a string or an array of strings.
// Sort an outer array of families with all children in `name` order
treeTools.sortBy(families, 'name');
FAQs
Tools to manage deeply nested collection tree structures
The npm package tree-tools receives a total of 27 weekly downloads. As such, tree-tools popularity was classified as not popular.
We found that tree-tools 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.