Gathering detailed insights and metrics for unist-util-map
Gathering detailed insights and metrics for unist-util-map
Gathering detailed insights and metrics for unist-util-map
Gathering detailed insights and metrics for unist-util-map
unist-util-index
unist utility to index property values or computed keys to nodes
unist-util-map-postorder
[unist](https://github.com/syntax-tree/unist) utility to create a new tree by mapping all nodes in postorder traversal with a given function.
unist-util-reduce
Parse unist trees, and map over nodes that pass a predicate function
npm install unist-util-map
Typescript
Module System
Node Version
NPM Version
99.3
Supply Chain
99.5
Quality
78.1
Maintenance
100
Vulnerability
100
License
JavaScript (86.75%)
TypeScript (13.25%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
34 Stars
90 Commits
4 Forks
8 Watchers
1 Branches
12 Contributors
Updated on Mar 24, 2025
Latest Version
4.0.0
Package Id
unist-util-map@4.0.0
Unpacked Size
17.23 kB
Size
5.20 kB
File Count
7
NPM Version
9.7.2
Node Version
20.0.0
Published on
Jul 07, 2023
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
1
unist utility to create a new tree by mapping all nodes with a given function.
This is a small utility that helps you make new trees.
You can use this utility to create a new tree by mapping all nodes with a given
function.
Creating new trees like this can lead to performance problems, as it creates
new objects for every node.
When dealing with potentially large trees, and relatively few changes, use
unist-util-visit
(or
unist-util-visit-parents
) instead.
To remove certain nodes, you can also walk the tree with unist-util-visit
, or
use unist-util-filter
(clones the tree instead of
mutating) or unist-util-remove
(mutates).
To create trees, use unist-builder
.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install unist-util-map
In Deno with esm.sh
:
1import {map} from 'https://esm.sh/unist-util-map@4'
In browsers with esm.sh
:
1<script type="module"> 2 import {map} from 'https://esm.sh/unist-util-map@4?bundle' 3</script>
1import {u} from 'unist-builder' 2import {map} from 'unist-util-map' 3 4const tree = u('tree', [ 5 u('leaf', 'leaf 1'), 6 u('node', [u('leaf', 'leaf 2')]), 7 u('void'), 8 u('leaf', 'leaf 3') 9]) 10 11const next = map(tree, function (node) { 12 return node.type === 'leaf' 13 ? Object.assign({}, node, {value: 'CHANGED'}) 14 : node 15}) 16 17console.dir(next, {depth: undefined})
Yields:
1{ 2 type: 'tree', 3 children: [ 4 {type: 'leaf', value: 'CHANGED'}, 5 {type: 'node', children: [{type: 'leaf', value: 'CHANGED'}]}, 6 {type: 'void'}, 7 {type: 'leaf', value: 'CHANGED'} 8 ] 9}
👉 Note:
next
is a changed clone andtree
is not mutated.
This package exports the identifier map
.
There is no default export.
map(tree, mapFunction)
Create a new tree by mapping all nodes with the given function.
tree
(Node
)
— tree to mapmapFunction
(MapFunction
)
— function called with a node, its index, and its parent to produce a new
nodeNew mapped tree (Node
).
MapFunction
Function called with a node, its index, and its parent to produce a new node (TypeScript type).
node
(Node
)
— node to mapindex
(number
or undefined
)
— index of node
in parent
(if any)parent
(Node
or undefined
)
— parent of node
New mapped node (Node
).
The children on the returned node are not used. If the original node has children, those are mapped instead.
This package is fully typed with TypeScript.
It exports the additional type MapFunction
.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, unist-util-map@^4
,
compatible with Node.js 16.
unist-util-filter
— create a new tree with all nodes that pass the given functionunist-util-flatmap
— create a new tree by expanding a node into manyunist-util-remove
— remove nodes from treesunist-util-select
— select nodes with CSS-like selectorsunist-util-visit
— walk treesunist-builder
— create treesSee contributing.md
in syntax-tree/.github
for
ways to get started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 3/30 approved changesets -- score normalized to 1
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
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