Skip to content

Commit df29566

Browse files
committed
Add improved docs
1 parent 7d811fe commit df29566

File tree

3 files changed

+110
-16
lines changed

3 files changed

+110
-16
lines changed

index.js

+4
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
/**
2+
* @typedef {import('./lib/index.js').AssertionError} AssertionError
3+
*/
4+
15
export {_void, assert, parent, literal, wrap} from './lib/index.js'

lib/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/**
2+
* @typedef {import('unist-util-assert').AssertionError} AssertionError
3+
*
24
* @typedef {import('unist').Node} UnistNode
35
* @typedef {import('unist').Parent} UnistParent
46
* @typedef {import('unist').Literal} UnistLiteral

readme.md

+104-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [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)
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+, 16.0+, or 18.0+), install with [npm][]:
48+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4449

4550
```sh
4651
npm install hast-util-assert
@@ -78,36 +83,101 @@ assert({type: 'element', properties: {}, children: []})
7883

7984
## API
8085

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].
8388
There is no default export.
8489

85-
### `assert(tree)`
90+
### `assert(tree[, parent])`
8691

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

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
92104

93105
###### Returns
94106

95107
Nothing.
96108

97109
###### Throws
98110

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

101171
## Types
102172

103173
This package is fully typed with [TypeScript][].
104-
It does not export additional types.
174+
It exports the additional type [`AssertionError`][assertionerror].
105175

106176
## Compatibility
107177

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

113183
## Security
@@ -188,14 +258,32 @@ abide by its terms.
188258

189259
[unist-util-assert]: https://github.com/syntax-tree/unist-util-assert
190260

191-
[tree]: https://github.com/syntax-tree/unist#tree
261+
[unist]: https://github.com/syntax-tree/unist
192262

193-
[parent]: https://github.com/syntax-tree/unist#parent-1
263+
[node]: https://github.com/syntax-tree/unist#nodes
194264

195-
[child]: https://github.com/syntax-tree/unist#child
265+
[parent-node]: https://github.com/syntax-tree/unist#parent-1
196266

197-
[unist]: https://github.com/syntax-tree/unist
267+
[literal-node]: https://github.com/syntax-tree/unist#literal
198268

199269
[hast]: https://github.com/syntax-tree/hast
200270

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

Comments
 (0)