Skip to content

Commit 93a6640

Browse files
committed
Add improved docs
1 parent dffaa98 commit 93a6640

File tree

1 file changed

+105
-34
lines changed

1 file changed

+105
-34
lines changed

readme.md

+105-34
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,63 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[**unist**][unist] utility to assert trees.
11+
[unist][] utility to assert trees.
1212

13-
## Install
13+
## Contents
14+
15+
* [What is this?](#what-is-this)
16+
* [When should I use this?](#when-should-i-use-this)
17+
* [Install](#install)
18+
* [Use](#use)
19+
* [API](#api)
20+
* [`assert(node[, parent])`](#assertnode-parent)
21+
* [`parent(node[, parent])`](#parentnode-parent)
22+
* [`literal(node[, parent])`](#literalnode-parent)
23+
* [`_void(node[, parent])`](#_voidnode-parent)
24+
* [`wrap(fn)`](#wrapfn)
25+
* [Extensions](#extensions)
26+
* [Types](#types)
27+
* [Compatibility](#compatibility)
28+
* [Related](#related)
29+
* [Contribute](#contribute)
30+
* [License](#license)
31+
32+
## What is this?
33+
34+
This package is a tiny utility that helps you deal with nodes.
35+
36+
## When should I use this?
1437

15-
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
16-
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
38+
This utility is typically useful when you expect certain nodes in your APIs
39+
and want to make sure they’re valid and as expected.
1740

18-
[npm][]:
41+
Different utilities, [`mdast-util-assert`][mdast-util-assert],
42+
[`hast-util-assert`][hast-util-assert], and [`nlcst-test`][nlcst-test],
43+
do the same but for mdast, hast, and nlcst nodes, respectively.
44+
45+
## Install
46+
47+
This package is [ESM only][esm].
48+
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
1949

2050
```sh
2151
npm install unist-util-assert
2252
```
2353

54+
In Deno with [`esm.sh`][esmsh]:
55+
56+
```js
57+
import {assert} from 'https://esm.sh/unist-util-assert@3'
58+
```
59+
60+
In browsers with [`esm.sh`][esmsh]:
61+
62+
```html
63+
<script type="module">
64+
import {assert} from 'https://esm.sh/unist-util-assert@3?bundle'
65+
</script>
66+
```
67+
2468
## Use
2569

2670
```js
@@ -49,57 +93,74 @@ assert({type: 'paragraph', children: ['foo']})
4993

5094
## API
5195

52-
This package exports the following identifiers: `assert`, `parent`, `literal`,
53-
`_void`, `wrap`.
96+
This package exports the identifiers `assert`, `parent`, `literal`, `_void`,
97+
and `wrap`.
5498
There is no default export.
5599

56100
### `assert(node[, parent])`
57101

58-
Assert that `node` is a valid [unist][] [node][].
59-
If `node` is a [parent][], all [child][]ren will be asserted too.
102+
Assert that `node` is a valid unist [`Node`][node].
103+
If `tree` is a [parent][], all children will be asserted as well.
104+
105+
###### Throws
106+
107+
When `node`, or one of its children, is not a valid node.
60108

61109
### `parent(node[, parent])`
62110

63-
Assert that `node` is a valid [unist][] [parent][].
64-
All [child][]ren will be asserted too.
111+
Assert that `node` is a valid unist [`Parent`][parent].
112+
All children will be asserted as well.
65113

66114
### `literal(node[, parent])`
67115

68-
Assert that `node` is a valid [unist][] [literal][].
116+
Assert that `node` is a valid unist [`Literal`][literal].
69117

70118
### `_void(node[, parent])`
71119

72-
Assert that `node` is a valid [unist][] [node][], but neither [parent][] nor
73-
[literal][].
74-
75-
## Extensions
76-
77-
This module can be used as a base to test subsets of [unist][] (for an example,
78-
see [`mdast-util-assert`][mdast-util-assert]).
79-
All functions that are exposed from such a module, and functions used internally
80-
to test [child][]ren, should be wrapped in `wrap`, which adds an inspectable
81-
string of the respective node, and its parent when available, to the exposed
82-
error message.
120+
Assert that `node` is a valid unist [`Node`][node], but neither
121+
[`Parent`][parent] nor
122+
[`Literal`][literal].
83123

84124
### `wrap(fn)`
85125

86126
Wraps `fn` (which is passed a node, and an optional parent node), so that any
87127
errors thrown inside it will contain information regarding the node (and the
88128
parent, when given).
89129

130+
## Extensions
131+
132+
This module can be used as a base to test subsets of unist (for an example, see
133+
[`mdast-util-assert`][mdast-util-assert]).
134+
All functions that are exposed from such a module, and functions used internally
135+
to test children, should be wrapped in `wrap`, which adds an inspectable string
136+
of the respective node, and its parent when available, to the exposed error
137+
message.
138+
139+
## Types
140+
141+
This package is fully typed with [TypeScript][].
142+
It does not export additional types.
143+
144+
## Compatibility
145+
146+
Projects maintained by the unified collective are compatible with all maintained
147+
versions of Node.js.
148+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
149+
Our projects sometimes work with older versions, but this is not guaranteed.
150+
90151
## Related
91152

92153
* [`mdast-util-assert`][mdast-util-assert]
93-
Check [mdast](https://github.com/syntax-tree/mdast) nodes
154+
assert mdast nodes
94155
* [`hast-util-assert`](https://github.com/syntax-tree/hast-util-assert)
95-
Check [hast](https://github.com/syntax-tree/hast) nodes
156+
assert hast nodes
96157
* [`nlcst-test`](https://github.com/syntax-tree/nlcst-test)
97-
Check [nlcst](https://github.com/syntax-tree/nlcst) nodes
158+
assert nlcst nodes
98159

99160
## Contribute
100161

101-
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
102-
started.
162+
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
163+
ways to get started.
103164
See [`support.md`][support] for ways to get help.
104165

105166
This project has a [code of conduct][coc].
@@ -140,24 +201,34 @@ abide by its terms.
140201

141202
[npm]: https://docs.npmjs.com/cli/install
142203

204+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
205+
206+
[esmsh]: https://esm.sh
207+
208+
[typescript]: https://www.typescriptlang.org
209+
143210
[license]: license
144211

145212
[author]: https://wooorm.com
146213

147-
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
214+
[health]: https://github.com/syntax-tree/.github
148215

149-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
216+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
150217

151-
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
218+
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
219+
220+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
152221

153222
[unist]: https://github.com/syntax-tree/unist
154223

224+
[node]: https://github.com/syntax-tree/unist#node
225+
155226
[parent]: https://github.com/syntax-tree/unist#parent
156227

157228
[literal]: https://github.com/syntax-tree/unist#literal
158229

159-
[node]: https://github.com/syntax-tree/unist#node
230+
[mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert
160231

161-
[child]: https://github.com/syntax-tree/unist#child
232+
[hast-util-assert]: https://github.com/syntax-tree/hast-util-assert
162233

163-
[mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert
234+
[nlcst-test]: https://github.com/syntax-tree/nlcst-test

0 commit comments

Comments
 (0)