@@ -47,7 +47,7 @@ To create trees, use [`unist-builder`][unist-builder].
47
47
## Install
48
48
49
49
This package is [ ESM only] [ esm ] .
50
- In Node.js (version 12.20+, 14.14+, 16.0+, 18 .0+), install with [ npm] [ ] :
50
+ In Node.js (version 14.14+ and 16 .0+), install with [ npm] [ ] :
51
51
52
52
``` sh
53
53
npm install unist-util-map
@@ -56,14 +56,14 @@ npm install unist-util-map
56
56
In Deno with [ ` esm.sh ` ] [ esmsh ] :
57
57
58
58
``` js
59
- import {map } from " https://esm.sh/unist-util-map@3"
59
+ import {map } from ' https://esm.sh/unist-util-map@3'
60
60
```
61
61
62
62
In browsers with [ ` esm.sh ` ] [ esmsh ] :
63
63
64
64
``` html
65
65
<script type =" module" >
66
- import {map } from " https://esm.sh/unist-util-map@3?bundle"
66
+ import {map } from ' https://esm.sh/unist-util-map@3?bundle'
67
67
</script >
68
68
```
69
69
@@ -107,39 +107,56 @@ Yields:
107
107
108
108
## API
109
109
110
- This package exports the identifier ` map ` .
110
+ This package exports the identifier [ ` map ` ] [ api-map ] .
111
111
There is no default export.
112
112
113
113
### ` map(tree, mapFunction) `
114
114
115
- Create a new tree ([ ` Node ` ] [ node ] ) by mapping all nodes with the given function
116
- ([ ` MapFunction ` ] [ map-function ] ).
115
+ Create a new tree by mapping all nodes with the given function.
116
+
117
+ ###### Parameters
118
+
119
+ * ` tree ` ([ ` Node ` ] [ node ] )
120
+ — tree to map
121
+ * ` mapFunction ` ([ ` MapFunction ` ] [ api-mapfunction ] )
122
+ — function called with a node, its index, and its parent to produce a new
123
+ node
117
124
118
125
###### Returns
119
126
120
127
New mapped tree ([ ` Node ` ] [ node ] ).
121
128
122
- #### ` function mapFunction(node, index, parent) `
129
+ #### ` MapFunction `
130
+
131
+ Function called with a node, its index, and its parent to produce a new
132
+ node (TypeScript type).
133
+
134
+ ###### Parameters
123
135
124
- Function called with a node ([ ` Node ` ] [ node ] ), its [ index] [ ] (` number? ` ), and its
125
- [ parent] [ ] (` Node? ` ) to produce a new node.
136
+ * ` node ` ([ ` Node ` ] [ node ] )
137
+ — node to map
138
+ * ` index ` (` number ` or ` undefined ` )
139
+ — index of ` node ` in ` parent ` (if any)
140
+ * ` parent ` ([ ` Node ` ] [ node ] or ` undefined ` )
141
+ — parent of ` node `
126
142
127
143
###### Returns
128
144
129
- Node to be used in the new tree ([ ` Node ` ] [ node ] ).
145
+ New mapped node ([ ` Node ` ] [ node ] ).
146
+
130
147
The children on the returned node are not used.
131
- if the original node has children, those are mapped instead.
148
+ If the original node has children, those are mapped instead.
132
149
133
150
## Types
134
151
135
152
This package is fully typed with [ TypeScript] [ ] .
136
- It exports a type ` MapFunction<Tree extends Node = Node> ` to properly type ` MapFunction ` s .
153
+ It exports the additional type [ ` MapFunction ` ] [ api-mapfunction ] .
137
154
138
155
## Compatibility
139
156
140
157
Projects maintained by the unified collective are compatible with all maintained
141
158
versions of Node.js.
142
- As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18 .0+.
159
+ As of now, that is Node.js 14.14+ and 16 .0+.
143
160
Our projects sometimes work with older versions, but this is not guaranteed.
144
161
145
162
## Related
@@ -223,10 +240,6 @@ abide by its terms.
223
240
224
241
[ node ] : https://github.com/syntax-tree/unist#node
225
242
226
- [ parent ] : https://github.com/syntax-tree/unist#parent-1
227
-
228
- [ index ] : https://github.com/syntax-tree/unist#index
229
-
230
243
[ unist-util-visit ] : https://github.com/syntax-tree/unist-util-visit
231
244
232
245
[ unist-util-visit-parents ] : https://github.com/syntax-tree/unist-util-visit-parents
@@ -237,4 +250,6 @@ abide by its terms.
237
250
238
251
[ unist-builder ] : https://github.com/syntax-tree/unist-builder
239
252
240
- [ map-function ] : #function-mapfunctionnode-index-parent
253
+ [ api-map ] : #maptree-mapfunction
254
+
255
+ [ api-mapfunction ] : #mapfunction
0 commit comments