18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
20
* [ ` matter(file[, options]) ` ] ( #matterfile-options )
21
+ * [ ` Options ` ] ( #options )
22
+ * [ ` YamlOptions ` ] ( #yamloptions )
21
23
* [ Types] ( #types )
22
24
* [ Compatibility] ( #compatibility )
23
25
* [ Contribute] ( #contribute )
@@ -47,7 +49,7 @@ stripping frontmatter.
47
49
## Install
48
50
49
51
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] [ ] :
51
53
52
54
``` sh
53
55
npm install vfile-matter
@@ -104,52 +106,72 @@ console.log(String(file))
104
106
105
107
## API
106
108
107
- This package exports the identifier ` matter ` .
109
+ This package exports the identifier [ ` matter ` ] [ api-matter ] .
108
110
There is no default export.
109
111
110
112
### ` matter(file[, options]) `
111
113
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 ` .
114
115
115
116
If no matter is found in the file, nothing happens, except that
116
117
` file.data.matter ` is set to an empty object (` {} ` ).
117
118
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).
119
133
120
- Configuration (optional).
134
+ ###### Fields
121
135
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) `
123
141
124
- Remove the YAML front matter from the file ( ` boolean ` , default: ` false ` ).
142
+ ### ` YamlOptions `
125
143
126
- ###### ` options.yaml `
144
+ Options for the YAML parser (TypeScript type).
127
145
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
131
147
[ ` ParseOptions ` ] ( https://eemeli.org/yaml/#parse-options ) ,
132
148
[ ` DocumentOptions ` ] ( https://eemeli.org/yaml/#document-options ) ,
133
149
[ ` SchemaOptions ` ] ( https://eemeli.org/yaml/#schema-options ) , and
134
150
[ ` ToJsOptions ` ] ( https://eemeli.org/yaml/#tojs-options ) .
135
151
136
- ###### Returns
152
+ ###### Type
137
153
138
- The given ` file ` ([ ` VFile ` ] [ vfile ] ).
154
+ ``` ts
155
+ type YamlOptions = ParseOptions &
156
+ DocumentOptions &
157
+ SchemaOptions &
158
+ ToJsOptions
159
+ ` ` `
139
160
140
161
## Types
141
162
142
163
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].
144
166
145
167
To type ` file .data .matter ` , you can augment ` DataMap ` from ` vfile ` as follows:
146
168
147
169
` ` ` ts
148
170
declare module ' vfile' {
149
171
interface DataMap {
150
172
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
153
175
}
154
176
}
155
177
}
@@ -159,7 +181,7 @@ declare module 'vfile' {
159
181
160
182
Projects maintained by the unified collective are compatible with all maintained
161
183
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+.
163
185
Our projects sometimes work with older versions, but this is not guaranteed.
164
186
165
187
## Contribute
@@ -231,3 +253,9 @@ abide by its terms.
231
253
[ remark-frontmatter ] : https://github.com/remarkjs/remark-frontmatter
232
254
233
255
[ 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