17
17
* [ Install] ( #install )
18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
- * [ ` assert(tree) ` ] ( #asserttree )
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+, 16.0+, or 18 .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 hast-util-assert
@@ -78,36 +83,101 @@ assert({type: 'element', properties: {}, children: []})
78
83
79
84
## API
80
85
81
- This package exports the identifiers ` assert ` , ` parent ` , ` literal ` , ` _void ` ,
82
- and ` wrap ` .
86
+ This package exports the identifiers [ ` _void ` ] [ void ] , [ ` assert ` ] [ assert ] ,
87
+ [ ` literal ` ] [ literal ] , [ ` parent ` ] [ parent ] , and [ ` wrap ` ] [ wrap ] .
83
88
There is no default export.
84
89
85
- ### ` assert(tree) `
90
+ ### ` assert(tree[, parent] ) `
86
91
87
- Assert that [ ` tree ` ] [ tree ] is a valid [ hast] [ ] node.
88
- If ` tree ` is a [ parent] [ ] , all [ child] [ ] ren will be asserted as well.
92
+ Assert that ` tree ` is a valid hast [ ` Node ` ] [ node ] .
89
93
90
- The ` parent ` , ` literal ` , ` _void ` , and ` wrap ` methods from
91
- [ ` unist-util-assert ` ] [ unist-util-assert ] are also exported.
94
+ If ` tree ` is a parent, all children will be asserted too.
95
+
96
+ Supports unknown hast nodes.
97
+
98
+ ###### Parameters
99
+
100
+ * ` tree ` (` unknown ` )
101
+ — thing to assert
102
+ * ` parent ` ([ ` Parent ` ] [ parent-node ] , optional)
103
+ — optional, valid parent
92
104
93
105
###### Returns
94
106
95
107
Nothing.
96
108
97
109
###### Throws
98
110
99
- When ` node ` , or one of its children, is not a valid mdast node.
111
+ When ` tree ` (or its descendants) is not a hast node
112
+ ([ ` AssertionError ` ] [ assertionerror ] ).
113
+
114
+ ### ` parent(tree[, parent]) `
115
+
116
+ Assert that ` tree ` is a valid hast [ ` Parent ` ] [ parent-node ] .
117
+
118
+ All children will be asserted too.
119
+
120
+ Supports unknown hast nodes.
121
+
122
+ ###### Parameters
123
+
124
+ * ` tree ` (` unknown ` )
125
+ — thing to assert
126
+ * ` parent ` ([ ` Parent ` ] [ parent-node ] , optional)
127
+ — optional, valid parent
128
+
129
+ ###### Returns
130
+
131
+ Nothing.
132
+
133
+ ###### Throws
134
+
135
+ When ` tree ` is not a parent or its descendants are not nodes
136
+ ([ ` AssertionError ` ] [ assertionerror ] )
137
+
138
+ ### ` literal(node[, parent]) `
139
+
140
+ Assert that ` node ` is a valid hast [ ` Literal ` ] [ literal-node ] .
141
+
142
+ Supports unknown hast nodes.
143
+
144
+ ###### Parameters
145
+
146
+ * ` node ` (` unknown ` )
147
+ — thing to assert
148
+ * ` parent ` ([ ` Parent ` ] [ parent-node ] , optional)
149
+ — optional, valid parent
150
+
151
+ ###### Returns
152
+
153
+ Nothing.
154
+
155
+ ###### Throws
156
+
157
+ When ` node ` is not a hast literal ([ ` AssertionError ` ] [ assertionerror ] ).
158
+
159
+ ### ` _void(node[, parent]) `
160
+
161
+ Re-exported from [ ` unist-util-assert ` ] [ unist-util-assert-void ] .
162
+
163
+ ### ` wrap(fn) `
164
+
165
+ Re-exported from [ ` unist-util-assert ` ] [ unist-util-assert-wrap ] .
166
+
167
+ ### ` AssertionError `
168
+
169
+ Re-exported from [ ` unist-util-assert ` ] [ unist-util-assert-assertionerror ] .
100
170
101
171
## Types
102
172
103
173
This package is fully typed with [ TypeScript] [ ] .
104
- It does not export additional types .
174
+ It exports the additional type [ ` AssertionError ` ] [ assertionerror ] .
105
175
106
176
## Compatibility
107
177
108
178
Projects maintained by the unified collective are compatible with all maintained
109
179
versions of Node.js.
110
- As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18 .0+.
180
+ As of now, that is Node.js 14.14+ and 16 .0+.
111
181
Our projects sometimes work with older versions, but this is not guaranteed.
112
182
113
183
## Security
@@ -188,14 +258,32 @@ abide by its terms.
188
258
189
259
[ unist-util-assert ] : https://github.com/syntax-tree/unist-util-assert
190
260
191
- [ tree ] : https://github.com/syntax-tree/unist#tree
261
+ [ unist ] : https://github.com/syntax-tree/unist
192
262
193
- [ parent ] : https://github.com/syntax-tree/unist#parent-1
263
+ [ node ] : https://github.com/syntax-tree/unist#nodes
194
264
195
- [ child ] : https://github.com/syntax-tree/unist#child
265
+ [ parent-node ] : https://github.com/syntax-tree/unist#parent-1
196
266
197
- [ unist ] : https://github.com/syntax-tree/unist
267
+ [ literal-node ] : https://github.com/syntax-tree/unist#literal
198
268
199
269
[ hast ] : https://github.com/syntax-tree/hast
200
270
201
271
[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
272
+
273
+ [ void ] : #_voidnode-parent
274
+
275
+ [ assert ] : #asserttree-parent
276
+
277
+ [ literal ] : #literalnode-parent
278
+
279
+ [ parent ] : #parenttree-parent
280
+
281
+ [ wrap ] : #wrapfn
282
+
283
+ [ assertionerror ] : #assertionerror
284
+
285
+ [ unist-util-assert-void ] : https://github.com/syntax-tree/unist-util-assert#_voidnode-parent
286
+
287
+ [ unist-util-assert-wrap ] : https://github.com/syntax-tree/unist-util-assert#wrapfn
288
+
289
+ [ unist-util-assert-assertionerror ] : https://github.com/syntax-tree/unist-util-assert#assertionerror
0 commit comments