Skip to content

Commit 1e417be

Browse files
committed
Add separate exports of functions
1 parent 9c5ac78 commit 1e417be

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

lib/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,14 @@ export function toVFile(options) {
4343
return looksLikeAVFile(options) ? options : new VFile(options)
4444
}
4545

46-
toVFile.readSync = readSync
47-
toVFile.writeSync = writeSync
48-
4946
/**
5047
* Create a virtual file and read it in, synchronously.
5148
*
5249
* @param {Compatible} description
5350
* @param {ReadOptions} [options]
5451
* @returns {VFile}
5552
*/
56-
function readSync(description, options) {
53+
export function readSync(description, options) {
5754
var file = toVFile(description)
5855
file.value = fs.readFileSync(path.resolve(file.cwd, file.path), options)
5956
return file
@@ -66,13 +63,13 @@ function readSync(description, options) {
6663
* @param {WriteOptions} [options]
6764
* @returns {VFile}
6865
*/
69-
function writeSync(description, options) {
66+
export function writeSync(description, options) {
7067
var file = toVFile(description)
7168
fs.writeFileSync(path.resolve(file.cwd, file.path), file.value || '', options)
7269
return file
7370
}
7471

75-
toVFile.read =
72+
export const read =
7673
/**
7774
* @type {{
7875
* (description: Compatible, options: ReadOptions, callback: Callback): void
@@ -141,7 +138,7 @@ toVFile.read =
141138
}
142139
)
143140

144-
toVFile.write =
141+
export const write =
145142
/**
146143
* @type {{
147144
* (description: Compatible, options: WriteOptions, callback: Callback): void
@@ -221,3 +218,8 @@ function looksLikeAVFile(value) {
221218
'messages' in value
222219
)
223220
}
221+
222+
toVFile.readSync = readSync
223+
toVFile.writeSync = writeSync
224+
toVFile.read = read
225+
toVFile.write = write

readme.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ npm install to-vfile
2525
## Use
2626

2727
```js
28-
import {toVFile} from 'to-vfile'
28+
import {toVFile, readSync} from 'to-vfile'
2929

3030
console.log(toVFile('readme.md'))
3131
console.log(toVFile(new URL('./readme.md', import.meta.url)))
32-
console.log(toVFile.readSync('.git/HEAD'))
33-
console.log(toVFile.readSync('.git/HEAD', 'utf8'))
32+
console.log(readSync('.git/HEAD'))
33+
console.log(readSync('.git/HEAD', 'utf8'))
3434
```
3535
3636
Yields:
@@ -66,7 +66,8 @@ VFile {
6666
6767
## API
6868
69-
This package exports the following identifiers: `toVFile`.
69+
This package exports the following identifiers: `toVFile`, `read`, `readSync`,
70+
`write`, and `writeSync`.
7071
There is no default export.
7172
7273
### `toVFile(options)`
@@ -77,7 +78,7 @@ Works like the [vfile][] constructor, except when `options` is `string` or
7778
`{value: options}`, or when `options` is a WHATWG `URL` object, in which case
7879
it’s treated as `{path: fileURLToPath(options)}`.
7980
80-
### `toVFile.read(options[, encoding][, callback])`
81+
### `read(options[, encoding][, callback])`
8182
8283
Creates a virtual file from options (`toVFile(options)`), reads the file from
8384
the file system and populates `file.value` with the result.
@@ -87,12 +88,12 @@ file.
8788
If `callback` is not given, returns a [`Promise`][promise] that is rejected with
8889
an error or resolved with the populated virtual file.
8990
90-
### `toVFile.readSync(options[, encoding])`
91+
### `readSync(options[, encoding])`
9192
92-
Like `toVFile.read` but synchronous.
93+
Like `read` but synchronous.
9394
Either throws an error or returns a populated virtual file.
9495
95-
### `toVFile.write(options[, fsOptions][, callback])`
96+
### `write(options[, fsOptions][, callback])`
9697
9798
Creates a virtual file from `options` (`toVFile(options)`), writes the file to
9899
the file system.
@@ -101,9 +102,9 @@ If `callback` is given, invokes it with an error, if any.
101102
If `callback` is not given, returns a [`Promise`][promise] that is rejected with
102103
an error or resolved with the written virtual file.
103104
104-
### `toVFile.writeSync(options[, fsOptions])`
105+
### `writeSync(options[, fsOptions])`
105106
106-
Like `toVFile.write` but synchronous.
107+
Like `write` but synchronous.
107108
Either throws an error or returns a populated virtual file.
108109
109110
## Contribute

0 commit comments

Comments
 (0)