Gathering detailed insights and metrics for unist-util-reduce
Gathering detailed insights and metrics for unist-util-reduce
Gathering detailed insights and metrics for unist-util-reduce
Gathering detailed insights and metrics for unist-util-reduce
npm install unist-util-reduce
Typescript
Module System
TypeScript (87.3%)
JavaScript (12.7%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
5 Stars
22 Commits
1 Forks
9 Branches
1 Contributors
Updated on May 24, 2025
Latest Version
0.2.2
Package Id
unist-util-reduce@0.2.2
Unpacked Size
5.80 kB
Size
2.82 kB
File Count
7
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
unist utility to recursively reduce a tree
npm:
1npm install unist-util-reduce
1const u = require("unist-builder"); 2const reduce = require("unist-util-reduce"); 3const assert = require("assert"); 4 5const tree = u("tree", [ 6 u("leaf", "1"), 7 u("node", [u("leaf", "2")]), 8 u("void"), 9 u("leaf", "3") 10]); 11 12const newTree = reduce(tree, function(node) { 13 if (node.value === "2") { 14 const duplicateNode = { ...node, value: "two" }; 15 return [duplicateNode, node]; 16 } 17 return node; 18}); 19 20const expected = u("tree", [ 21 u("leaf", "1"), 22 u("node", [u("leaf", "two"), u("leaf", "2")]), 23 u("void"), 24 u("leaf", "3") 25]); 26 27assert.deepEqual(newTree, expected);
NOTE: leaf
with value
2
is visited before it's parent node
. By the
time your transform
function is invoked, it's children
will already have
been passed through transform
.
reduce(tree, transform)
tree
- A node of type Parent
transform
- A function with the signature:
(node: Node, path: number[], root: Paretn) => Node | Node[]
node
- The Node
in the tree to be transformedpath
- The path to reach this node in each level of the treeroot
- The Parent
root node.concat()
on the children
array of the node's parent.unist-util-filter
— Create a new tree with all nodes that pass a testunist-util-map
— Create a new tree with all nodes mapped by a given functionunist-util-remove
— Remove nodes from a tree that pass a testunist-util-select
— Select nodes with CSS-like selectorsNo vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/22 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
32 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More