diff options
author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2019-10-06 21:37:45 +0200 |
---|---|---|
committer | Dimitri Staessens <dimitri@ouroboros.rocks> | 2019-10-06 21:37:45 +0200 |
commit | 3c51c3be85bb0d1bdb87ea0d6632f1c256912f27 (patch) | |
tree | c7ccc8279b12c4f7bdbbb4270d617e48f51722e4 /node_modules/fs-extra/docs | |
parent | 412c104bebc507bea9c94fd53b5bdc4b64cbfe31 (diff) | |
download | website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.tar.gz website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.zip |
build: Add some required modules for node
Diffstat (limited to 'node_modules/fs-extra/docs')
27 files changed, 777 insertions, 0 deletions
diff --git a/node_modules/fs-extra/docs/copy-sync.md b/node_modules/fs-extra/docs/copy-sync.md new file mode 100644 index 0000000..0a33e47 --- /dev/null +++ b/node_modules/fs-extra/docs/copy-sync.md @@ -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. + +## 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 }) +``` diff --git a/node_modules/fs-extra/docs/copy.md b/node_modules/fs-extra/docs/copy.md new file mode 100644 index 0000000..f7909d0 --- /dev/null +++ b/node_modules/fs-extra/docs/copy.md @@ -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>` Note that if `src` is a file, `dest` cannot be a directory (see [issue #323](https://github.com/jprichardson/node-fs-extra/issues/323)). +- `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. Can also return a `Promise` that resolves to `true` or `false` (or pass in an `async` function). +- `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!') +}) +``` diff --git a/node_modules/fs-extra/docs/emptyDir-sync.md b/node_modules/fs-extra/docs/emptyDir-sync.md new file mode 100644 index 0000000..7decdbc --- /dev/null +++ b/node_modules/fs-extra/docs/emptyDir-sync.md @@ -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') +``` diff --git a/node_modules/fs-extra/docs/emptyDir.md b/node_modules/fs-extra/docs/emptyDir.md new file mode 100644 index 0000000..6553e9a --- /dev/null +++ b/node_modules/fs-extra/docs/emptyDir.md @@ -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) +}) +``` diff --git a/node_modules/fs-extra/docs/ensureDir-sync.md b/node_modules/fs-extra/docs/ensureDir-sync.md new file mode 100644 index 0000000..8f083d2 --- /dev/null +++ b/node_modules/fs-extra/docs/ensureDir-sync.md @@ -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 +``` diff --git a/node_modules/fs-extra/docs/ensureDir.md b/node_modules/fs-extra/docs/ensureDir.md new file mode 100644 index 0000000..d030d86 --- /dev/null +++ b/node_modules/fs-extra/docs/ensureDir.md @@ -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) +}) +``` diff --git a/node_modules/fs-extra/docs/ensureFile-sync.md b/node_modules/fs-extra/docs/ensureFile-sync.md new file mode 100644 index 0000000..25ac39d --- /dev/null +++ b/node_modules/fs-extra/docs/ensureFile-sync.md @@ -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 +``` diff --git a/node_modules/fs-extra/docs/ensureFile.md b/node_modules/fs-extra/docs/ensureFile.md new file mode 100644 index 0000000..987be63 --- /dev/null +++ b/node_modules/fs-extra/docs/ensureFile.md @@ -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) +}) +``` diff --git a/node_modules/fs-extra/docs/ensureLink-sync.md b/node_modules/fs-extra/docs/ensureLink-sync.md new file mode 100644 index 0000000..74769d3 --- /dev/null +++ b/node_modules/fs-extra/docs/ensureLink-sync.md @@ -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 +``` diff --git a/node_modules/fs-extra/docs/ensureLink.md b/node_modules/fs-extra/docs/ensureLink.md new file mode 100644 index 0000000..90d2a5d --- /dev/null +++ b/node_modules/fs-extra/docs/ensureLink.md @@ -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) +}) +``` diff --git a/node_modules/fs-extra/docs/ensureSymlink-sync.md b/node_modules/fs-extra/docs/ensureSymlink-sync.md new file mode 100644 index 0000000..328d4c4 --- /dev/null +++ b/node_modules/fs-extra/docs/ensureSymlink-sync.md @@ -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 +``` diff --git a/node_modules/fs-extra/docs/ensureSymlink.md b/node_modules/fs-extra/docs/ensureSymlink.md new file mode 100644 index 0000000..45524f1 --- /dev/null +++ b/node_modules/fs-extra/docs/ensureSymlink.md @@ -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) +}) +``` diff --git a/node_modules/fs-extra/docs/fs-read-write.md b/node_modules/fs-extra/docs/fs-read-write.md new file mode 100644 index 0000000..805ea3c --- /dev/null +++ b/node_modules/fs-extra/docs/fs-read-write.md @@ -0,0 +1,39 @@ +# About `fs.read()` & `fs.write()` + +[`fs.read()`](https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback) & [`fs.write()`](https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback) are different from other `fs` methods in that their callbacks are called with 3 arguments instead of the usual 2 arguments. + +If you're using them with callbacks, they will behave as usual. However, their promise usage is a little different. `fs-extra` promisifies these methods like [`util.promisify()`](https://nodejs.org/api/util.html#util_util_promisify_original) (only available in Node 8+) does. + +Here's the example promise usage: + +## `fs.read()` + +```js +// Basic promises +fs.read(fd, buffer, offset, length, position) + .then(results => { + console.log(results) + // { bytesRead: 20, buffer: <Buffer 0f 34 5d ...> } + }) + +// Async/await usage: +async function example () { + const { bytesRead, buffer } = await fs.read(fd, Buffer.alloc(length), offset, length, position) +} +``` + +## `fs.write()` + +```js +// Basic promises +fs.write(fd, buffer, offset, length, position) + .then(results => { + console.log(results) + // { bytesWritten: 20, buffer: <Buffer 0f 34 5d ...> } + }) + +// Async/await usage: +async function example () { + const { bytesWritten, buffer } = await fs.write(fd, Buffer.alloc(length), offset, length, position) +} +``` diff --git a/node_modules/fs-extra/docs/move-sync.md b/node_modules/fs-extra/docs/move-sync.md new file mode 100644 index 0000000..cd701fe --- /dev/null +++ b/node_modules/fs-extra/docs/move-sync.md @@ -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 }) +``` diff --git a/node_modules/fs-extra/docs/move.md b/node_modules/fs-extra/docs/move.md new file mode 100644 index 0000000..0dd210c --- /dev/null +++ b/node_modules/fs-extra/docs/move.md @@ -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!') +}) +``` diff --git a/node_modules/fs-extra/docs/outputFile-sync.md b/node_modules/fs-extra/docs/outputFile-sync.md new file mode 100644 index 0000000..38eee8b --- /dev/null +++ b/node_modules/fs-extra/docs/outputFile-sync.md @@ -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! +``` diff --git a/node_modules/fs-extra/docs/outputFile.md b/node_modules/fs-extra/docs/outputFile.md new file mode 100644 index 0000000..766787d --- /dev/null +++ b/node_modules/fs-extra/docs/outputFile.md @@ -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) +}) +``` diff --git a/node_modules/fs-extra/docs/outputJson-sync.md b/node_modules/fs-extra/docs/outputJson-sync.md new file mode 100644 index 0000000..ef78f80 --- /dev/null +++ b/node_modules/fs-extra/docs/outputJson-sync.md @@ -0,0 +1,25 @@ +# outputJsonSync(file, object, [options]) + +Almost the same as [`writeJsonSync`](writeJson-sync.md), except that if the directory does not exist, it's created. + +**Alias:** `outputJSONSync()` + +- `file` `<String>` +- `object` `<Object>` +- `options` `<Object>` + - `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. + - `EOL` `<String>` Set EOL character. Default is `\n`. + - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) + - Also accepts [`fs.writeFileSync` options](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options) + +## 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 +``` diff --git a/node_modules/fs-extra/docs/outputJson.md b/node_modules/fs-extra/docs/outputJson.md new file mode 100644 index 0000000..7156991 --- /dev/null +++ b/node_modules/fs-extra/docs/outputJson.md @@ -0,0 +1,40 @@ +# outputJson(file, object, [options, callback]) + +Almost the same as [`writeJson`](writeJson.md), except that if the directory does not exist, it's created. + +**Alias:** `outputJSON()` + +- `file` `<String>` +- `object` `<Object>` +- `options` `<Object>` + - `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. + - `EOL` `<String>` Set EOL character. Default is `\n`. + - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) + - Also accepts [`fs.writeFile` options](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback) +- `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) +}) +``` diff --git a/node_modules/fs-extra/docs/pathExists-sync.md b/node_modules/fs-extra/docs/pathExists-sync.md new file mode 100644 index 0000000..3ef973c --- /dev/null +++ b/node_modules/fs-extra/docs/pathExists-sync.md @@ -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). diff --git a/node_modules/fs-extra/docs/pathExists.md b/node_modules/fs-extra/docs/pathExists.md new file mode 100644 index 0000000..0302b09 --- /dev/null +++ b/node_modules/fs-extra/docs/pathExists.md @@ -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 +}) +``` diff --git a/node_modules/fs-extra/docs/readJson-sync.md b/node_modules/fs-extra/docs/readJson-sync.md new file mode 100644 index 0000000..a135637 --- /dev/null +++ b/node_modules/fs-extra/docs/readJson-sync.md @@ -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 +``` diff --git a/node_modules/fs-extra/docs/readJson.md b/node_modules/fs-extra/docs/readJson.md new file mode 100644 index 0000000..6edc329 --- /dev/null +++ b/node_modules/fs-extra/docs/readJson.md @@ -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 +}) +``` diff --git a/node_modules/fs-extra/docs/remove-sync.md b/node_modules/fs-extra/docs/remove-sync.md new file mode 100644 index 0000000..fb01fe8 --- /dev/null +++ b/node_modules/fs-extra/docs/remove-sync.md @@ -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. +``` diff --git a/node_modules/fs-extra/docs/remove.md b/node_modules/fs-extra/docs/remove.md new file mode 100644 index 0000000..3640293 --- /dev/null +++ b/node_modules/fs-extra/docs/remove.md @@ -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) +}) +``` diff --git a/node_modules/fs-extra/docs/writeJson-sync.md b/node_modules/fs-extra/docs/writeJson-sync.md new file mode 100644 index 0000000..c22459d --- /dev/null +++ b/node_modules/fs-extra/docs/writeJson-sync.md @@ -0,0 +1,24 @@ +# writeJsonSync(file, object, [options]) + +Writes an object to a JSON file. + +**Alias:** `writeJSONSync()` + +- `file` `<String>` +- `object` `<Object>` +- `options` `<Object>` + - `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. + - `EOL` `<String>` Set EOL character. Default is `\n`. + - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) + - Also accepts [`fs.writeFileSync` options](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options) + +## Example: + +```js +const fs = require('fs-extra') + +fs.writeJsonSync('./package.json', {name: 'fs-extra'}) +``` +--- + +**See also:** [`outputJsonSync()`](outputJson-sync.md) diff --git a/node_modules/fs-extra/docs/writeJson.md b/node_modules/fs-extra/docs/writeJson.md new file mode 100644 index 0000000..8e35271 --- /dev/null +++ b/node_modules/fs-extra/docs/writeJson.md @@ -0,0 +1,39 @@ +# writeJson(file, object, [options, callback]) + +Writes an object to a JSON file. + +**Alias:** `writeJSON()` + +- `file` `<String>` +- `object` `<Object>` +- `options` `<Object>` + - `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. + - `EOL` `<String>` Set EOL character. Default is `\n`. + - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) + - Also accepts [`fs.writeFile` options](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback) +- `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) |