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-visit-parents
unist utility to recursively walk over nodes, with ancestral information
unist-util-is
unist utility to check if a node passes a test
unist-util-visit
unist utility to visit nodes
unist-util-stringify-position
unist utility to serialize a node, position, or point as a human readable location
npm install unist-util-map
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
35 Stars
90 Commits
4 Forks
9 Watching
1 Branches
12 Contributors
Updated on 28 Apr 2024
JavaScript (86.75%)
TypeScript (13.25%)
Cumulative downloads
Total Downloads
Last day
6.6%
17,906
Compared to previous day
Last week
2.9%
99,068
Compared to previous week
Last month
10.1%
439,303
Compared to previous month
Last year
-9.7%
4,763,461
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
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
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 2024-11-18
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