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
* [ Related] ( #related )
@@ -39,7 +44,7 @@ for any [unist][] node.
39
44
## Install
40
45
41
46
This package is [ ESM only] [ esm ] .
42
- In Node.js (version 12.20+, 14.14+, 16.0+, 18 .0+), install with [ npm] [ ] :
47
+ In Node.js (version 14.14+ and 16 .0+), install with [ npm] [ ] :
43
48
44
49
``` sh
45
50
npm install nlcst-test
@@ -48,14 +53,14 @@ npm install nlcst-test
48
53
In Deno with [ ` esm.sh ` ] [ esmsh ] :
49
54
50
55
``` js
51
- import {assert } from " https://esm.sh/nlcst-test@3"
56
+ import {assert } from ' https://esm.sh/nlcst-test@3'
52
57
```
53
58
54
59
In browsers with [ ` esm.sh ` ] [ esmsh ] :
55
60
56
61
``` html
57
62
<script type =" module" >
58
- import {assert } from " https://esm.sh/nlcst-test@3?bundle"
63
+ import {assert } from ' https://esm.sh/nlcst-test@3?bundle'
59
64
</script >
60
65
```
61
66
@@ -78,36 +83,101 @@ assert({type: 'WordNode', value: 'foo'})
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 [ nlcst] [ ] [ node] [ ] .
88
- If ` tree ` is a [ parent] [ ] , all [ child] [ ] ren will be asserted as well.
92
+ Assert that ` tree ` is a valid nlcst [ ` 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 nlcst nodes.
97
+
98
+ ###### Parameters
99
+
100
+ * ` tree ` (` unknown ` )
101
+ — thing to assert
102
+ * ` parent ` ([ ` Parent ` ] [ parent-node ] , optional)
103
+ — optional, valid parent
104
+
105
+ ###### Returns
106
+
107
+ Nothing.
92
108
93
109
###### Throws
94
110
95
- When ` node ` , or one of its children, is not a valid nlcst node.
111
+ When ` tree ` (or its descendants) is not an nlcst node
112
+ ([ ` AssertionError ` ] [ assertionerror ] ).
113
+
114
+ ### ` parent(tree[, parent]) `
115
+
116
+ Assert that ` tree ` is a valid nlcst [ ` Parent ` ] [ parent-node ] .
117
+
118
+ All children will be asserted too.
119
+
120
+ Supports unknown nlcst 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 nlcst [ ` Literal ` ] [ literal-node ] .
141
+
142
+ Supports unknown nlcst nodes.
143
+
144
+ ###### Parameters
145
+
146
+ * ` node ` (` unknown ` )
147
+ — thing to assert
148
+ * ` parent ` ([ ` Parent ` ] [ parent-node ] , optional)
149
+ — optional, valid parent
96
150
97
151
###### Returns
98
152
99
153
Nothing.
100
154
155
+ ###### Throws
156
+
157
+ When ` node ` is not an nlcst 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 ] .
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
## Related
@@ -181,16 +251,32 @@ abide by its terms.
181
251
182
252
[ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
183
253
254
+ [ unist-util-assert ] : https://github.com/syntax-tree/unist-util-assert
255
+
256
+ [ unist ] : https://github.com/syntax-tree/unist
257
+
258
+ [ node ] : https://github.com/syntax-tree/unist#nodes
259
+
260
+ [ parent-node ] : https://github.com/syntax-tree/unist#parent-1
261
+
262
+ [ literal-node ] : https://github.com/syntax-tree/unist#literal
263
+
184
264
[ nlcst ] : https://github.com/syntax-tree/nlcst
185
265
186
- [ unist-util-assert ] : https://github.com/syntax-tree/unist-util-assert
266
+ [ void ] : #_voidnode-parent
187
267
188
- [ tree ] : https://github.com/syntax-tree/unist#tree
268
+ [ assert ] : #asserttree-parent
189
269
190
- [ unist ] : https://github.com/syntax-tree/unist
270
+ [ literal ] : #literalnode-parent
271
+
272
+ [ parent ] : #parenttree-parent
273
+
274
+ [ wrap ] : #wrapfn
275
+
276
+ [ assertionerror ] : #assertionerror
191
277
192
- [ child ] : https://github.com/syntax-tree/unist#child
278
+ [ unist-util-assert-void ] : https://github.com/syntax-tree/unist-util-assert#_voidnode-parent
193
279
194
- [ node ] : https://github.com/syntax-tree/nlcst#nodes
280
+ [ unist-util-assert-wrap ] : https://github.com/syntax-tree/unist-util-assert#wrapfn
195
281
196
- [ parent ] : https://github.com/syntax-tree/nlcst#parent
282
+ [ unist-util-assert-assertionerror ] : https://github.com/syntax-tree/unist-util-assert#assertionerror
0 commit comments