Skip to content

Commit fe2ed91

Browse files
committed
Add improved docs
1 parent d2cc544 commit fe2ed91

File tree

2 files changed

+54
-26
lines changed

2 files changed

+54
-26
lines changed

lib/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,34 @@
1717
* @typedef {Prettify<ParseOptions & DocumentOptions & SchemaOptions & ToJsOptions>} YamlOptions
1818
* Options for the YAML parser.
1919
*
20+
* Equivalent to `ParseOptions`, `DocumentOptions`, `SchemaOptions`, and `ToJsOptions`.
21+
*
2022
* @typedef Options
2123
* Configuration (optional).
2224
* @property {boolean | null | undefined} [strip=false]
2325
* Remove the YAML front matter from the file.
2426
* @property {YamlOptions | null | undefined} [yaml]
25-
* Options for the YAML parser.
26-
*
27-
* These are passed as `x` in `yaml.parse('', x)`, which is equivalent to
28-
* `ParseOptions`, `DocumentOptions`, `SchemaOptions`, and `ToJsOptions`.
27+
* Configuration for the YAML parser, passed to `yaml` as `x` in
28+
* `yaml.parse('', x)`.
2929
*/
3030

3131
import buffer from 'is-buffer'
3232
import yaml from 'yaml'
3333

3434
/**
35-
* Parse the YAML front matter in a `vfile` and expose it as `file.data.matter`.
35+
* Parse the YAML front matter in a file and expose it as `file.data.matter`.
3636
*
3737
* If no matter is found in the file, nothing happens, except that
3838
* `file.data.matter` is set to an empty object (`{}`).
3939
*
4040
* @template {VFile} File
4141
* File type.
4242
* @param {File} file
43-
* Virtual file
43+
* Virtual file.
4444
* @param {Options | null | undefined} [options]
45-
* Options
45+
* Configuration.
4646
* @returns {File}
47-
* The given `file`
47+
* The given `file`.
4848
*/
4949
// To do: next major: don’t return given file.
5050
export function matter(file, options) {

readme.md

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* [Use](#use)
1919
* [API](#api)
2020
* [`matter(file[, options])`](#matterfile-options)
21+
* [`Options`](#options)
22+
* [`YamlOptions`](#yamloptions)
2123
* [Types](#types)
2224
* [Compatibility](#compatibility)
2325
* [Contribute](#contribute)
@@ -47,7 +49,7 @@ stripping frontmatter.
4749
## Install
4850

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

5254
```sh
5355
npm install vfile-matter
@@ -104,52 +106,72 @@ console.log(String(file))
104106

105107
## API
106108

107-
This package exports the identifier `matter`.
109+
This package exports the identifier [`matter`][api-matter].
108110
There is no default export.
109111

110112
### `matter(file[, options])`
111113

112-
Parse the YAML front matter in a [`vfile`][vfile], and add it as
113-
`file.data.matter`.
114+
Parse the YAML front matter in a file and expose it as `file.data.matter`.
114115

115116
If no matter is found in the file, nothing happens, except that
116117
`file.data.matter` is set to an empty object (`{}`).
117118

118-
##### `options`
119+
###### Parameters
120+
121+
* `file` ([`VFile`][vfile])
122+
— virtual file
123+
* `options` ([`Options`][api-options], optional)
124+
— configuration
125+
126+
###### Returns
127+
128+
The given file ([`VFile`][vfile]).
129+
130+
### `Options`
131+
132+
Configuration (TypeScript type).
119133

120-
Configuration (optional).
134+
###### Fields
121135

122-
###### `options.strip`
136+
* `strip` (`boolean`, default: `false`).
137+
— remove the YAML front matter from the file
138+
* `yaml` ([`YamlOptions`][api-yaml-options], default: {})
139+
— configuration for the YAML parser, passed to [`yaml`][yaml] as `x` in
140+
`yaml.parse('', x)`
123141

124-
Remove the YAML front matter from the file (`boolean`, default: `false`).
142+
### `YamlOptions`
125143

126-
###### `options.yaml`
144+
Options for the YAML parser (TypeScript type).
127145

128-
Options for the YAML parser (default: `{}`).
129-
These are passed to [`yaml`][yaml] as `x` in `yaml.parse('', x)`, which is
130-
equivalent to the combination of
146+
Equivalent to the combination of
131147
[`ParseOptions`](https://eemeli.org/yaml/#parse-options),
132148
[`DocumentOptions`](https://eemeli.org/yaml/#document-options),
133149
[`SchemaOptions`](https://eemeli.org/yaml/#schema-options), and
134150
[`ToJsOptions`](https://eemeli.org/yaml/#tojs-options).
135151

136-
###### Returns
152+
###### Type
137153

138-
The given `file` ([`VFile`][vfile]).
154+
```ts
155+
type YamlOptions = ParseOptions &
156+
DocumentOptions &
157+
SchemaOptions &
158+
ToJsOptions
159+
```
139160
140161
## Types
141162
142163
This package is fully typed with [TypeScript][].
143-
It exports the additional types `YamlOptions` and `Options`.
164+
It exports the additional types [`Options`][api-options] and
165+
[`YamlOptions`][api-yaml-options].
144166
145167
To type `file.data.matter`, you can augment `DataMap` from `vfile` as follows:
146168
147169
```ts
148170
declare module 'vfile' {
149171
interface DataMap {
150172
matter: {
151-
// `file.data.matter.string` is typed as `string?`.
152-
title?: string
173+
// `file.data.matter.string` is typed as `string | undefined`.
174+
title?: string | undefined
153175
}
154176
}
155177
}
@@ -159,7 +181,7 @@ declare module 'vfile' {
159181

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

165187
## Contribute
@@ -231,3 +253,9 @@ abide by its terms.
231253
[remark-frontmatter]: https://github.com/remarkjs/remark-frontmatter
232254

233255
[yaml]: https://github.com/eemeli/yaml
256+
257+
[api-matter]: #matterfile-options
258+
259+
[api-options]: #options
260+
261+
[api-yaml-options]: #yamloptions

0 commit comments

Comments
 (0)