2
2
* @typedef {import('vfile').VFileValue } Value
3
3
* @typedef {import('vfile').VFileOptions } Options
4
4
* @typedef {import('vfile').BufferEncoding } BufferEncoding
5
+ * Encodings supported by the buffer class.
5
6
*
6
- * @typedef {number | string } Mode
7
- * @typedef {{encoding?: BufferEncoding | null | undefined, flag?: string | undefined} } ReadOptions
8
- * @typedef {{encoding?: null | undefined | BufferEncoding, mode?: Mode | undefined, flag?: string | undefined} } WriteOptions
7
+ * This is a copy of the types from Node and `VFile`.
9
8
*
9
+ * @typedef ReadOptions
10
+ * Configuration for `fs.readFile`.
11
+ * @property {BufferEncoding | null | undefined } [encoding]
12
+ * Encoding to read file as, will turn `file.value` into a string if passed.
13
+ * @property {string | undefined } [flag]
14
+ * File system flags to use.
15
+ *
16
+ * @typedef WriteOptions
17
+ * Configuration for `fs.writeFile`.
18
+ * @property {BufferEncoding | null | undefined } [encoding]
19
+ * Encoding to write file as.
20
+ * @property {number | string | undefined } [mode]
21
+ * File mode (permission and sticky bits) if the file was newly created.
22
+ * @property {string | undefined } [flag]
23
+ * File system flags to use.
10
24
*
11
25
* @typedef {URL | Value } Path
12
26
* URL to file or path to file.
@@ -38,14 +52,16 @@ import {VFile} from 'vfile'
38
52
/**
39
53
* Create a virtual file from a description.
40
54
*
55
+ * This is like `VFile`, but it accepts a file path instead of file cotnents.
56
+ *
41
57
* If `options` is a string, URL, or buffer, it’s used as the path.
42
- * Otherwise, if it’s a `VFile` , that’s returned instead.
58
+ * Otherwise, if it’s a file , that’s returned instead.
43
59
* Otherwise, the options are passed through to `new VFile()`.
44
60
*
45
61
* @param {Compatible | null | undefined } [description]
46
62
* Path to file, file options, or file itself.
47
63
* @returns {VFile }
48
- * Given `VFile` or new `VFile` .
64
+ * Given file or new file .
49
65
*/
50
66
export function toVFile ( description ) {
51
67
if ( typeof description === 'string' || description instanceof URL ) {
@@ -68,7 +84,7 @@ export function toVFile(description) {
68
84
* @param {BufferEncoding | ReadOptions | null | undefined } [options]
69
85
* Encoding to use or Node.JS read options.
70
86
* @returns {VFile }
71
- * Given `VFile` or new `VFile` .
87
+ * Given file or new file .
72
88
*/
73
89
export function readSync ( description , options ) {
74
90
const file = toVFile ( description )
@@ -84,7 +100,7 @@ export function readSync(description, options) {
84
100
* @param {BufferEncoding | WriteOptions | null | undefined } [options]
85
101
* Encoding to use or Node.JS write options.
86
102
* @returns {VFile }
87
- * Given `VFile` or new `VFile` .
103
+ * Given file or new file .
88
104
*/
89
105
export function writeSync ( description , options ) {
90
106
const file = toVFile ( description )
@@ -103,12 +119,12 @@ export function writeSync(description, options) {
103
119
* Callback called when done.
104
120
* @returns
105
121
* Nothing when a callback is given, otherwise promise that resolves to given
106
- * `VFile` or new `VFile` .
122
+ * file or new file .
107
123
*/
108
124
export const read =
109
125
/**
110
126
* @type {{
111
- * (description: Compatible, options: BufferEncoding | ReadOptions, callback: Callback): void
127
+ * (description: Compatible, options: BufferEncoding | ReadOptions | null | undefined , callback: Callback): void
112
128
* (description: Compatible, callback: Callback): void
113
129
* (description: Compatible, options?: BufferEncoding | ReadOptions | null | undefined): Promise<VFile>
114
130
* }}
@@ -185,12 +201,12 @@ export const read =
185
201
* Callback called when done.
186
202
* @returns
187
203
* Nothing when a callback is given, otherwise promise that resolves to given
188
- * `VFile` or new `VFile` .
204
+ * file or new file .
189
205
*/
190
206
export const write =
191
207
/**
192
208
* @type {{
193
- * (description: Compatible, options: BufferEncoding | WriteOptions, callback: Callback): void
209
+ * (description: Compatible, options: BufferEncoding | WriteOptions | null | undefined , callback: Callback): void
194
210
* (description: Compatible, callback: Callback): void
195
211
* (description: Compatible, options?: BufferEncoding | WriteOptions | null | undefined): Promise<VFile>
196
212
* }}
@@ -272,6 +288,7 @@ function looksLikeAVFile(value) {
272
288
)
273
289
}
274
290
291
+ // To do: next major: remove?
275
292
toVFile . readSync = readSync
276
293
toVFile . writeSync = writeSync
277
294
toVFile . read = read
0 commit comments