Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
operation-tree-node
Advanced tools
Operation method collection for tree node(like operation array).
npm install --save operation-tree-node
common arguments:
name | type | description |
---|---|---|
data | object[] | example: [{ id: 1, name: "1", children: [{ id: 2, name: "2" }] }] |
callback | (node, index, arr, parent) => object/void | node: tree node, index: parent children's index, arr: parent children, parent: parent node |
props | { children: string, parent: string } | tree node's 'children' and 'parent' name |
examples:
import { treeEach } from "operation-tree-node";
const treeData1 = [{ id: 1, name: "1", children: [{ id: 2, name: "2" }] }];
treeEach(treeData1, (node, index, arr, parent) => {
console.log(node.name, index, arr, parent);
});
// '1', 0, [treeData], undefined
// '2', 0, [treeData[0].children], [treeData[0]]
// use children props
const treeData2 = [{ id: 1, name: "1", child: [{ id: 2, name: "2" }] }];
treeEach(treeData2, console.log, { children: "child" });
import { treeMap } from "operation-tree-node";
const treeData = [{ id: 1, name: "1", children: [{ id: 2, name: "2" }] }];
// tree node's +1
const newData = treeMap(treeData, node => ({
id: node.id + 1,
name: node.name,
...(node.children ? { children: node.children } : {})
}));
console.log(newData);
// [{ id: 2, name: '1', children: [{ id: 3, name: '2' }] }]
import { treeFilter } from "operation-tree-node";
const treeData = [
{ id: 1, name: "1", child: [{ id: 2, name: "2" }] },
{ id: 3, name: "3" }
];
const result = treeFilter(treeData, node => node.id === 2, {
children: "child"
});
console.log(result);
// [{ id: 1, name: '1', child: [{ id: 2, name: '2' }] }]
import { treeToFlatArray } from "operation-tree-node";
const treeData = [{ id: 1, name: "1", children: [{ id: 2, name: "2" }] }];
const result = treeToFlatArray(treeData);
console.log(result);
// [
// { id: 1, name: '1', children: [{ id: 2, name: '2' }] },
// { id: 2, name: '2' }
// ]
arguments:
name | type | description |
---|---|---|
data | (same) | (same) |
callback | (currentNode, nextNode) => boolean | currentNode/nextNode: tree node, compare with them |
props | (same) | (same) |
import { treeMerge } from "operation-tree-node";
const treeData = [
{ id: 1, name: "1", type: "1", children: [{ id: 2, name: "2" }] },
{ id: 3, name: "3", type: "1", children: [{ id: 4, name: "4" }] }
];
const result = treeMerge(
treeData,
(curr, next) => curr.type && curr.type === next.type
);
console.log(result);
// [
// {
// id: 1,
// name: '1',
// type: '1',
// children: [{ id: 2, name: '2' }, { id: 4, name: '4' }]
// }
// ]
arguments:
name | type | description |
---|---|---|
data | (same) | (same) |
callback | (currentNode, nextNode) => number | currentNode/nextNode: tree node, compare with them |
props | (same) | (same) |
const treeData = [
{
id: 1,
name: "1",
children: [{ id: 3, name: "3" }, { id: 2, name: "2" }]
}
];
// 1,3,2 => 1,2,3
const newData = treeSort(
treeData,
(currentNode, nextNode) => currentNode.id - nextNode.id
);
console.log(newData);
// [
// {
// id: 1,
// name: '1',
// children: [{ id: 2, name: '2' }, { id: 3, name: '3' }]
// }
// ]);
FAQs
Operation method collection for tree node(like operation array).
The npm package operation-tree-node receives a total of 56 weekly downloads. As such, operation-tree-node popularity was classified as not popular.
We found that operation-tree-node 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.