Skip to content

Commit 5dc944d

Browse files
committed
Add improved docs
1 parent e0e4b49 commit 5dc944d

File tree

3 files changed

+114
-20
lines changed

3 files changed

+114
-20
lines changed

index.js

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

lib/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/**
22
* @typedef {import('unist').Node} UnistNode
33
* @typedef {import('unist').Parent} UnistParent
4+
* @typedef {import('unist-util-assert').AssertionError} AssertionError
45
*
56
* @typedef {import('nlcst').Root} Root
67
* @typedef {import('nlcst').Content} Content
8+
*/
9+
10+
/**
711
* @typedef {Root | Content} Node
812
* @typedef {Extract<Node, UnistParent>} Parent
913
*/

readme.md

Lines changed: 106 additions & 20 deletions
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
* [Related](#related)
@@ -39,7 +44,7 @@ for any [unist][] node.
3944
## Install
4045

4146
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][]:
4348

4449
```sh
4550
npm install nlcst-test
@@ -48,14 +53,14 @@ npm install nlcst-test
4853
In Deno with [`esm.sh`][esmsh]:
4954

5055
```js
51-
import {assert} from "https://esm.sh/nlcst-test@3"
56+
import {assert} from 'https://esm.sh/nlcst-test@3'
5257
```
5358

5459
In browsers with [`esm.sh`][esmsh]:
5560

5661
```html
5762
<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'
5964
</script>
6065
```
6166

@@ -78,36 +83,101 @@ assert({type: 'WordNode', value: 'foo'})
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 [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].
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 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.
92108

93109
###### Throws
94110

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
96150

97151
###### Returns
98152

99153
Nothing.
100154

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+
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
## Related
@@ -181,16 +251,32 @@ abide by its terms.
181251

182252
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
183253

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+
184264
[nlcst]: https://github.com/syntax-tree/nlcst
185265

186-
[unist-util-assert]: https://github.com/syntax-tree/unist-util-assert
266+
[void]: #_voidnode-parent
187267

188-
[tree]: https://github.com/syntax-tree/unist#tree
268+
[assert]: #asserttree-parent
189269

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
191277

192-
[child]: https://github.com/syntax-tree/unist#child
278+
[unist-util-assert-void]: https://github.com/syntax-tree/unist-util-assert#_voidnode-parent
193279

194-
[node]: https://github.com/syntax-tree/nlcst#nodes
280+
[unist-util-assert-wrap]: https://github.com/syntax-tree/unist-util-assert#wrapfn
195281

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

Comments
 (0)