Skip to content

Commit 5af0a42

Browse files
committed
Add improved docs
1 parent 6bbf257 commit 5af0a42

File tree

1 file changed

+91
-18
lines changed

1 file changed

+91
-18
lines changed

readme.md

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

11-
[**unist**][unist] utility to remove [`position`][position]s from tree.
11+
[unist][] utility to create a remove positional info from a tree.
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+
* [`removePosition(node[, force])`](#removepositionnode-force)
21+
* [Types](#types)
22+
* [Compatibility](#compatibility)
23+
* [Contribute](#contribute)
24+
* [License](#license)
25+
26+
## What is this?
27+
28+
This is a small utility that helps you remove the `position` field from nodes in
29+
a unist tree.
30+
31+
## When should I use this?
32+
33+
Often, positional info is the whole reason, or an important reason, for using
34+
ASTs.
35+
Sometimes, especially when comparing trees, or when inserting one tree into
36+
another, the positional info is at best useless and at worst harmful.
37+
In those cases, you can use this utility to remove `position` fields from a
38+
tree.
39+
40+
You might find the utility [`unist-util-position`][unist-util-position]
41+
useful to instead get clean position info from a tree, or
42+
[`unist-util-generated`][unist-util-generated] useful to check whether a node is
43+
considered to be generated (not in the original input file).
1444

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.
45+
You might also enjoy
46+
[`unist-util-stringify-position`][unist-util-stringify-position] when you want
47+
to display positional info to users.
1748

18-
[npm][]:
49+
## Install
50+
51+
This package is [ESM only][esm].
52+
In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]:
1953

2054
```sh
2155
npm install unist-util-remove-position
2256
```
2357

58+
In Deno with [`esm.sh`][esmsh]:
59+
60+
```js
61+
import {removePosition} from "https://esm.sh/unist-util-remove-position@4"
62+
```
63+
64+
In browsers with [`esm.sh`][esmsh]:
65+
66+
```html
67+
<script type="module">
68+
import {removePosition} from "https://esm.sh/unist-util-remove-position@4?bundle"
69+
</script>
70+
```
71+
2472
## Use
2573

2674
```js
27-
import remark from 'remark'
75+
import {fromMarkdown} from 'mdast-util-from-markdown'
2876
import {removePosition} from 'unist-util-remove-position'
2977

30-
const tree = remark().parse('Some _emphasis_, **importance**, and `code`.')
78+
const tree = fromMarkdown('Some _emphasis_, **importance**, and `code`.')
3179

3280
removePosition(tree, true)
3381

@@ -58,22 +106,35 @@ Yields:
58106

59107
## API
60108

61-
This package exports the following identifiers: `removePosition`.
109+
This package exports the identifier `removePosition`.
62110
There is no default export.
63111

64112
### `removePosition(node[, force])`
65113

66-
Remove [`position`][position] fields from [`node`][node].
67-
If `force` is given, uses `delete`, otherwise, sets `position`s to `undefined`.
114+
Remove the `position` field from a tree ([`Node`][node]).
115+
If `force` is given (`boolean`, default: `false`), uses `delete` to remove the
116+
field entirely, otherwise it’s set to `undefined`.
68117

69118
###### Returns
70119

71-
The given `node`.
120+
The given, modified, `node` ([`Node`][node]).
121+
122+
## Types
123+
124+
This package is fully typed with [TypeScript][].
125+
It exports no additional types.
126+
127+
## Compatibility
128+
129+
Projects maintained by the unified collective are compatible with all maintained
130+
versions of Node.js.
131+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
132+
Our projects sometimes work with older versions, but this is not guaranteed.
72133

73134
## Contribute
74135

75-
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
76-
started.
136+
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
137+
ways to get started.
77138
See [`support.md`][support] for ways to get help.
78139

79140
This project has a [code of conduct][coc].
@@ -114,18 +175,30 @@ abide by its terms.
114175

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

178+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
179+
180+
[esmsh]: https://esm.sh
181+
182+
[typescript]: https://www.typescriptlang.org
183+
117184
[license]: license
118185

119186
[author]: https://wooorm.com
120187

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

123-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
190+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
124191

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

127-
[unist]: https://github.com/syntax-tree/unist
194+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
128195

129-
[position]: https://github.com/syntax-tree/unist#position
196+
[unist]: https://github.com/syntax-tree/unist
130197

131198
[node]: https://github.com/syntax-tree/unist#node
199+
200+
[unist-util-position]: https://github.com/syntax-tree/unist-util-position
201+
202+
[unist-util-generated]: https://github.com/syntax-tree/unist-util-generated
203+
204+
[unist-util-stringify-position]: https://github.com/syntax-tree/unist-util-stringify-position

0 commit comments

Comments
 (0)