|
8 | 8 | [![Backers][backers-badge]][collective]
|
9 | 9 | [![Chat][chat-badge]][chat]
|
10 | 10 |
|
11 |
| -[**unist**][unist] utility to inspect nodes. |
| 11 | +[unist][] utility to inspect trees. |
12 | 12 |
|
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. |
14 | 31 |
|
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 |
17 | 39 |
|
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][]: |
19 | 42 |
|
20 | 43 | ```sh
|
21 | 44 | npm install unist-util-inspect
|
22 | 45 | ```
|
23 | 46 |
|
| 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 | + |
24 | 61 | ## Use
|
25 | 62 |
|
26 | 63 | ```js
|
@@ -54,36 +91,48 @@ root[2]
|
54 | 91 |
|
55 | 92 | ## API
|
56 | 93 |
|
57 |
| -This package exports the following identifiers: `inspect`, `inspectColor`, and |
| 94 | +This package exports the identifiers `inspect`, `inspectColor`, and |
58 | 95 | `inspectNoColor`.
|
59 | 96 | There is no default export.
|
60 | 97 |
|
61 | 98 | ### `inspect(node[, options])`
|
62 | 99 |
|
63 |
| -Inspect the given [`node`][node]. |
| 100 | +Inspect the given `node` ([`Node`][node]). |
64 | 101 | By default, colors are added in Node, and not in other places.
|
65 | 102 | See below on how to change that.
|
66 | 103 |
|
67 | 104 | ###### `options.showPositions`
|
68 | 105 |
|
69 | 106 | Whether to include positional information (`boolean`, default: `true`).
|
70 | 107 |
|
71 |
| -###### Returns |
| 108 | +##### Returns |
72 | 109 |
|
73 |
| -`string` — String representing `node`. |
| 110 | +Pretty printed `node` (`string`). |
74 | 111 |
|
75 | 112 | ### `inspectColor(node[, options])`
|
76 | 113 |
|
77 |
| -Inspect, with ANSI color sequences (default in Node). |
| 114 | +Inspect with ANSI color sequences (default in Node, Deno). |
78 | 115 |
|
79 | 116 | ### `inspectNoColor(node[, options])`
|
80 | 117 |
|
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. |
82 | 131 |
|
83 | 132 | ## Contribute
|
84 | 133 |
|
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. |
87 | 136 | See [`support.md`][support] for ways to get help.
|
88 | 137 |
|
89 | 138 | This project has a [code of conduct][coc].
|
@@ -122,18 +171,26 @@ abide by its terms.
|
122 | 171 |
|
123 | 172 | [chat]: https://github.com/syntax-tree/unist/discussions
|
124 | 173 |
|
125 |
| -[unist]: https://github.com/syntax-tree/unist |
126 |
| - |
127 | 174 | [npm]: https://docs.npmjs.com/cli/install
|
128 | 175 |
|
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 |
130 | 181 |
|
131 | 182 | [license]: license
|
132 | 183 |
|
133 | 184 | [author]: https://wooorm.com
|
134 | 185 |
|
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 |
136 | 191 |
|
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 |
138 | 193 |
|
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