Skip to content

Commit 1e58f86

Browse files
committed
Add improved docs
1 parent a556bdd commit 1e58f86

File tree

2 files changed

+78
-21
lines changed

2 files changed

+78
-21
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const colorExpression =
3232
* Inspects a node, without using color.
3333
*
3434
* @param {unknown} node
35-
* @param {InspectOptions} [options]
35+
* @param {Options} [options]
3636
* @returns {string}
3737
*/
3838
export function inspectNoColor(node, options) {
@@ -43,7 +43,7 @@ export function inspectNoColor(node, options) {
4343
* Inspects a node, using color.
4444
*
4545
* @param {unknown} tree
46-
* @param {InspectOptions} [options]
46+
* @param {Options} [options]
4747
* @returns {string}
4848
*/
4949
export function inspectColor(tree, options = {}) {

readme.md

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

11-
[**unist**][unist] utility to inspect nodes.
11+
[unist][] utility to inspect 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+
* [`inspect(node[, options])`](#inspectnode-options)
21+
* [`inspectColor(node[, options])`](#inspectcolornode-options)
22+
* [`inspectNoColor(node[, options])`](#inspectnocolornode-options)
23+
* [Types](#types)
24+
* [Compatibility](#compatibility)
25+
* [Contribute](#contribute)
26+
* [License](#license)
27+
28+
## What is this?
29+
30+
This is a utility pretty prints the tree.
1431

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.
32+
## When should I use this?
33+
34+
This utility pretty prints the tree in a format that is made custom for unist
35+
trees, which is terser than the often verbose and repetitive JSON,
36+
to more easily spot bugs and see what’s going on in the tree.
37+
38+
## Install
1739

18-
[npm][]:
40+
This package is [ESM only][esm].
41+
In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]:
1942

2043
```sh
2144
npm install unist-util-inspect
2245
```
2346

47+
In Deno with [`esm.sh`][esmsh]:
48+
49+
```js
50+
import {inspect} from "https://esm.sh/unist-util-inspect@8"
51+
```
52+
53+
In browsers with [`esm.sh`][esmsh]:
54+
55+
```html
56+
<script type="module">
57+
import {inspect} from "https://esm.sh/unist-util-inspect@7?bundle"
58+
</script>
59+
```
60+
2461
## Use
2562

2663
```js
@@ -54,36 +91,48 @@ root[2]
5491

5592
## API
5693

57-
This package exports the following identifiers: `inspect`, `inspectColor`, and
94+
This package exports the identifiers `inspect`, `inspectColor`, and
5895
`inspectNoColor`.
5996
There is no default export.
6097

6198
### `inspect(node[, options])`
6299

63-
Inspect the given [`node`][node].
100+
Inspect the given `node` ([`Node`][node]).
64101
By default, colors are added in Node, and not in other places.
65102
See below on how to change that.
66103

67104
###### `options.showPositions`
68105

69106
Whether to include positional information (`boolean`, default: `true`).
70107

71-
###### Returns
108+
##### Returns
72109

73-
`string` — String representing `node`.
110+
Pretty printed `node` (`string`).
74111

75112
### `inspectColor(node[, options])`
76113

77-
Inspect, with ANSI color sequences (default in Node).
114+
Inspect with ANSI color sequences (default in Node, Deno).
78115

79116
### `inspectNoColor(node[, options])`
80117

81-
Inspect, but without ANSI color sequences (default in browser).
118+
Inspect without ANSI color sequences (default in browser, `react-native`).
119+
120+
## Types
121+
122+
This package is fully typed with [TypeScript][].
123+
It exports the additional type `Options`.
124+
125+
## Compatibility
126+
127+
Projects maintained by the unified collective are compatible with all maintained
128+
versions of Node.js.
129+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
130+
Our projects sometimes work with older versions, but this is not guaranteed.
82131

83132
## Contribute
84133

85-
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
86-
started.
134+
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
135+
ways to get started.
87136
See [`support.md`][support] for ways to get help.
88137

89138
This project has a [code of conduct][coc].
@@ -122,18 +171,26 @@ abide by its terms.
122171

123172
[chat]: https://github.com/syntax-tree/unist/discussions
124173

125-
[unist]: https://github.com/syntax-tree/unist
126-
127174
[npm]: https://docs.npmjs.com/cli/install
128175

129-
[node]: https://github.com/syntax-tree/unist#node
176+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
177+
178+
[esmsh]: https://esm.sh
179+
180+
[typescript]: https://www.typescriptlang.org
130181

131182
[license]: license
132183

133184
[author]: https://wooorm.com
134185

135-
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
186+
[health]: https://github.com/syntax-tree/.github
187+
188+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
189+
190+
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
136191

137-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
192+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
138193

139-
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
194+
[unist]: https://github.com/syntax-tree/unist
195+
196+
[node]: https://github.com/syntax-tree/unist#node

0 commit comments

Comments
 (0)