Template Upload
This commit is contained in:
37
node_modules/fs-extra/docs/copy-sync.md
generated
vendored
Normal file
37
node_modules/fs-extra/docs/copy-sync.md
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
# copySync(src, dest, [options])
|
||||
|
||||
Copy a file or directory. The directory can have contents. Like `cp -r`.
|
||||
|
||||
- `src` `<String>`
|
||||
- `dest` `<String>`
|
||||
- `options` `<Object>`
|
||||
- `overwrite` `<boolean>`: overwrite existing file or directory, default is `true`. _Note that the copy operation will silently fail if you set this to `false` and the destination exists._ Use the `errorOnExist` option to change this behavior.
|
||||
- `errorOnExist` `<boolean>`: when `overwrite` is `false` and the destination exists, throw an error. Default is `false`.
|
||||
- `dereference` `<boolean>`: dereference symlinks, default is `false`.
|
||||
- `preserveTimestamps` `<boolean>`: will set last modification and access times to the ones of the original source files, default is `false`.
|
||||
- `filter` `<Function>`: Function to filter copied files. Return `true` to include, `false` to exclude. This can also be a RegExp, however this is deprecated (See [issue #239](https://github.com/jprichardson/node-fs-extra/issues/239) for background).
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
// copy file
|
||||
fs.copySync('/tmp/myfile', '/tmp/mynewfile')
|
||||
|
||||
// copy directory, even if it has subdirectories or files
|
||||
fs.copySync('/tmp/mydir', '/tmp/mynewdir')
|
||||
```
|
||||
|
||||
**Using filter function**
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const filterFunc = (src, dest) => {
|
||||
// your logic here
|
||||
// it will be copied if return true
|
||||
}
|
||||
|
||||
fs.copySync('/tmp/mydir', '/tmp/mynewdir', { filter: filterFunc })
|
||||
```
|
57
node_modules/fs-extra/docs/copy.md
generated
vendored
Normal file
57
node_modules/fs-extra/docs/copy.md
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
# copy(src, dest, [options, callback])
|
||||
|
||||
Copy a file or directory. The directory can have contents. Like `cp -r`.
|
||||
|
||||
- `src` `<String>`
|
||||
- `dest` `<String>`
|
||||
- `options` `<Object>`
|
||||
- `overwrite` `<boolean>`: overwrite existing file or directory, default is `true`. _Note that the copy operation will silently fail if you set this to `false` and the destination exists._ Use the `errorOnExist` option to change this behavior.
|
||||
- `errorOnExist` `<boolean>`: when `overwrite` is `false` and the destination exists, throw an error. Default is `false`.
|
||||
- `dereference` `<boolean>`: dereference symlinks, default is `false`.
|
||||
- `preserveTimestamps` `<boolean>`: will set last modification and access times to the ones of the original source files, default is `false`.
|
||||
- `filter` `<Function>`: Function to filter copied files. Return `true` to include, `false` to exclude. This can also be a RegExp, however this is deprecated (See [issue #239](https://github.com/jprichardson/node-fs-extra/issues/239) for background).
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
fs.copy('/tmp/myfile', '/tmp/mynewfile', err => {
|
||||
if (err) return console.error(err)
|
||||
|
||||
console.log('success!')
|
||||
}) // copies file
|
||||
|
||||
fs.copy('/tmp/mydir', '/tmp/mynewdir', err => {
|
||||
if (err) return console.error(err)
|
||||
|
||||
console.log('success!')
|
||||
}) // copies directory, even if it has subdirectories or files
|
||||
|
||||
// Promise usage:
|
||||
fs.copy('/tmp/myfile', '/tmp/mynewfile')
|
||||
.then(() => {
|
||||
console.log('success!')
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
||||
|
||||
**Using filter function**
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const filterFunc = (src, dest) => {
|
||||
// your logic here
|
||||
// it will be copied if return true
|
||||
}
|
||||
|
||||
fs.copy('/tmp/mydir', '/tmp/mynewdir', { filter: filterFunc }, err => {
|
||||
if (err) return console.error(err)
|
||||
|
||||
console.log('success!')
|
||||
})
|
||||
```
|
16
node_modules/fs-extra/docs/emptyDir-sync.md
generated
vendored
Normal file
16
node_modules/fs-extra/docs/emptyDir-sync.md
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
# emptyDirSync(dir)
|
||||
|
||||
Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.
|
||||
|
||||
**Alias:** `emptydirSync()`
|
||||
|
||||
- `dir` `<String>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
// assume this directory has a lot of files and folders
|
||||
fs.emptyDirSync('/tmp/some/dir')
|
||||
```
|
30
node_modules/fs-extra/docs/emptyDir.md
generated
vendored
Normal file
30
node_modules/fs-extra/docs/emptyDir.md
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
# emptyDir(dir, [callback])
|
||||
|
||||
Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.
|
||||
|
||||
**Alias:** `emptydir()`
|
||||
|
||||
- `dir` `<String>`
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
// assume this directory has a lot of files and folders
|
||||
fs.emptyDir('/tmp/some/dir', err => {
|
||||
if (err) return console.error(err)
|
||||
|
||||
console.log('success!')
|
||||
})
|
||||
|
||||
// With promises
|
||||
fs.emptyDir('/tmp/some/dir')
|
||||
.then(() => {
|
||||
console.log('success!')
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
17
node_modules/fs-extra/docs/ensureDir-sync.md
generated
vendored
Normal file
17
node_modules/fs-extra/docs/ensureDir-sync.md
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
# ensureDirSync(dir)
|
||||
|
||||
Ensures that the directory exists. If the directory structure does not exist, it is created. Like `mkdir -p`.
|
||||
|
||||
**Aliases:** `mkdirsSync()`, `mkdirpSync()`
|
||||
|
||||
- `dir` `<String>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const dir = '/tmp/this/path/does/not/exist'
|
||||
fs.ensureDirSync(dir)
|
||||
// dir has now been created, including the directory it is to be placed in
|
||||
```
|
29
node_modules/fs-extra/docs/ensureDir.md
generated
vendored
Normal file
29
node_modules/fs-extra/docs/ensureDir.md
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
# ensureDir(dir, [callback])
|
||||
|
||||
Ensures that the directory exists. If the directory structure does not exist, it is created. Like `mkdir -p`.
|
||||
|
||||
**Aliases:** `mkdirs()`, `mkdirp()`
|
||||
|
||||
- `dir` `<String>`
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const dir = '/tmp/this/path/does/not/exist'
|
||||
fs.ensureDir(dir, err => {
|
||||
console.log(err) // => null
|
||||
// dir has now been created, including the directory it is to be placed in
|
||||
})
|
||||
|
||||
// With Promises:
|
||||
fs.ensureDir(dir)
|
||||
.then(() => {
|
||||
console.log('success!')
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
17
node_modules/fs-extra/docs/ensureFile-sync.md
generated
vendored
Normal file
17
node_modules/fs-extra/docs/ensureFile-sync.md
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
# ensureFileSync(file)
|
||||
|
||||
Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.
|
||||
|
||||
**Alias:** `createFileSync()`
|
||||
|
||||
- `file` `<String>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const file = '/tmp/this/path/does/not/exist/file.txt'
|
||||
fs.ensureFileSync(file)
|
||||
// file has now been created, including the directory it is to be placed in
|
||||
```
|
29
node_modules/fs-extra/docs/ensureFile.md
generated
vendored
Normal file
29
node_modules/fs-extra/docs/ensureFile.md
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
# ensureFile(file, [callback])
|
||||
|
||||
Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.
|
||||
|
||||
**Alias:** `createFile()`
|
||||
|
||||
- `file` `<String>`
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const file = '/tmp/this/path/does/not/exist/file.txt'
|
||||
fs.ensureFile(file, err => {
|
||||
console.log(err) // => null
|
||||
// file has now been created, including the directory it is to be placed in
|
||||
})
|
||||
|
||||
// With Promises:
|
||||
fs.ensureFile(file)
|
||||
.then(() => {
|
||||
console.log('success!')
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
17
node_modules/fs-extra/docs/ensureLink-sync.md
generated
vendored
Normal file
17
node_modules/fs-extra/docs/ensureLink-sync.md
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
# ensureLinkSync(srcpath, dstpath)
|
||||
|
||||
Ensures that the link exists. If the directory structure does not exist, it is created.
|
||||
|
||||
- `srcpath` `<String>`
|
||||
- `dstpath` `<String>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const srcpath = '/tmp/file.txt'
|
||||
const dstpath = '/tmp/this/path/does/not/exist/file.txt'
|
||||
fs.ensureLinkSync(srcpath, dstpath)
|
||||
// link has now been created, including the directory it is to be placed in
|
||||
```
|
29
node_modules/fs-extra/docs/ensureLink.md
generated
vendored
Normal file
29
node_modules/fs-extra/docs/ensureLink.md
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
# ensureLink(srcpath, dstpath, [callback])
|
||||
|
||||
Ensures that the link exists. If the directory structure does not exist, it is created.
|
||||
|
||||
- `srcpath` `<String>`
|
||||
- `dstpath` `<String>`
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const srcpath = '/tmp/file.txt'
|
||||
const dstpath = '/tmp/this/path/does/not/exist/file.txt'
|
||||
fs.ensureLink(srcpath, dstpath, err => {
|
||||
console.log(err) // => null
|
||||
// link has now been created, including the directory it is to be placed in
|
||||
})
|
||||
|
||||
// With Promises:
|
||||
fs.ensureLink(srcpath, dstpath)
|
||||
.then(() => {
|
||||
console.log('success!')
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
18
node_modules/fs-extra/docs/ensureSymlink-sync.md
generated
vendored
Normal file
18
node_modules/fs-extra/docs/ensureSymlink-sync.md
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
# ensureSymlinkSync(srcpath, dstpath, [type])
|
||||
|
||||
Ensures that the symlink exists. If the directory structure does not exist, it is created.
|
||||
|
||||
- `srcpath` `<String>`
|
||||
- `dstpath` `<String>`
|
||||
- `type` `<String>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const srcpath = '/tmp/file.txt'
|
||||
const dstpath = '/tmp/this/path/does/not/exist/file.txt'
|
||||
fs.ensureSymlinkSync(srcpath, dstpath)
|
||||
// symlink has now been created, including the directory it is to be placed in
|
||||
```
|
30
node_modules/fs-extra/docs/ensureSymlink.md
generated
vendored
Normal file
30
node_modules/fs-extra/docs/ensureSymlink.md
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
# ensureSymlink(srcpath, dstpath, [type, callback])
|
||||
|
||||
Ensures that the symlink exists. If the directory structure does not exist, it is created.
|
||||
|
||||
- `srcpath` `<String>`
|
||||
- `dstpath` `<String>`
|
||||
- `type` `<String>`
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const srcpath = '/tmp/file.txt'
|
||||
const dstpath = '/tmp/this/path/does/not/exist/file.txt'
|
||||
fs.ensureSymlink(srcpath, dstpath, err => {
|
||||
console.log(err) // => null
|
||||
// symlink has now been created, including the directory it is to be placed in
|
||||
})
|
||||
|
||||
// With Promises:
|
||||
fs.ensureSymlink(srcpath, dstpath)
|
||||
.then(() => {
|
||||
console.log('success!')
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
24
node_modules/fs-extra/docs/move-sync.md
generated
vendored
Normal file
24
node_modules/fs-extra/docs/move-sync.md
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# moveSync(src, dest, [options])
|
||||
|
||||
Moves a file or directory, even across devices.
|
||||
|
||||
- `src` `<String>`
|
||||
- `dest` `<String>`
|
||||
- `options` `<Object>`
|
||||
- `overwrite` `<boolean>`: overwrite existing file or directory, default is `false`.
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
fs.moveSync('/tmp/somefile', '/tmp/does/not/exist/yet/somefile')
|
||||
```
|
||||
|
||||
**Using `overwrite` option**
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
fs.moveSync('/tmp/somedir', '/tmp/may/already/existed/somedir', { overwrite: true })
|
||||
```
|
41
node_modules/fs-extra/docs/move.md
generated
vendored
Normal file
41
node_modules/fs-extra/docs/move.md
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
# move(src, dest, [options, callback])
|
||||
|
||||
Moves a file or directory, even across devices.
|
||||
|
||||
- `src` `<String>`
|
||||
- `dest` `<String>`
|
||||
- `options` `<Object>`
|
||||
- `overwrite` `<boolean>`: overwrite existing file or directory, default is `false`.
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
fs.move('/tmp/somefile', '/tmp/does/not/exist/yet/somefile', err => {
|
||||
if (err) return console.error(err)
|
||||
|
||||
console.log('success!')
|
||||
})
|
||||
|
||||
fs.move('/tmp/somefile', '/tmp/does/not/exist/yet/somefile')
|
||||
.then(() => {
|
||||
console.log('success!')
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
||||
|
||||
**Using `overwrite` option**
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
fs.move('/tmp/somedir', '/tmp/may/already/existed/somedir', { overwrite: true }, err => {
|
||||
if (err) return console.error(err)
|
||||
|
||||
console.log('success!')
|
||||
})
|
||||
```
|
19
node_modules/fs-extra/docs/outputFile-sync.md
generated
vendored
Normal file
19
node_modules/fs-extra/docs/outputFile-sync.md
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# outputFileSync(file, data, [options])
|
||||
|
||||
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).
|
||||
|
||||
- `file` `<String>`
|
||||
- `data` `<String> | <Buffer> | <Uint8Array>`
|
||||
- `options` `<Object> | <String>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const file = '/tmp/this/path/does/not/exist/file.txt'
|
||||
fs.outputFileSync(file, 'hello!')
|
||||
|
||||
const data = fs.readFileSync(file, 'utf8')
|
||||
console.log(data) // => hello!
|
||||
```
|
34
node_modules/fs-extra/docs/outputFile.md
generated
vendored
Normal file
34
node_modules/fs-extra/docs/outputFile.md
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
# outputFile(file, data, [options, callback])
|
||||
|
||||
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).
|
||||
|
||||
- `file` `<String>`
|
||||
- `data` `<String> | <Buffer> | <Uint8Array>`
|
||||
- `options` `<Object> | <String>`
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const file = '/tmp/this/path/does/not/exist/file.txt'
|
||||
fs.outputFile(file, 'hello!', err => {
|
||||
console.log(err) // => null
|
||||
|
||||
fs.readFile(file, 'utf8', (err, data) => {
|
||||
if (err) return console.error(err)
|
||||
console.log(data) // => hello!
|
||||
})
|
||||
})
|
||||
|
||||
// With Promises:
|
||||
fs.outputFile(file, 'hello!')
|
||||
.then(() => fs.readFile(file, 'utf8'))
|
||||
.then(data => {
|
||||
console.log(data) // => hello!
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
22
node_modules/fs-extra/docs/outputJson-sync.md
generated
vendored
Normal file
22
node_modules/fs-extra/docs/outputJson-sync.md
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# outputJsonSync(file, object, [options])
|
||||
|
||||
Almost the same as [`writeJsonSync`](writeJson-sync.md), except that if the directory does not exist, it's created.
|
||||
`options` are what you'd pass to [`jsonFile.writeFileSync()`](https://github.com/jprichardson/node-jsonfile#writefilesyncfilename-obj-options).
|
||||
|
||||
**Alias:** `outputJSONSync()`
|
||||
|
||||
- `file` `<String>`
|
||||
- `object` `<Object>`
|
||||
- `options` `<Object>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const file = '/tmp/this/path/does/not/exist/file.json'
|
||||
fs.outputJsonSync(file, {name: 'JP'})
|
||||
|
||||
const data = fs.readJsonSync(file)
|
||||
console.log(data.name) // => JP
|
||||
```
|
37
node_modules/fs-extra/docs/outputJson.md
generated
vendored
Normal file
37
node_modules/fs-extra/docs/outputJson.md
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
# outputJson(file, object, [options, callback])
|
||||
|
||||
Almost the same as [`writeJson`](writeJson.md), except that if the directory does not exist, it's created.
|
||||
`options` are what you'd pass to [`jsonFile.writeFile()`](https://github.com/jprichardson/node-jsonfile#writefilefilename-options-callback).
|
||||
|
||||
**Alias:** `outputJSON()`
|
||||
|
||||
- `file` `<String>`
|
||||
- `object` `<Object>`
|
||||
- `options` `<Object>`
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const file = '/tmp/this/path/does/not/exist/file.json'
|
||||
fs.outputJson(file, {name: 'JP'}, err => {
|
||||
console.log(err) // => null
|
||||
|
||||
fs.readJson(file, (err, data) => {
|
||||
if (err) return console.error(err)
|
||||
console.log(data.name) // => JP
|
||||
})
|
||||
})
|
||||
|
||||
// With Promises:
|
||||
fs.outputJson(file, {name: 'JP'})
|
||||
.then(() => fs.readJson(file))
|
||||
.then(data => {
|
||||
console.log(data.name) // => JP
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
3
node_modules/fs-extra/docs/pathExists-sync.md
generated
vendored
Normal file
3
node_modules/fs-extra/docs/pathExists-sync.md
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# pathExistsSync(file)
|
||||
|
||||
An alias for [`fs.existsSync()`](https://nodejs.org/api/fs.html#fs_fs_existssync_path), created for consistency with [`pathExists()`](pathExists.md).
|
22
node_modules/fs-extra/docs/pathExists.md
generated
vendored
Normal file
22
node_modules/fs-extra/docs/pathExists.md
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# pathExists(file[, callback])
|
||||
|
||||
Test whether or not the given path exists by checking with the file system. Like [`fs.exists`](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback), but with a normal callback signature (err, exists). Uses `fs.access` under the hood.
|
||||
|
||||
- `file` `<String>`
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const file = '/tmp/this/path/does/not/exist/file.txt'
|
||||
// Promise usage:
|
||||
fs.pathExists(file)
|
||||
.then(exists => console.log(exists)) // => false
|
||||
// Callback usage:
|
||||
fs.pathExists(file, (err, exists) => {
|
||||
console.log(err) // => null
|
||||
console.log(exists) // => false
|
||||
})
|
||||
```
|
33
node_modules/fs-extra/docs/readJson-sync.md
generated
vendored
Normal file
33
node_modules/fs-extra/docs/readJson-sync.md
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
# readJsonSync(file, [options])
|
||||
|
||||
Reads a JSON file and then parses it into an object. `options` are the same
|
||||
that you'd pass to [`jsonFile.readFileSync`](https://github.com/jprichardson/node-jsonfile#readfilesyncfilename-options).
|
||||
|
||||
**Alias:** `readJSONSync()`
|
||||
|
||||
- `file` `<String>`
|
||||
- `options` `<Object>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const packageObj = fs.readJsonSync('./package.json')
|
||||
console.log(packageObj.version) // => 2.0.0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
`readJsonSync()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const file = '/tmp/some-invalid.json'
|
||||
const data = '{not valid JSON'
|
||||
fs.writeFileSync(file, data)
|
||||
|
||||
const obj = fs.readJsonSync(file, { throws: false })
|
||||
console.log(obj) // => null
|
||||
```
|
58
node_modules/fs-extra/docs/readJson.md
generated
vendored
Normal file
58
node_modules/fs-extra/docs/readJson.md
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
# readJson(file, [options, callback])
|
||||
|
||||
Reads a JSON file and then parses it into an object. `options` are the same
|
||||
that you'd pass to [`jsonFile.readFile`](https://github.com/jprichardson/node-jsonfile#readfilefilename-options-callback).
|
||||
|
||||
**Alias:** `readJSON()`
|
||||
|
||||
- `file` `<String>`
|
||||
- `options` `<Object>`
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
fs.readJson('./package.json', (err, packageObj) => {
|
||||
if (err) console.error(err)
|
||||
|
||||
console.log(packageObj.version) // => 0.1.3
|
||||
})
|
||||
|
||||
// Promise Usage
|
||||
fs.readJson('./package.json')
|
||||
.then(packageObj => {
|
||||
console.log(packageObj.version) // => 0.1.3
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
`readJson()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const file = '/tmp/some-invalid.json'
|
||||
const data = '{not valid JSON'
|
||||
fs.writeFileSync(file, data)
|
||||
|
||||
fs.readJson(file, { throws: false }, (err, obj) => {
|
||||
if (err) console.error(err)
|
||||
|
||||
console.log(obj) // => null
|
||||
})
|
||||
|
||||
// Promise Usage
|
||||
fs.readJson(file, { throws: false })
|
||||
.then(obj => {
|
||||
console.log(obj) // => null
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err) // Not called
|
||||
})
|
||||
```
|
16
node_modules/fs-extra/docs/remove-sync.md
generated
vendored
Normal file
16
node_modules/fs-extra/docs/remove-sync.md
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
# removeSync(path)
|
||||
|
||||
Removes a file or directory. The directory can have contents. Like `rm -rf`.
|
||||
|
||||
- `path` `<String>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
// remove file
|
||||
fs.removeSync('/tmp/myfile')
|
||||
|
||||
fs.removeSync('/home/jprichardson') // I just deleted my entire HOME directory.
|
||||
```
|
34
node_modules/fs-extra/docs/remove.md
generated
vendored
Normal file
34
node_modules/fs-extra/docs/remove.md
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
# remove(path, [callback])
|
||||
|
||||
Removes a file or directory. The directory can have contents. Like `rm -rf`.
|
||||
|
||||
- `path` `<String>`
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
// remove file
|
||||
fs.remove('/tmp/myfile', err => {
|
||||
if (err) return console.error(err)
|
||||
|
||||
console.log('success!')
|
||||
})
|
||||
|
||||
fs.remove('/home/jprichardson', err => {
|
||||
if (err) return console.error(err)
|
||||
|
||||
console.log('success!') // I just deleted my entire HOME directory.
|
||||
})
|
||||
|
||||
// Promise Usage
|
||||
fs.remove('/tmp/myfile')
|
||||
.then(() => {
|
||||
console.log('success!')
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
21
node_modules/fs-extra/docs/writeJson-sync.md
generated
vendored
Normal file
21
node_modules/fs-extra/docs/writeJson-sync.md
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# writeJsonSync(file, object, [options])
|
||||
|
||||
Writes an object to a JSON file. `options` are the same that
|
||||
you'd pass to [`jsonFile.writeFileSync()`](https://github.com/jprichardson/node-jsonfile#writefilesyncfilename-obj-options).
|
||||
|
||||
**Alias:** `writeJSONSync()`
|
||||
|
||||
- `file` `<String>`
|
||||
- `object` `<Object>`
|
||||
- `options` `<Object>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
fs.writeJsonSync('./package.json', {name: 'fs-extra'})
|
||||
```
|
||||
---
|
||||
|
||||
**See also:** [`outputJsonSync()`](outputJson-sync.md)
|
36
node_modules/fs-extra/docs/writeJson.md
generated
vendored
Normal file
36
node_modules/fs-extra/docs/writeJson.md
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
# writeJson(file, object, [options, callback])
|
||||
|
||||
Writes an object to a JSON file. `options` are the same that
|
||||
you'd pass to [`jsonFile.writeFile()`](https://github.com/jprichardson/node-jsonfile#writefilefilename-options-callback).
|
||||
|
||||
**Alias:** `writeJSON()`
|
||||
|
||||
- `file` `<String>`
|
||||
- `object` `<Object>`
|
||||
- `options` `<Object>`
|
||||
- `callback` `<Function>`
|
||||
|
||||
## Example:
|
||||
|
||||
```js
|
||||
const fs = require('fs-extra')
|
||||
|
||||
fs.writeJson('./package.json', {name: 'fs-extra'}, err => {
|
||||
if (err) return console.error(err)
|
||||
|
||||
console.log('success!')
|
||||
})
|
||||
|
||||
// With Promises
|
||||
fs.writeJson('./package.json', {name: 'fs-extra'})
|
||||
.then(() => {
|
||||
console.log('success!')
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**See also:** [`outputJson()`](outputJson.md)
|
Reference in New Issue
Block a user