Skip to content

Commit b6778a7

Browse files
committed
Add improved docs
1 parent 9dab570 commit b6778a7

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import {truncate} from 'hast-util-truncate'
2525

2626
/**
27-
* Truncate the tree to a certain comment.
27+
* Truncate `tree` to a certain comment.
2828
*
2929
* @template {Node} Tree
3030
* Type of tree.

readme.md

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`excerpt(tree, options?)`](#excerpttree-options)
20+
* [`excerpt(tree[, options])`](#excerpttree-options)
21+
* [`Options`](#options)
22+
* [Syntax tree](#syntax-tree)
2123
* [Types](#types)
2224
* [Compatibility](#compatibility)
2325
* [Security](#security)
@@ -47,7 +49,7 @@ a document, for use with [`rehype-meta`][rehype-meta].
4749
## Install
4850

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

5254
```sh
5355
npm install hast-util-excerpt
@@ -113,48 +115,62 @@ console.log(excerpt(tree));
113115

114116
## API
115117

116-
This package exports the identifier `excerpt`.
118+
This package exports the identifier [`excerpt`][excerpt].
117119
There is no default export.
118120

119-
### `excerpt(tree, options?)`
121+
### `excerpt(tree[, options])`
120122

121-
Truncate the tree to a comment.
123+
Truncate `tree` to a certain comment.
122124

123-
##### `options`
125+
###### Parameters
124126

125-
Configuration (optional).
127+
* `tree` ([`Node`][node])
128+
— tree to truncate
129+
* `options` ([`Options`][options])
130+
— configuration (optional)
126131

127-
###### `options.comment`
132+
###### Returns
133+
134+
Truncated copy of `tree` ([`Node`][node]) when a comment is found, `undefined`
135+
otherwise.
136+
137+
### `Options`
138+
139+
Configuration (TypeScript type).
140+
141+
##### Fields
142+
143+
###### `comment`
128144

129145
Comment value to search for (`string`, default: `'more'`).
130146

131-
###### `options.maxSearchSize`
147+
###### `maxSearchSize`
132148

133149
How far to search for the comment before bailing (`number`, default: `2048`).
134150
The goal of this project is to find user-defined explicit excerpts, that are
135151
assumed to be somewhat reasonably placed.
136152
This option prevents searching giant documents for some comment that probably
137153
won’t be found at the end.
138154

139-
###### `options.ignore`
155+
###### `ignore`
140156

141-
Nodes to exclude from the resulting tree (`Array<Node>`).
157+
Nodes to exclude from the resulting tree ([`Array<Node>`][node]).
142158
These are not counted towards `size`.
143159

144-
###### Returns
160+
## Syntax tree
145161

146-
Truncated copy of `tree` if there’s a comment, `undefined` otherwise (`Node?`).
162+
The syntax tree is [hast][].
147163

148164
## Types
149165

150166
This package is fully typed with [TypeScript][].
151-
It exports the additional type `Options`.
167+
It exports the additional type [`Options`][options].
152168

153169
## Compatibility
154170

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

160176
## Security
@@ -243,3 +259,9 @@ abide by its terms.
243259
[rehype-infer-description-meta]: https://github.com/rehypejs/rehype-infer-description-meta
244260

245261
[rehype-meta]: https://github.com/rehypejs/rehype-meta
262+
263+
[excerpt]: #excerpttree-options
264+
265+
[options]: #options
266+
267+
[node]: https://github.com/syntax-tree/hast#nodes

0 commit comments

Comments
 (0)