Skip to content

Commit 9501371

Browse files
committed
Add improved docs
1 parent 595c2b1 commit 9501371

File tree

1 file changed

+63
-11
lines changed

1 file changed

+63
-11
lines changed

readme.md

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
* [Use](#use)
1919
* [API](#api)
2020
* [`fromJs(value[, options])`](#fromjsvalue-options)
21+
* [`Options`](#options)
22+
* [`Plugin`](#plugin)
23+
* [`Value`](#value)
24+
* [`Version`](#version)
2125
* [Types](#types)
2226
* [Compatibility](#compatibility)
2327
* [Contribute](#contribute)
@@ -41,7 +45,7 @@ It turns the tree into a string of JavaScript.
4145
## Install
4246

4347
This package is [ESM only][esm].
44-
In Node.js (version 14.14+, 16.0+, or 18.0+), install with [npm][]:
48+
In Node.js (version 14.14+ or 16.0+), install with [npm][]:
4549

4650
```sh
4751
npm install esast-util-from-js
@@ -105,8 +109,8 @@ Yields:
105109
sourceType: 'module',
106110
comments: [],
107111
position: {
108-
start: { line: 1, column: 1, offset: 0 },
109-
end: { line: 7, column: 1, offset: 157 }
112+
start: {line: 1, column: 1, offset: 0},
113+
end: {line: 7, column: 1, offset: 157}
110114
}
111115
}
112116
```
@@ -120,13 +124,25 @@ There is no default export.
120124

121125
Parse a JavaScript (`string` or `Buffer` in UTF-8) to an esast ([`Node`][node]).
122126

123-
##### `options`
127+
###### Parameters
124128

125-
Configuration (optional).
129+
* `value` ([`Value`][value])
130+
— serialized JavaScript to parse
131+
* `options` ([`Options`][options], optional)
132+
— configuration
133+
134+
###### Returns
135+
136+
Tree (`Program`).
137+
138+
### `Options`
139+
140+
Configuration (TypeScript type).
126141

127142
###### `options.version`
128143

129-
JavaScript version (`number` or `'latest'`, default: `'latest'`).
144+
JavaScript version ([`Version`][version], default: `'latest'`).
145+
130146
When a number, must be a year in the range `2015` and `2022` (both including).
131147
`'latest'` is the same as passing the latest supported year.
132148

@@ -163,23 +179,51 @@ Whether a shell hasbang is allowed (`boolean`, default: `false`).
163179

164180
###### `options.plugins`
165181

166-
List of acorn plugins (`Array<Plugin>`).
182+
List of acorn plugins ([`Array<Plugin>`][plugin], default: `[]`).
167183
Examples are [`acorn-jsx`][acorn-jsx] and [`acorn-stage3`][acorn-stage3].
168184

169-
##### Returns
185+
### `Plugin`
186+
187+
Acorn plugin (TypeScript type).
170188

171-
Tree ([`Node`][node]).
189+
###### Type
190+
191+
```ts
192+
type Plugin = (Parser: ParserClass) => ParserClass
193+
```
194+
195+
### `Value`
196+
197+
Input value (TypeScript type).
198+
199+
###### Type
200+
201+
```ts
202+
type Value = string | Buffer // `Buffer` is added when Node.js types ere used.
203+
```
204+
205+
### `Version`
206+
207+
JavaScript version (TypeScript type).
208+
209+
`'latest'` is equivalent to the latest supported year.
210+
211+
###### Type
212+
213+
```ts
214+
type Version = 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 'latest'
215+
```
172216
173217
## Types
174218
175219
This package is fully typed with [TypeScript][].
176-
It exports the additional types `Value`, `Options`, `Version`, and `Plugin`.
220+
It exports the additional types `Options`, `Plugin`, `Value`, and `Version`.
177221
178222
## Compatibility
179223
180224
Projects maintained by the unified collective are compatible with all maintained
181225
versions of Node.js.
182-
As of now, that is Node.js 14.14+, 16.0+, and 18.0+.
226+
As of now, that is Node.js 14.14+ and 16.0+.
183227
Our projects sometimes work with older versions, but this is not guaranteed.
184228
185229
## Contribute
@@ -261,3 +305,11 @@ abide by its terms.
261305
[acorn-stage3]: https://github.com/acornjs/acorn-stage3
262306
263307
[estree-util-to-js]: https://github.com/syntax-tree/estree-util-to-js
308+
309+
[options]: #options
310+
311+
[plugin]: #plugin
312+
313+
[value]: #value
314+
315+
[version]: #version

0 commit comments

Comments
 (0)