Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
array-tree-filter
Advanced tools
The array-tree-filter npm package is used to filter tree structures in JavaScript arrays. It allows you to traverse and filter nodes in a tree-like array based on a predicate function.
Filter Tree Nodes
This feature allows you to filter nodes in a tree structure based on a predicate function. In this example, the tree is filtered to include only nodes whose value contains '1'.
const arrayTreeFilter = require('array-tree-filter');
const tree = [
{
value: '1',
children: [
{ value: '1.1', children: [{ value: '1.1.1' }] },
{ value: '1.2' }
]
},
{ value: '2', children: [{ value: '2.1' }] }
];
const result = arrayTreeFilter(tree, (item, level) => item.value.indexOf('1') > -1);
console.log(result);
Lodash is a popular utility library that provides a wide range of functions for manipulating arrays, objects, and other data structures. It includes functions like `_.filter` and `_.map` that can be used to traverse and filter tree structures, although it does not provide a dedicated tree filtering function like array-tree-filter.
Treeify is a library that converts a flat array of nodes into a tree structure. While it focuses on creating tree structures rather than filtering them, it can be used in conjunction with other libraries to achieve similar functionality to array-tree-filter.
Flat-tree is a library for working with binary trees in a flat array representation. It provides functions for traversing and manipulating tree structures, but it is more specialized for binary trees and does not offer the same general-purpose tree filtering capabilities as array-tree-filter.
Filter and traverse nested hierarchical tree structures.
import arrayTreeFilter from 'array-tree-filter';
const data = [{
value: 'a',
children: [{
value: 'b',
children: [{
value: 'c'
}, {
value: 'd',
}]
}],
}];
const values = ['a', 'b', 'c'];
const result = arrayTreeFilter(
data, (item, level) => item.value === values[level]
);
console.log(result);
// [
// { value: 'a', children: [...] },
// { value: 'b', children: [...] },
// { value: 'c', children: [...] }
// ]
FAQs
filter in array tree
The npm package array-tree-filter receives a total of 831,934 weekly downloads. As such, array-tree-filter popularity was classified as popular.
We found that array-tree-filter demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.