Skip to content

Commit b0eb751

Browse files
manidlouRyanZim
andauthored
Improve docs (#795)
* improve docs * Update docs/ensureSymlink-sync.md Co-authored-by: Ryan Zimmerman <[email protected]> * Update docs/ensureSymlink.md Co-authored-by: Ryan Zimmerman <[email protected]> * add Error type to docs Co-authored-by: Ryan Zimmerman <[email protected]>
1 parent a2738d3 commit b0eb751

24 files changed

+77
-72
lines changed

docs/copy-sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# copySync(src, dest[, options])
22

3-
Copy a file or directory. The directory can have contents. Like `cp -r`.
3+
Copy a file or directory. The directory can have contents.
44

55
- `src` `<String>` Note that if `src` is a directory it will copy everything inside of this directory, not the entire directory itself (see [issue #537](https://github.com/jprichardson/node-fs-extra/issues/537)).
66
- `dest` `<String>` Note that if `src` is a file, `dest` cannot be a directory (see [issue #323](https://github.com/jprichardson/node-fs-extra/issues/323)).

docs/copy.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# copy(src, dest[, options][, callback])
22

3-
Copy a file or directory. The directory can have contents. Like `cp -r`.
3+
Copy a file or directory. The directory can have contents.
44

55
- `src` `<String>` Note that if `src` is a directory it will copy everything inside of this directory, not the entire directory itself (see [issue #537](https://github.com/jprichardson/node-fs-extra/issues/537)).
66
- `dest` `<String>` Note that if `src` is a file, `dest` cannot be a directory (see [issue #323](https://github.com/jprichardson/node-fs-extra/issues/323)).
@@ -11,6 +11,7 @@ Copy a file or directory. The directory can have contents. Like `cp -r`.
1111
- `preserveTimestamps` `<boolean>`: When true, will set last modification and access times to the ones of the original source files. When false, timestamp behavior is OS-dependent. Default is `false`.
1212
- `filter` `<Function>`: Function to filter copied files. Return `true` to include, `false` to exclude. Can also return a `Promise` that resolves to `true` or `false` (or pass in an `async` function).
1313
- `callback` `<Function>`
14+
- `err` `<Error>`
1415

1516
## Example:
1617

@@ -20,13 +21,11 @@ const fs = require('fs-extra')
2021
// With a callback:
2122
fs.copy('/tmp/myfile', '/tmp/mynewfile', err => {
2223
if (err) return console.error(err)
23-
2424
console.log('success!')
2525
}) // copies file
2626

2727
fs.copy('/tmp/mydir', '/tmp/mynewdir', err => {
2828
if (err) return console.error(err)
29-
3029
console.log('success!')
3130
}) // copies directory, even if it has subdirectories or files
3231

@@ -64,7 +63,6 @@ const filterFunc = (src, dest) => {
6463

6564
fs.copy('/tmp/mydir', '/tmp/mynewdir', { filter: filterFunc }, err => {
6665
if (err) return console.error(err)
67-
6866
console.log('success!')
6967
})
7068
```

docs/emptyDir.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Ensures that a directory is empty. Deletes directory contents if the directory i
66

77
- `dir` `<String>`
88
- `callback` `<Function>`
9+
- `err` `<Error>`
910

1011
## Example:
1112

@@ -16,7 +17,6 @@ const fs = require('fs-extra')
1617
// With a callback:
1718
fs.emptyDir('/tmp/some/dir', err => {
1819
if (err) return console.error(err)
19-
2020
console.log('success!')
2121
})
2222

docs/ensureDir-sync.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# ensureDirSync(dir[,options])
22

3-
Ensures that the directory exists. If the directory structure does not exist, it is created. Like `mkdir -p`. If provided, options may specify the desired mode for the directory.
3+
Ensures that the directory exists. If the directory structure does not exist, it is created. If provided, options may specify the desired mode for the directory.
44

55
**Aliases:** `mkdirsSync()`, `mkdirpSync()`
66

77
- `dir` `<String>`
88
- `options` `<Integer>|<Object>`
9+
- If it is `Integer`, it will be `mode`.
10+
- If it is `Object`, it will be `{ mode: <Integer> }`.
11+
912
## Example:
1013

1114
```js

docs/ensureDir.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# ensureDir(dir[,options][,callback])
22

3-
Ensures that the directory exists. If the directory structure does not exist, it is created. Like `mkdir -p`.
3+
Ensures that the directory exists. If the directory structure does not exist, it is created.
44

55
**Aliases:** `mkdirs()`, `mkdirp()`
66

77
- `dir` `<String>`
88
- `options` `<Integer>|<Object>`
9+
- If it is `Integer`, it will be `mode`.
10+
- If it is `Object`, it will be `{ mode: <Integer> }`.
911
- `callback` `<Function>`
12+
- `err` `<Error>`
1013

1114
## Example:
1215

docs/ensureFile.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Ensures that the file exists. If the file that is requested to be created is in
66

77
- `file` `<String>`
88
- `callback` `<Function>`
9+
- `err` `<Error>`
910

1011
## Example:
1112

docs/ensureLink-sync.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# ensureLinkSync(srcpath, dstpath)
1+
# ensureLinkSync(srcPath, destPath)
22

33
Ensures that the link exists. If the directory structure does not exist, it is created.
44

55
**Alias:** `createLinkSync()`
66

7-
- `srcpath` `<String>`
8-
- `dstpath` `<String>`
7+
- `srcPath` `<String>`
8+
- `destPath` `<String>`
99

1010
## Example:
1111

1212
```js
1313
const fs = require('fs-extra')
1414

15-
const srcpath = '/tmp/file.txt'
16-
const dstpath = '/tmp/this/path/does/not/exist/file.txt'
17-
fs.ensureLinkSync(srcpath, dstpath)
15+
const srcPath = '/tmp/file.txt'
16+
const destPath = '/tmp/this/path/does/not/exist/file.txt'
17+
fs.ensureLinkSync(srcPath, destPath)
1818
// link has now been created, including the directory it is to be placed in
1919
```

docs/ensureLink.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
# ensureLink(srcpath, dstpath[, callback])
1+
# ensureLink(srcPath, destPath[, callback])
22

33
Ensures that the link exists. If the directory structure does not exist, it is created.
44

55
**Alias:** `createLink()`
66

7-
- `srcpath` `<String>`
8-
- `dstpath` `<String>`
7+
- `srcPath` `<String>`
8+
- `destPath` `<String>`
99
- `callback` `<Function>`
10+
- `err` `<Error>`
1011

1112
## Example:
1213

1314
```js
1415
const fs = require('fs-extra')
1516

16-
const srcpath = '/tmp/file.txt'
17-
const dstpath = '/tmp/this/path/does/not/exist/file.txt'
17+
const srcPath = '/tmp/file.txt'
18+
const destPath = '/tmp/this/path/does/not/exist/file.txt'
1819

1920
// With a callback:
20-
fs.ensureLink(srcpath, dstpath, err => {
21+
fs.ensureLink(srcPath, destPath, err => {
2122
console.log(err) // => null
2223
// link has now been created, including the directory it is to be placed in
2324
})
2425

2526
// With Promises:
26-
fs.ensureLink(srcpath, dstpath)
27+
fs.ensureLink(srcPath, destPath)
2728
.then(() => {
2829
console.log('success!')
2930
})
@@ -41,5 +42,5 @@ async function example (src, dest) {
4142
}
4243
}
4344

44-
example(srcpath, dstpath)
45+
example(srcPath, destPath)
4546
```

docs/ensureSymlink-sync.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# ensureSymlinkSync(srcpath, dstpath[, type])
1+
# ensureSymlinkSync(srcPath, destPath[, type])
22

33
Ensures that the symlink exists. If the directory structure does not exist, it is created.
44

55
**Alias:** `createSymlinkSync()`
66

7-
- `srcpath` `<String>`
8-
- `dstpath` `<String>`
9-
- `type` `<String>`
7+
- `srcPath` `<String>`
8+
- `destPath` `<String>`
9+
- `type` `<String>` It is only available on Windows and ignored on other platforms. It can be set to `dir`, `file`, or `junction`.
1010

1111
## Example:
1212

1313
```js
1414
const fs = require('fs-extra')
1515

16-
const srcpath = '/tmp/file.txt'
17-
const dstpath = '/tmp/this/path/does/not/exist/file.txt'
18-
fs.ensureSymlinkSync(srcpath, dstpath)
16+
const srcPath = '/tmp/file.txt'
17+
const destPath = '/tmp/this/path/does/not/exist/file.txt'
18+
fs.ensureSymlinkSync(srcPath, destPath)
1919
// symlink has now been created, including the directory it is to be placed in
2020
```

docs/ensureSymlink.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
# ensureSymlink(srcpath, dstpath[, type][, callback])
1+
# ensureSymlink(srcPath, destPath[, type][, callback])
22

33
Ensures that the symlink exists. If the directory structure does not exist, it is created.
44

55
**Alias:** `createSymlink()`
66

7-
- `srcpath` `<String>`
8-
- `dstpath` `<String>`
9-
- `type` `<String>`
7+
- `srcPath` `<String>`
8+
- `destPath` `<String>`
9+
- `type` `<String>` It is only available on Windows and ignored on other platforms. It can be set to `dir`, `file`, or `junction`.
1010
- `callback` `<Function>`
11+
- `err` `<Error>`
1112

1213
## Example:
1314

1415
```js
1516
const fs = require('fs-extra')
1617

17-
const srcpath = '/tmp/file.txt'
18-
const dstpath = '/tmp/this/path/does/not/exist/file.txt'
18+
const srcPath = '/tmp/file.txt'
19+
const destPath = '/tmp/this/path/does/not/exist/file.txt'
1920

2021
// With a callback:
21-
fs.ensureSymlink(srcpath, dstpath, err => {
22+
fs.ensureSymlink(srcPath, destPath, err => {
2223
console.log(err) // => null
2324
// symlink has now been created, including the directory it is to be placed in
2425
})
2526

2627
// With Promises:
27-
fs.ensureSymlink(srcpath, dstpath)
28+
fs.ensureSymlink(srcPath, destPath)
2829
.then(() => {
2930
console.log('success!')
3031
})
@@ -42,5 +43,5 @@ async function example (src, dest) {
4243
}
4344
}
4445

45-
example(srcpath, dstpath)
46+
example(srcPath, destPath)
4647
```

docs/move-sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ fs.moveSync('/tmp/somefile', '/tmp/does/not/exist/yet/somefile')
2020
```js
2121
const fs = require('fs-extra')
2222

23-
fs.moveSync('/tmp/somedir', '/tmp/may/already/existed/somedir', { overwrite: true })
23+
fs.moveSync('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true })
2424
```

docs/move.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ Moves a file or directory, even across devices.
77
- `options` `<Object>`
88
- `overwrite` `<boolean>`: overwrite existing file or directory, default is `false`.
99
- `callback` `<Function>`
10+
- `err` `<Error>`
1011

1112
## Example:
1213

1314
```js
1415
const fs = require('fs-extra')
1516

16-
const srcpath = '/tmp/file.txt'
17-
const dstpath = '/tmp/this/path/does/not/exist/file.txt'
17+
const src = '/tmp/file.txt'
18+
const dest = '/tmp/this/path/does/not/exist/file.txt'
1819

1920
// With a callback:
20-
fs.move(srcpath, dstpath, err => {
21+
fs.move(src, dest, err => {
2122
if (err) return console.error(err)
22-
2323
console.log('success!')
2424
})
2525

2626
// With Promises:
27-
fs.move(srcpath, dstpath)
27+
fs.move(src, dest)
2828
.then(() => {
2929
console.log('success!')
3030
})
@@ -35,24 +35,23 @@ fs.move(srcpath, dstpath)
3535
// With async/await:
3636
async function example (src, dest) {
3737
try {
38-
await fs.move(srcpath, dstpath)
38+
await fs.move(src, dest)
3939
console.log('success!')
4040
} catch (err) {
4141
console.error(err)
4242
}
4343
}
4444

45-
example(srcpath, dstpath)
45+
example(src, dest)
4646
```
4747

4848
**Using `overwrite` option**
4949

5050
```js
5151
const fs = require('fs-extra')
5252

53-
fs.move('/tmp/somedir', '/tmp/may/already/existed/somedir', { overwrite: true }, err => {
53+
fs.move('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true }, err => {
5454
if (err) return console.error(err)
55-
5655
console.log('success!')
5756
})
5857
```

docs/outputFile-sync.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# outputFileSync(file, data[, options])
22

3-
Almost the same as `writeFileSync` (i.e. it [overwrites](http://pages.citebite.com/v2o5n8l2f5reb)), except that if the parent directory does not exist, it's created. `file` must be a file path (a buffer or a file descriptor is not allowed). `options` are what you'd pass to [`fs.writeFileSync()`](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options).
3+
Almost the same as `writeFileSync` (i.e. it [overwrites](http://pages.citebite.com/v2o5n8l2f5reb)), except that if the parent directory does not exist, it's created. `file` must be a file path (a buffer or a file descriptor is not allowed).
44

55
- `file` `<String>`
66
- `data` `<String> | <Buffer> | <Uint8Array>`
7-
- `options` `<Object> | <String>`
7+
- `options` `<Object> | <String>` (the same as [`fs.writeFileSync()` options](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options))
88

99
## Example:
1010

docs/outputFile.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# outputFile(file, data[, options][, callback])
22

3-
Almost the same as `writeFile` (i.e. it [overwrites](http://pages.citebite.com/v2o5n8l2f5reb)), except that if the parent directory does not exist, it's created. `file` must be a file path (a buffer or a file descriptor is not allowed). `options` are what you'd pass to [`fs.writeFile()`](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback).
3+
Almost the same as `writeFile` (i.e. it [overwrites](http://pages.citebite.com/v2o5n8l2f5reb)), except that if the parent directory does not exist, it's created. `file` must be a file path (a buffer or a file descriptor is not allowed).
44

55
- `file` `<String>`
66
- `data` `<String> | <Buffer> | <Uint8Array>`
7-
- `options` `<Object> | <String>`
7+
- `options` `<Object> | <String>` (the same as [`fs.writeFile()` options](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback))
88
- `callback` `<Function>`
9+
- `err` `<Error>`
910

1011
## Example:
1112

docs/outputJson-sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Almost the same as [`writeJsonSync`](writeJson-sync.md), except that if the dire
1010
- `spaces` `<Number|String>` Number of spaces to indent; or a string to use for indentation (i.e. pass `'\t'` for tab indentation). See [the docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) for more info.
1111
- `EOL` `<String>` Set EOL character. Default is `\n`.
1212
- `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)
13-
- Also accepts [`fs.writeFileSync` options](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options)
13+
- Also accepts [`fs.writeFileSync()` options](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options)
1414

1515
## Example:
1616

docs/outputJson.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ Almost the same as [`writeJson`](writeJson.md), except that if the directory doe
1010
- `spaces` `<Number|String>` Number of spaces to indent; or a string to use for indentation (i.e. pass `'\t'` for tab indentation). See [the docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) for more info.
1111
- `EOL` `<String>` Set EOL character. Default is `\n`.
1212
- `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)
13-
- Also accepts [`fs.writeFile` options](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback)
13+
- Also accepts [`fs.writeFile()` options](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback)
1414
- `callback` `<Function>`
15+
- `err` `<Error>`
1516

1617
## Example:
1718

docs/pathExists.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Test whether or not the given path exists by checking with the file system. Like
44

55
- `file` `<String>`
66
- `callback` `<Function>`
7+
- `err` `<Error>`
8+
- `exists` `<boolean>`
79

810
## Example:
911

docs/readJson-sync.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# readJsonSync(file[, options])
22

3-
Reads a JSON file and then parses it into an object. `options` are the same
4-
that you'd pass to [`jsonFile.readFileSync`](https://github.com/jprichardson/node-jsonfile#readfilesyncfilename-options).
3+
Reads a JSON file and then parses it into an object.
54

65
**Alias:** `readJSONSync()`
76

87
- `file` `<String>`
9-
- `options` `<Object>`
8+
- `options` `<Object>` (the same as [`jsonFile.readFileSync()` options](https://github.com/jprichardson/node-jsonfile#readfilesyncfilename-options))
109

1110
## Example:
1211

0 commit comments

Comments
 (0)