Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
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
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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.