22
22
* [ ` literal(node[, parent]) ` ] ( #literalnode-parent )
23
23
* [ ` _void(node[, parent]) ` ] ( #_voidnode-parent )
24
24
* [ ` wrap(fn) ` ] ( #wrapfn )
25
+ * [ ` AssertionError ` ] ( #assertionerror )
25
26
* [ Extensions] ( #extensions )
26
27
* [ Types] ( #types )
27
28
* [ Compatibility] ( #compatibility )
@@ -45,7 +46,7 @@ do the same but for mdast, hast, and nlcst nodes, respectively.
45
46
## Install
46
47
47
48
This package is [ ESM only] [ esm ] .
48
- In Node.js (version 12.20+, 14.14+, 16.0+, or 18 .0+), install with [ npm] [ ] :
49
+ In Node.js (version 14.14+ and 16 .0+), install with [ npm] [ ] :
49
50
50
51
``` sh
51
52
npm install unist-util-assert
@@ -93,41 +94,113 @@ assert({type: 'paragraph', children: ['foo']})
93
94
94
95
## API
95
96
96
- This package exports the identifiers ` assert ` , ` parent ` , ` literal ` , ` _void ` ,
97
- and ` wrap ` .
97
+ This package exports the identifiers [ ` _void ` ] [ void ] , [ ` assert ` ] [ assert ] ,
98
+ [ ` literal ` ] [ literal ] , [ ` parent ` ] [ parent ] , and [ ` wrap ` ] [ wrap ] .
98
99
There is no default export.
99
100
100
101
### ` assert(tree[, parent]) `
101
102
102
103
Assert that ` tree ` is a valid unist [ ` Node ` ] [ node ] .
103
104
104
- If ` tree ` is a [ parent] [ ] , all children will be asserted as well.
105
+ If ` tree ` is a parent, all children will be asserted too.
106
+
107
+ ###### Parameters
108
+
109
+ * ` tree ` (` unknown ` )
110
+ — thing to assert
111
+ * ` parent ` ([ ` Parent ` ] [ parent-node ] , optional)
112
+ — optional, valid parent
113
+
114
+ ###### Returns
115
+
116
+ Nothing.
105
117
106
118
###### Throws
107
119
108
- When ` node ` , or one of its children, is not a valid node.
120
+ When ` tree ` ( or its descendants) is not a node.
109
121
110
122
### ` parent(tree[, parent]) `
111
123
112
- Assert that ` tree ` is a valid unist [ ` Parent ` ] [ parent ] .
124
+ Assert that ` tree ` is a valid unist [ ` Parent ` ] [ parent-node ] .
125
+
126
+ All children will be asserted too.
127
+
128
+ ###### Parameters
129
+
130
+ * ` tree ` (` unknown ` )
131
+ — thing to assert
132
+ * ` parent ` ([ ` Parent ` ] [ parent-node ] , optional)
133
+ — optional, valid parent
134
+
135
+ ###### Returns
136
+
137
+ Nothing.
138
+
139
+ ###### Throws
113
140
114
- All children will be asserted as well .
141
+ When ` tree ` is not a parent or its descendants are not nodes .
115
142
116
143
### ` literal(node[, parent]) `
117
144
118
- Assert that ` node ` is a valid unist [ ` Literal ` ] [ literal ] .
145
+ Assert that ` node ` is a valid unist [ ` Literal ` ] [ literal-node ] .
146
+
147
+ ###### Parameters
148
+
149
+ * ` tree ` (` unknown ` )
150
+ — thing to assert
151
+ * ` parent ` ([ ` Parent ` ] [ parent-node ] , optional)
152
+ — optional, valid parent
153
+
154
+ ###### Returns
155
+
156
+ Nothing.
157
+
158
+ ###### Throws
159
+
160
+ When ` node ` is not a literal.
119
161
120
162
### ` _void(node[, parent]) `
121
163
122
- Assert that ` node ` is a valid unist [ ` Node ` ] [ node ] , but neither
123
- [ ` Parent ` ] [ parent ] nor
124
- [ ` Literal ` ] [ literal ] .
164
+ Assert that ` node ` is a valid void node.
165
+
166
+ ###### Parameters
167
+
168
+ * ` tree ` (` unknown ` )
169
+ — thing to assert
170
+ * ` parent ` ([ ` Parent ` ] [ parent-node ] , optional)
171
+ — optional, valid parent
172
+
173
+ ###### Returns
174
+
175
+ Nothing.
176
+
177
+ ###### Throws
178
+
179
+ When ` node ` is not a node, a parent, or a literal.
125
180
126
181
### ` wrap(fn) `
127
182
128
- Wraps ` fn ` (which is passed a node, and an optional parent node), so that any
129
- errors thrown inside it will contain information regarding the node (and the
130
- parent, when given).
183
+ Wrapper that adds the current node (and parent, if available) to error
184
+ messages.
185
+
186
+ ###### Parameters
187
+
188
+ * ` fn ` (` (node?: any, parent?: Parent | null | undefined) => asserts node is Node) ` )
189
+ — custom assertion
190
+
191
+ ###### Returns
192
+
193
+ Wrapped ` fn ` .
194
+
195
+ ### ` AssertionError `
196
+
197
+ Assertion error from ` node:assert ` (TypeScript type).
198
+
199
+ ###### Type
200
+
201
+ ``` ts
202
+ type AssertionError = import (' node:assert' ).AssertionError
203
+ ` ` `
131
204
132
205
## Extensions
133
206
@@ -141,13 +214,13 @@ message.
141
214
## Types
142
215
143
216
This package is fully typed with [TypeScript][].
144
- It exports the additional type ` AssertionError ` .
217
+ It exports the additional type [ ` AssertionError ` ][assertionerror] .
145
218
146
219
## Compatibility
147
220
148
221
Projects maintained by the unified collective are compatible with all maintained
149
222
versions of Node.js.
150
- As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18 .0+.
223
+ As of now, that is Node.js 14.14+ and 16 .0+.
151
224
Our projects sometimes work with older versions, but this is not guaranteed.
152
225
153
226
## Related
@@ -225,12 +298,24 @@ abide by its terms.
225
298
226
299
[node]: https://github.com/syntax-tree/unist#node
227
300
228
- [ parent ] : https://github.com/syntax-tree/unist#parent
301
+ [parent-node ]: https://github.com/syntax-tree/unist#parent
229
302
230
- [ literal ] : https://github.com/syntax-tree/unist#literal
303
+ [literal-node ]: https://github.com/syntax-tree/unist#literal
231
304
232
305
[mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert
233
306
234
307
[hast-util-assert]: https://github.com/syntax-tree/hast-util-assert
235
308
236
309
[nlcst-test]: https://github.com/syntax-tree/nlcst-test
310
+
311
+ [assert]: #asserttree-parent
312
+
313
+ [parent]: #parenttree-parent
314
+
315
+ [literal]: #literalnode-parent
316
+
317
+ [void]: #_voidnode-parent
318
+
319
+ [wrap]: #wrapfn
320
+
321
+ [assertionerror]: #assertionerror
0 commit comments