Skip to content

Commit

Permalink
Add improved docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 5, 2022
1 parent a556bdd commit 1e58f86
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 21 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const colorExpression =
* Inspects a node, without using color.
*
* @param {unknown} node
* @param {InspectOptions} [options]
* @param {Options} [options]
* @returns {string}
*/
export function inspectNoColor(node, options) {
Expand All @@ -43,7 +43,7 @@ export function inspectNoColor(node, options) {
* Inspects a node, using color.
*
* @param {unknown} tree
* @param {InspectOptions} [options]
* @param {Options} [options]
* @returns {string}
*/
export function inspectColor(tree, options = {}) {
Expand Down
95 changes: 76 additions & 19 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,56 @@
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]

[**unist**][unist] utility to inspect nodes.
[unist][] utility to inspect trees.

## Install
## Contents

* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`inspect(node[, options])`](#inspectnode-options)
* [`inspectColor(node[, options])`](#inspectcolornode-options)
* [`inspectNoColor(node[, options])`](#inspectnocolornode-options)
* [Types](#types)
* [Compatibility](#compatibility)
* [Contribute](#contribute)
* [License](#license)

## What is this?

This is a utility pretty prints the tree.

This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
## When should I use this?

This utility pretty prints the tree in a format that is made custom for unist
trees, which is terser than the often verbose and repetitive JSON,
to more easily spot bugs and see what’s going on in the tree.

## Install

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

```sh
npm install unist-util-inspect
```

In Deno with [`esm.sh`][esmsh]:

```js
import {inspect} from "https://esm.sh/unist-util-inspect@8"
```

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

```html
<script type="module">
import {inspect} from "https://esm.sh/unist-util-inspect@7?bundle"
</script>
```

## Use

```js
Expand Down Expand Up @@ -54,36 +91,48 @@ root[2]

## API

This package exports the following identifiers: `inspect`, `inspectColor`, and
This package exports the identifiers `inspect`, `inspectColor`, and
`inspectNoColor`.
There is no default export.

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

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

###### `options.showPositions`

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

###### Returns
##### Returns

`string` — String representing `node`.
Pretty printed `node` (`string`).

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

Inspect, with ANSI color sequences (default in Node).
Inspect with ANSI color sequences (default in Node, Deno).

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

Inspect, but without ANSI color sequences (default in browser).
Inspect without ANSI color sequences (default in browser, `react-native`).

## Types

This package is fully typed with [TypeScript][].
It exports the additional type `Options`.

## Compatibility

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

## Contribute

See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
started.
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
ways to get started.
See [`support.md`][support] for ways to get help.

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

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

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

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

[node]: https://github.com/syntax-tree/unist#node
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

[esmsh]: https://esm.sh

[typescript]: https://www.typescriptlang.org

[license]: license

[author]: https://wooorm.com

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

[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md

[support]: https://github.com/syntax-tree/.github/blob/main/support.md

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

[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
[unist]: https://github.com/syntax-tree/unist

[node]: https://github.com/syntax-tree/unist#node

0 comments on commit 1e58f86

Please sign in to comment.