Skip to content

Commit 42550a0

Browse files
committed
Add improved docs
1 parent 3216604 commit 42550a0

File tree

1 file changed

+84
-16
lines changed

1 file changed

+84
-16
lines changed

readme.md

Lines changed: 84 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,58 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[**hast**][hast] utility to assert trees.
11+
[hast][] 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(tree)`](#asserttree)
21+
* [Types](#types)
22+
* [Compatibility](#compatibility)
23+
* [Security](#security)
24+
* [Related](#related)
25+
* [Contribute](#contribute)
26+
* [License](#license)
27+
28+
## What is this?
29+
30+
This package is a tiny utility that helps you deal with nodes.
31+
32+
## When should I use this?
33+
34+
This utility is typically useful when you expect certain nodes in your APIs
35+
and want to make sure they’re valid and as expected.
36+
37+
A different utility, [`unist-util-assert`][unist-util-assert], does the same but
38+
for any [unist][] node.
1439

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.
40+
## Install
1741

18-
[npm][]:
42+
This package is [ESM only][esm].
43+
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
1944

2045
```sh
2146
npm install hast-util-assert
2247
```
2348

49+
In Deno with [`esm.sh`][esmsh]:
50+
51+
```js
52+
import {assert} from 'https://esm.sh/hast-util-assert@3'
53+
```
54+
55+
In browsers with [`esm.sh`][esmsh]:
56+
57+
```html
58+
<script type="module">
59+
import {assert} from 'https://esm.sh/hast-util-assert@3?bundle'
60+
</script>
61+
```
62+
2463
## Use
2564

2665
```js
@@ -39,18 +78,37 @@ assert({type: 'element', properties: {}, children: []})
3978

4079
## API
4180

42-
This package exports the following identifiers: `assert`, `parent`, `literal`,
43-
`_void`, `wrap`.
81+
This package exports the identifiers `assert`, `parent`, `literal`, `_void`,
82+
and `wrap`.
4483
There is no default export.
4584

4685
### `assert(tree)`
4786

48-
Assert that the given `tree` is a valid [**hast**][hast] [*tree*][tree].
49-
If `tree` is a [*parent*][parent], all [*children*][child] will be asserted as
50-
well.
87+
Assert that [`tree`][tree] is a valid [hast][] node.
88+
If `tree` is a [parent][], all [child][]ren will be asserted as well.
5189

5290
The `parent`, `literal`, `_void`, and `wrap` methods from
53-
[`unist-util-assert`][unist-util-assert] are also included.
91+
[`unist-util-assert`][unist-util-assert] are also exported.
92+
93+
###### Returns
94+
95+
Nothing.
96+
97+
###### Throws
98+
99+
When `node`, or one of its children, is not a valid mdast node.
100+
101+
## Types
102+
103+
This package is fully typed with [TypeScript][].
104+
It does not export additional types.
105+
106+
## Compatibility
107+
108+
Projects maintained by the unified collective are compatible with all maintained
109+
versions of Node.js.
110+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
111+
Our projects sometimes work with older versions, but this is not guaranteed.
54112

55113
## Security
56114

@@ -68,8 +126,8 @@ The `parent`, `literal`, `_void`, and `wrap` methods from
68126

69127
## Contribute
70128

71-
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
72-
started.
129+
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
130+
ways to get started.
73131
See [`support.md`][support] for ways to get help.
74132

75133
This project has a [code of conduct][coc].
@@ -110,15 +168,23 @@ abide by its terms.
110168

111169
[npm]: https://docs.npmjs.com/cli/install
112170

171+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
172+
173+
[esmsh]: https://esm.sh
174+
175+
[typescript]: https://www.typescriptlang.org
176+
113177
[license]: license
114178

115179
[author]: https://wooorm.com
116180

117-
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
181+
[health]: https://github.com/syntax-tree/.github
182+
183+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
118184

119-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
185+
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
120186

121-
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
187+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
122188

123189
[unist-util-assert]: https://github.com/syntax-tree/unist-util-assert
124190

@@ -128,6 +194,8 @@ abide by its terms.
128194

129195
[child]: https://github.com/syntax-tree/unist#child
130196

197+
[unist]: https://github.com/syntax-tree/unist
198+
131199
[hast]: https://github.com/syntax-tree/hast
132200

133201
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting

0 commit comments

Comments
 (0)