17
17
* [ Install] ( #install )
18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
- * [ ` assert(node) ` ] ( #assertnode )
20
+ * [ ` assert(tree[, parent]) ` ] ( #asserttree-parent )
21
+ * [ ` parent(tree[, parent]) ` ] ( #parenttree-parent )
22
+ * [ ` literal(node[, parent]) ` ] ( #literalnode-parent )
23
+ * [ ` _void(node[, parent]) ` ] ( #_voidnode-parent )
24
+ * [ ` wrap(fn) ` ] ( #wrapfn )
25
+ * [ ` AssertionError ` ] ( #assertionerror )
21
26
* [ Types] ( #types )
22
27
* [ Compatibility] ( #compatibility )
23
28
* [ Security] ( #security )
@@ -40,7 +45,7 @@ for any [unist][] node.
40
45
## Install
41
46
42
47
This package is [ ESM only] [ esm ] .
43
- In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
48
+ In Node.js (version 14.14+ and 16.0+), install with [ npm] [ ] :
44
49
45
50
``` sh
46
51
npm install mdast-util-assert
@@ -79,41 +84,107 @@ assert({type: 'paragraph', value: 'foo'})
79
84
80
85
## API
81
86
82
- This package exports the identifiers ` assert ` , ` parent ` , ` literal ` , ` _void ` ,
83
- and ` wrap ` .
87
+ This package exports the identifiers [ ` _void ` ] [ api-void ] ,
88
+ [ ` assert ` ] [ api-assert ] , [ ` literal ` ] [ api-literal ] , [ ` parent ` ] [ api-parent ] ,
89
+ and [ ` wrap ` ] [ api-wrap ] .
84
90
There is no default export.
85
91
86
- ### ` assert(node ) `
92
+ ### ` assert(tree[, parent] ) `
87
93
88
- Assert that [ ` tree ` ] [ tree ] is a valid [ mdast] [ ] [ node] [ ] .
89
- If ` tree ` is a [ parent] [ ] , all [ child] [ ] ren will be asserted as well.
94
+ Assert that ` tree ` is a valid mdast [ ` Node ` ] [ node ] .
90
95
91
- The ` parent ` , ` literal ` , ` _void ` , and ` wrap ` methods from
92
- [ ` unist-util-assert ` ] [ unist-util-assert ] are also exported.
96
+ If ` tree ` is a parent, all children will be asserted too.
97
+
98
+ Supports unknown mdast nodes.
99
+
100
+ ###### Parameters
101
+
102
+ * ` tree ` (` unknown ` )
103
+ — thing to assert
104
+ * ` parent ` ([ ` Parent ` ] [ parent ] , optional)
105
+ — optional, valid parent
106
+
107
+ ###### Returns
108
+
109
+ Nothing.
93
110
94
111
###### Throws
95
112
96
- When ` node ` , or one of its children, is not a valid mdast node.
113
+ When ` tree ` (or its descendants) is not an mdast node
114
+ ([ ` AssertionError ` ] [ assertionerror ] ).
115
+
116
+ ### ` parent(tree[, parent]) `
117
+
118
+ Assert that ` tree ` is a valid mdast [ ` Parent ` ] [ parent ] .
119
+
120
+ All children will be asserted too.
121
+
122
+ Supports unknown mdast nodes.
123
+
124
+ ###### Parameters
125
+
126
+ * ` tree ` (` unknown ` )
127
+ — thing to assert
128
+ * ` parent ` ([ ` Parent ` ] [ parent ] , optional)
129
+ — optional, valid parent
130
+
131
+ ###### Returns
132
+
133
+ Nothing.
134
+
135
+ ###### Throws
136
+
137
+ When ` tree ` is not a parent or its descendants are not nodes
138
+ ([ ` AssertionError ` ] [ assertionerror ] )
139
+
140
+ ### ` literal(node[, parent]) `
141
+
142
+ Assert that ` node ` is a valid mdast [ ` Literal ` ] [ literal ] .
143
+
144
+ Supports unknown mdast nodes.
145
+
146
+ ###### Parameters
147
+
148
+ * ` node ` (` unknown ` )
149
+ — thing to assert
150
+ * ` parent ` ([ ` Parent ` ] [ parent ] , optional)
151
+ — optional, valid parent
97
152
98
153
###### Returns
99
154
100
155
Nothing.
101
156
157
+ ###### Throws
158
+
159
+ When ` node ` is not an mdast literal ([ ` AssertionError ` ] [ assertionerror ] ).
160
+
161
+ ### ` _void(node[, parent]) `
162
+
163
+ Re-exported from [ ` unist-util-assert ` ] [ unist-util-assert-void ] .
164
+
165
+ ### ` wrap(fn) `
166
+
167
+ Re-exported from [ ` unist-util-assert ` ] [ unist-util-assert-wrap ] .
168
+
169
+ ### ` AssertionError `
170
+
171
+ Re-exported from [ ` unist-util-assert ` ] [ unist-util-assert-assertionerror ] .
172
+
102
173
## Types
103
174
104
175
This package is fully typed with [ TypeScript] [ ] .
105
- It does not export additional types .
176
+ It exports the additional type [ ` AssertionError ` ] [ assertionerror ] .
106
177
107
178
## Compatibility
108
179
109
180
Projects maintained by the unified collective are compatible with all maintained
110
181
versions of Node.js.
111
- As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
182
+ As of now, that is Node.js 14.14+ and 16.0+.
112
183
Our projects sometimes work with older versions, but this is not guaranteed.
113
184
114
185
## Security
115
186
116
- Use of ` mdast-util-assert ` does not involve [ ** hast** ] [ hast ] so there are no
187
+ Use of ` mdast-util-assert ` does not involve ** [ hast] [ ] ** so there are no
117
188
openings for [ cross-site scripting (XSS)] [ xss ] attacks.
118
189
119
190
## Related
@@ -191,16 +262,32 @@ abide by its terms.
191
262
192
263
[ unist ] : https://github.com/syntax-tree/unist
193
264
194
- [ tree ] : https://github.com/syntax-tree/unist#tree
195
-
196
- [ child ] : https://github.com/syntax-tree/unist#child
197
-
198
265
[ unist-util-assert ] : https://github.com/syntax-tree/unist-util-assert
199
266
200
267
[ mdast ] : https://github.com/syntax-tree/mdast
201
268
202
269
[ node ] : https://github.com/syntax-tree/mdast#nodes
203
270
271
+ [ literal ] : https://github.com/syntax-tree/mdast#literal
272
+
204
273
[ parent ] : https://github.com/syntax-tree/mdast#parent
205
274
206
275
[ hast ] : https://github.com/syntax-tree/hast
276
+
277
+ [ api-void ] : #_voidnode-parent
278
+
279
+ [ api-assert ] : #asserttree-parent
280
+
281
+ [ api-literal ] : #literalnode-parent
282
+
283
+ [ api-parent ] : #parenttree-parent
284
+
285
+ [ api-wrap ] : #wrapfn
286
+
287
+ [ assertionerror ] : #assertionerror
288
+
289
+ [ unist-util-assert-void ] : https://github.com/syntax-tree/unist-util-assert#_voidnode-parent
290
+
291
+ [ unist-util-assert-wrap ] : https://github.com/syntax-tree/unist-util-assert#wrapfn
292
+
293
+ [ unist-util-assert-assertionerror ] : https://github.com/syntax-tree/unist-util-assert#assertionerror
0 commit comments