Skip to content

Commit 97754ef

Browse files
committed
Add improved docs
1 parent 1f66a62 commit 97754ef

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

lib/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ const empty = []
4646
* Truncate the tree to a certain number of characters.
4747
*
4848
* @template {Node} Tree
49+
* Type of tree.
4950
* @param {Tree} tree
51+
* Tree to truncate.
5052
* @param {Options | null | undefined} [options]
53+
* Configuration (optional).
5154
* @returns {Tree}
5255
* A shallow copy of `tree`, truncated.
5356
*/

readme.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`truncate(tree, options?)`](#truncatetree-options)
20+
* [`truncate(tree[, options])`](#truncatetree-options)
21+
* [`Options`](#options)
2122
* [Types](#types)
2223
* [Compatibility](#compatibility)
2324
* [Security](#security)
@@ -47,7 +48,7 @@ document, for use with [`rehype-meta`][rehype-meta].
4748
## Install
4849

4950
This package is [ESM only][esm].
50-
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
51+
In Node.js (version 14.14+ or 16.0+), install with [npm][]:
5152

5253
```sh
5354
npm install hast-util-truncate
@@ -109,16 +110,29 @@ console.log(truncate(tree, {ellipsis: '…'}));
109110

110111
## API
111112

112-
This package exports the identifier `truncate`.
113+
This package exports the identifier [`truncate`][truncate].
113114
There is no default export.
114115

115-
### `truncate(tree, options?)`
116+
### `truncate(tree[, options])`
116117

117118
Truncate the tree to a certain number of characters.
118119

119-
##### `options`
120+
###### Parameters
120121

121-
Configuration (optional).
122+
* `tree` ([`Node`][node])
123+
— tree to truncate
124+
* `options` ([`Options`][options], optional)
125+
— configuration
126+
127+
###### Returns
128+
129+
Truncated copy of `tree` ([`Node`][node]).
130+
131+
### `Options`
132+
133+
Configuration (TypeScript type).
134+
135+
##### Fields
122136

123137
###### `options.size`
124138

@@ -149,27 +163,23 @@ Set `maxCharacterStrip: 0` to not find a nice break.
149163
Nodes to exclude from the resulting tree (`Array<Node>`).
150164
These are not counted towards `size`.
151165

152-
###### Returns
153-
154-
Truncated copy of `tree` (`Node`).
155-
156166
## Types
157167

158168
This package is fully typed with [TypeScript][].
159-
It exports the additional type `Options`.
169+
It exports the additional type [`Options`][options].
160170

161171
## Compatibility
162172

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

168178
## Security
169179

170180
Use of `hast-util-truncate` should be safe if the tree is already safe and
171181
you’re not using user content in options.
172-
When in doubt, use [`hast-util-sanitize`][sanitize].
182+
When in doubt, use [`hast-util-sanitize`][hast-util-sanitize].
173183

174184
## Related
175185

@@ -242,12 +252,18 @@ abide by its terms.
242252

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

245-
[sanitize]: https://github.com/syntax-tree/hast-util-sanitize
246-
247255
[hast]: https://github.com/syntax-tree/hast
248256

257+
[node]: https://github.com/syntax-tree/hast#nodes
258+
259+
[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize
260+
249261
[hast-util-excerpt]: https://github.com/syntax-tree/hast-util-excerpt
250262

251263
[rehype-infer-description-meta]: https://github.com/rehypejs/rehype-infer-description-meta
252264

253265
[rehype-meta]: https://github.com/rehypejs/rehype-meta
266+
267+
[truncate]: #truncatetree-options
268+
269+
[options]: #options

0 commit comments

Comments
 (0)