Skip to content

Commit c635d51

Browse files
committed
Add improved docs
1 parent 2543409 commit c635d51

File tree

2 files changed

+56
-28
lines changed

2 files changed

+56
-28
lines changed

lib/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/**
22
* @typedef {import('unist').Node} Node
3-
* @typedef {import('unist').Parent} Parent
4-
* @typedef {import('unist').Position} Position
5-
* @typedef {import('unist').Point} Point
63
*
74
* @typedef Options
85
* Configuration.
@@ -17,6 +14,16 @@
1714

1815
import {color} from './color.js'
1916

17+
/**
18+
* Inspect a node, with color in Node, without color in browsers.
19+
*
20+
* @param tree
21+
* Tree to inspect.
22+
* @param options
23+
* Configuration.
24+
* @returns
25+
* Pretty printed `tree`.
26+
*/
2027
/* c8 ignore next */
2128
export const inspect = color ? inspectColor : inspectNoColor
2229

@@ -36,15 +43,15 @@ const colorExpression =
3643
/**
3744
* Inspect a node, without color.
3845
*
39-
* @param {unknown} node
46+
* @param {unknown} tree
4047
* Tree to inspect.
4148
* @param {Options | null | undefined} [options]
4249
* Configuration.
4350
* @returns {string}
4451
* Pretty printed `tree`.
4552
*/
46-
export function inspectNoColor(node, options) {
47-
return inspectColor(node, options).replace(colorExpression, '')
53+
export function inspectNoColor(tree, options) {
54+
return inspectColor(tree, options).replace(colorExpression, '')
4855
}
4956

5057
/**

readme.md

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`inspect(node[, options])`](#inspectnode-options)
21-
* [`inspectColor(node[, options])`](#inspectcolornode-options)
22-
* [`inspectNoColor(node[, options])`](#inspectnocolornode-options)
20+
* [`inspect(tree[, options])`](#inspecttree-options)
21+
* [`inspectColor(tree[, options])`](#inspectcolortree-options)
22+
* [`inspectNoColor(tree[, options])`](#inspectnocolortree-options)
23+
* [`Options`](#options)
2324
* [Types](#types)
2425
* [Compatibility](#compatibility)
2526
* [Contribute](#contribute)
@@ -38,7 +39,7 @@ to more easily spot bugs and see what’s going on in the tree.
3839
## Install
3940

4041
This package is [ESM only][esm].
41-
In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]:
42+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4243

4344
```sh
4445
npm install unist-util-inspect
@@ -47,14 +48,14 @@ npm install unist-util-inspect
4748
In Deno with [`esm.sh`][esmsh]:
4849

4950
```js
50-
import {inspect} from "https://esm.sh/unist-util-inspect@8"
51+
import {inspect} from 'https://esm.sh/unist-util-inspect@7'
5152
```
5253

5354
In browsers with [`esm.sh`][esmsh]:
5455

5556
```html
5657
<script type="module">
57-
import {inspect} from "https://esm.sh/unist-util-inspect@7?bundle"
58+
import {inspect} from 'https://esm.sh/unist-util-inspect@7?bundle'
5859
</script>
5960
```
6061

@@ -91,42 +92,54 @@ root[2]
9192

9293
## API
9394

94-
This package exports the identifiers `inspect`, `inspectColor`, and
95-
`inspectNoColor`.
95+
This package exports the identifiers [`inspect`][api-inspect],
96+
[`inspectColor`][api-inspectcolor], and [`inspectNoColor`][api-inspectnocolor].
9697
There is no default export.
9798

98-
### `inspect(node[, options])`
99+
### `inspect(tree[, options])`
99100

100-
Inspect the given `node` ([`Node`][node]).
101-
By default, colors are added in Node, and not in other places.
102-
See below on how to change that.
101+
Inspect a tree, with color in Node, without color in browsers.
103102

104-
###### `options.showPositions`
103+
###### Parameters
105104

106-
Whether to include positional information (`boolean`, default: `true`).
105+
* `tree` ([`Node`][node])
106+
— tree to inspect
107+
* `options` ([`Options`][api-options], optional)
108+
— configuration
107109

108-
##### Returns
110+
###### Returns
109111

110-
Pretty printed `node` (`string`).
112+
Pretty printed `tree` (`string`).
111113

112-
### `inspectColor(node[, options])`
114+
### `inspectColor(tree[, options])`
113115

114-
Inspect with ANSI color sequences (default in Node, Deno).
116+
Inspect a tree, with color.
117+
Otherwise same as [`inspect`][api-inspect].
115118

116-
### `inspectNoColor(node[, options])`
119+
### `inspectNoColor(tree[, options])`
117120

118-
Inspect without ANSI color sequences (default in browser, `react-native`).
121+
Inspect a tree, without color.
122+
Otherwise same as [`inspect`][api-inspect].
123+
124+
### `Options`
125+
126+
Configuration (TypeScript type).
127+
128+
###### Fields
129+
130+
* `showPositions` (`boolean`, default: `true`)
131+
— whether to include positional information
119132

120133
## Types
121134

122135
This package is fully typed with [TypeScript][].
123-
It exports the additional type `Options`.
136+
It exports the additional type [`Options`][api-options].
124137

125138
## Compatibility
126139

127140
Projects maintained by the unified collective are compatible with all maintained
128141
versions of Node.js.
129-
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
142+
As of now, that is Node.js 14.14+ and 16.0+.
130143
Our projects sometimes work with older versions, but this is not guaranteed.
131144

132145
## Contribute
@@ -194,3 +207,11 @@ abide by its terms.
194207
[unist]: https://github.com/syntax-tree/unist
195208

196209
[node]: https://github.com/syntax-tree/unist#node
210+
211+
[api-inspect]: #inspecttree-options
212+
213+
[api-inspectcolor]: #inspectcolortree-options
214+
215+
[api-inspectnocolor]: #inspectnocolortree-options
216+
217+
[api-options]: #options

0 commit comments

Comments
 (0)