Skip to content

Commit f9717dd

Browse files
committed
Add improved docs
1 parent a802741 commit f9717dd

File tree

1 file changed

+104
-17
lines changed

1 file changed

+104
-17
lines changed

readme.md

Lines changed: 104 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [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)
2126
* [Types](#types)
2227
* [Compatibility](#compatibility)
2328
* [Security](#security)
@@ -40,7 +45,7 @@ for any [unist][] node.
4045
## Install
4146

4247
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][]:
4449

4550
```sh
4651
npm install mdast-util-assert
@@ -79,41 +84,107 @@ assert({type: 'paragraph', value: 'foo'})
7984

8085
## API
8186

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].
8490
There is no default export.
8591

86-
### `assert(node)`
92+
### `assert(tree[, parent])`
8793

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].
9095

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.
93110

94111
###### Throws
95112

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
97152

98153
###### Returns
99154

100155
Nothing.
101156

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+
102173
## Types
103174

104175
This package is fully typed with [TypeScript][].
105-
It does not export additional types.
176+
It exports the additional type [`AssertionError`][assertionerror].
106177

107178
## Compatibility
108179

109180
Projects maintained by the unified collective are compatible with all maintained
110181
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+.
112183
Our projects sometimes work with older versions, but this is not guaranteed.
113184

114185
## Security
115186

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
117188
openings for [cross-site scripting (XSS)][xss] attacks.
118189

119190
## Related
@@ -191,16 +262,32 @@ abide by its terms.
191262

192263
[unist]: https://github.com/syntax-tree/unist
193264

194-
[tree]: https://github.com/syntax-tree/unist#tree
195-
196-
[child]: https://github.com/syntax-tree/unist#child
197-
198265
[unist-util-assert]: https://github.com/syntax-tree/unist-util-assert
199266

200267
[mdast]: https://github.com/syntax-tree/mdast
201268

202269
[node]: https://github.com/syntax-tree/mdast#nodes
203270

271+
[literal]: https://github.com/syntax-tree/mdast#literal
272+
204273
[parent]: https://github.com/syntax-tree/mdast#parent
205274

206275
[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

Comments
 (0)