From 2cc1aebc12dd300f91eaa2edf8cb23298cdeee43 Mon Sep 17 00:00:00 2001 From: Mani Maghsoudlou Date: Sat, 4 Aug 2018 14:08:03 -0700 Subject: [PATCH 1/4] moveSync: refactor to use renameSync --- ...ve-sync-prevent-moving-into-itself.test.js | 2 +- lib/move-sync/__tests__/move-sync.test.js | 94 +++----------- lib/move-sync/index.js | 120 +++++------------- package.json | 1 - 4 files changed, 50 insertions(+), 167 deletions(-) diff --git a/lib/move-sync/__tests__/move-sync-prevent-moving-into-itself.test.js b/lib/move-sync/__tests__/move-sync-prevent-moving-into-itself.test.js index 3685faaf..1bf32c05 100644 --- a/lib/move-sync/__tests__/move-sync-prevent-moving-into-itself.test.js +++ b/lib/move-sync/__tests__/move-sync-prevent-moving-into-itself.test.js @@ -182,7 +182,7 @@ function testError (src, dest) { try { fs.moveSync(src, dest) } catch (err) { - assert.strictEqual(err.message, `Cannot move '${src}' into itself '${dest}'.`) + assert.strictEqual(err.message, `Cannot move '${src}' to a subdirectory of itself, '${dest}'.`) assert(fs.existsSync(src)) assert(!fs.existsSync(dest)) } diff --git a/lib/move-sync/__tests__/move-sync.test.js b/lib/move-sync/__tests__/move-sync.test.js index d2c226b3..2139b8ce 100644 --- a/lib/move-sync/__tests__/move-sync.test.js +++ b/lib/move-sync/__tests__/move-sync.test.js @@ -5,7 +5,6 @@ const os = require('os') const fse = require(process.cwd()) const path = require('path') const assert = require('assert') -const rimraf = require('rimraf') /* global afterEach, beforeEach, describe, it */ @@ -19,16 +18,13 @@ function createSyncErrFn (errCode) { } const originalRenameSync = fs.renameSync -const originalLinkSync = fs.linkSync function setUpMockFs (errCode) { fs.renameSync = createSyncErrFn(errCode) - fs.linkSync = createSyncErrFn(errCode) } function tearDownMockFs () { fs.renameSync = originalRenameSync - fs.linkSync = originalLinkSync } describe('moveSync()', () => { @@ -36,18 +32,15 @@ describe('moveSync()', () => { beforeEach(() => { TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move-sync') - fse.emptyDirSync(TEST_DIR) - // Create fixtures: - fs.writeFileSync(path.join(TEST_DIR, 'a-file'), 'sonic the hedgehog\n') - fs.mkdirSync(path.join(TEST_DIR, 'a-folder')) - fs.writeFileSync(path.join(TEST_DIR, 'a-folder/another-file'), 'tails\n') - fs.mkdirSync(path.join(TEST_DIR, 'a-folder/another-folder')) - fs.writeFileSync(path.join(TEST_DIR, 'a-folder/another-folder/file3'), 'knuckles\n') + // Create fixtures + fse.outputFileSync(path.join(TEST_DIR, 'a-file'), 'sonic the hedgehog\n') + fse.outputFileSync(path.join(TEST_DIR, 'a-folder/another-file'), 'tails\n') + fse.outputFileSync(path.join(TEST_DIR, 'a-folder/another-folder/file3'), 'knuckles\n') }) - afterEach(done => rimraf(TEST_DIR, done)) + afterEach(() => fse.removeSync(TEST_DIR)) it('should not move if src and dest are the same', () => { const src = `${TEST_DIR}/a-file` @@ -58,13 +51,12 @@ describe('moveSync()', () => { // assert src not affected const contents = fs.readFileSync(src, 'utf8') const expected = /^sonic the hedgehog\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) + assert(contents.match(expected)) }) it('should error if src and dest are the same and src does not exist', () => { const src = `${TEST_DIR}/non-existent` const dest = src - assert.throws(() => fse.moveSync(src, dest)) }) @@ -76,7 +68,7 @@ describe('moveSync()', () => { const contents = fs.readFileSync(dest, 'utf8') const expected = /^sonic the hedgehog\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) + assert(contents.match(expected)) }) it('should not overwrite the destination by default', () => { @@ -89,7 +81,7 @@ describe('moveSync()', () => { try { fse.moveSync(src, dest) } catch (err) { - assert.ok(err && err.code === 'EEXIST', 'throw EEXIST') + assert.strictEqual(err.message, 'dest already exists.') } }) @@ -103,7 +95,7 @@ describe('moveSync()', () => { try { fse.moveSync(src, dest, {overwrite: false}) } catch (err) { - assert.ok(err && err.code === 'EEXIST', 'throw EEXIST') + assert.strictEqual(err.message, 'dest already exists.') } }) @@ -121,7 +113,7 @@ describe('moveSync()', () => { assert.ok(contents.match(expected), `${contents} match ${expected}`) }) - it('should overwrite the destination directory if overwrite = true', done => { + it('should overwrite the destination directory if overwrite = true', () => { // Create src const src = path.join(TEST_DIR, 'src') fse.ensureDirSync(src) @@ -145,7 +137,6 @@ describe('moveSync()', () => { // verify dest has new stuff assert(pathsAfter.indexOf('some-file') >= 0) assert(pathsAfter.indexOf('some-folder') >= 0) - done() }) it('should create directory structure by default', () => { @@ -159,7 +150,7 @@ describe('moveSync()', () => { const contents = fs.readFileSync(dest, 'utf8') const expected = /^sonic the hedgehog\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) + assert(contents.match(expected)) }) it('should work across devices', () => { @@ -172,7 +163,7 @@ describe('moveSync()', () => { const contents = fs.readFileSync(dest, 'utf8') const expected = /^sonic the hedgehog\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) + assert(contents.match(expected)) tearDownMockFs() }) @@ -187,27 +178,12 @@ describe('moveSync()', () => { const contents = fs.readFileSync(dest + '/another-file', 'utf8') const expected = /^tails\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) - }) - - it('should move folders across devices with EISDIR error', () => { - const src = `${TEST_DIR}/a-folder` - const dest = `${TEST_DIR}/a-folder-dest` - - setUpMockFs('EISDIR') - - fse.moveSync(src, dest) - - const contents = fs.readFileSync(dest + '/another-folder/file3', 'utf8') - const expected = /^knuckles\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) - tearDownMockFs() + assert(contents.match(expected)) }) it('should overwrite folders across devices', () => { const src = `${TEST_DIR}/a-folder` const dest = `${TEST_DIR}/a-folder-dest` - fs.mkdirSync(dest) setUpMockFs('EXDEV') @@ -216,7 +192,7 @@ describe('moveSync()', () => { const contents = fs.readFileSync(dest + '/another-folder/file3', 'utf8') const expected = /^knuckles\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) + assert(contents.match(expected)) tearDownMockFs() }) @@ -230,35 +206,7 @@ describe('moveSync()', () => { const contents = fs.readFileSync(dest + '/another-folder/file3', 'utf8') const expected = /^knuckles\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) - tearDownMockFs() - }) - - it('should move folders across devices with EPERM error', () => { - const src = `${TEST_DIR}/a-folder` - const dest = `${TEST_DIR}/a-folder-dest` - - setUpMockFs('EPERM') - - fse.moveSync(src, dest) - - const contents = fs.readFileSync(dest + '/another-folder/file3', 'utf8') - const expected = /^knuckles\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) - tearDownMockFs() - }) - - it('should move folders across devices with ENOTSUP error', () => { - const src = `${TEST_DIR}/a-folder` - const dest = `${TEST_DIR}/a-folder-dest` - - setUpMockFs('ENOTSUP') - - fse.moveSync(src, dest) - - const contents = fs.readFileSync(dest + '/another-folder/file3', 'utf8') - const expected = /^knuckles\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) + assert(contents.match(expected)) tearDownMockFs() }) @@ -274,7 +222,7 @@ describe('moveSync()', () => { const contents = fs.readFileSync(dest, 'utf8') const expected = /^sonic the hedgehog\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) + assert(contents.match(expected)) }) }) @@ -306,7 +254,7 @@ describe('moveSync()', () => { const contents = fs.readFileSync(dest, 'utf8') const expected = /^sonic the hedgehog\r?\n$/ - assert.ok(contents.match(expected), `${contents} match ${expected}`) + assert(contents.match(expected)) }) }) @@ -324,7 +272,7 @@ describe('moveSync()', () => { try { fs.writeFileSync(path.join(differentDevice, 'file'), 'hi') } catch (err) { - console.log("Can't write to device. Skipping moveSync test.") + console.log(`Can't write to device. Skipping moveSync test.`) __skipTests = true } @@ -335,12 +283,8 @@ describe('moveSync()', () => { const src = '/mnt/some/weird/dir-really-weird' const dest = path.join(TEST_DIR, 'device-weird') - if (!fs.existsSync(src)) { - fse.mkdirpSync(src) - } - + if (!fs.existsSync(src)) fse.mkdirpSync(src) assert(!fs.existsSync(dest)) - assert(fs.lstatSync(src).isDirectory()) fse.moveSync(src, dest) diff --git a/lib/move-sync/index.js b/lib/move-sync/index.js index 6d4f56fa..b2dbc941 100644 --- a/lib/move-sync/index.js +++ b/lib/move-sync/index.js @@ -4,114 +4,54 @@ const fs = require('graceful-fs') const path = require('path') const copySync = require('../copy-sync').copySync const removeSync = require('../remove').removeSync -const mkdirpSync = require('../mkdirs').mkdirsSync -const buffer = require('../util/buffer') - -function moveSync (src, dest, options) { - options = options || {} - const overwrite = options.overwrite || options.clobber || false +const mkdirpSync = require('../mkdirs').mkdirpSync +const pathExistsSync = require('../path-exists').pathExistsSync +function moveSync (src, dest, opts) { + opts = opts || {} + const overwrite = opts.overwrite || opts.clobber || false src = path.resolve(src) dest = path.resolve(dest) - if (src === dest) return fs.accessSync(src) - if (isSrcSubdir(src, dest)) throw new Error(`Cannot move '${src}' into itself '${dest}'.`) - + const st = fs.statSync(src) + if (st.isDirectory() && isSrcSubdir(src, dest)) throw new Error(`Cannot move '${src}' to a subdirectory of itself, '${dest}'.`) mkdirpSync(path.dirname(dest)) - tryRenameSync() - - function tryRenameSync () { - if (overwrite) { - try { - return fs.renameSync(src, dest) - } catch (err) { - if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST' || err.code === 'EPERM') { - removeSync(dest) - options.overwrite = false // just overwriteed it, no need to do it again - return moveSync(src, dest, options) - } - - if (err.code !== 'EXDEV') throw err - return moveSyncAcrossDevice(src, dest, overwrite) - } - } else { - try { - fs.linkSync(src, dest) - return fs.unlinkSync(src) - } catch (err) { - if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM' || err.code === 'ENOTSUP') { - return moveSyncAcrossDevice(src, dest, overwrite) - } - throw err - } - } - } + return doRename(src, dest, overwrite) } -function moveSyncAcrossDevice (src, dest, overwrite) { - const stat = fs.statSync(src) - - if (stat.isDirectory()) { - return moveDirSyncAcrossDevice(src, dest, overwrite) - } else { - return moveFileSyncAcrossDevice(src, dest, overwrite) +function doRename (src, dest, overwrite) { + if (overwrite) { + removeSync(dest) + return rename(src, dest, overwrite) } + if (pathExistsSync(dest)) throw new Error('dest already exists.') + return rename(src, dest, overwrite) } -function moveFileSyncAcrossDevice (src, dest, overwrite) { - const BUF_LENGTH = 64 * 1024 - const _buff = buffer(BUF_LENGTH) - - const flags = overwrite ? 'w' : 'wx' - - const fdr = fs.openSync(src, 'r') - const stat = fs.fstatSync(fdr) - const fdw = fs.openSync(dest, flags, stat.mode) - let pos = 0 - - while (pos < stat.size) { - const bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos) - fs.writeSync(fdw, _buff, 0, bytesRead) - pos += bytesRead +function rename (src, dest, overwrite) { + try { + fs.renameSync(src, dest) + } catch (err) { + if (err.code !== 'EXDEV') throw err + return moveAcrossDevice(src, dest, overwrite) } - - fs.closeSync(fdr) - fs.closeSync(fdw) - return fs.unlinkSync(src) } -function moveDirSyncAcrossDevice (src, dest, overwrite) { - const options = { - overwrite: false +function moveAcrossDevice (src, dest, overwrite) { + const opts = { + overwrite, + errorOnExist: true } - if (overwrite) { - removeSync(dest) - tryCopySync() - } else { - tryCopySync() - } - - function tryCopySync () { - copySync(src, dest, options) - return removeSync(src) - } + copySync(src, dest, opts) + return removeSync(src) } -// return true if dest is a subdir of src, otherwise false. -// extract dest base dir and check if that is the same as src basename function isSrcSubdir (src, dest) { - try { - return fs.statSync(src).isDirectory() && - src !== dest && - dest.indexOf(src) > -1 && - dest.split(path.dirname(src) + path.sep)[1].split(path.sep)[0] === path.basename(src) - } catch (e) { - return false - } + const srcArr = src.split(path.sep) + const destArr = dest.split(path.sep) + return srcArr.reduce((acc, curr, i) => acc && destArr[i] === curr, true) } -module.exports = { - moveSync -} +module.exports = { moveSync } diff --git a/package.json b/package.json index 3d4db47a..9c4f33fb 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,6 @@ "mocha": "^5.0.5", "proxyquire": "^2.0.1", "read-dir-files": "^0.1.1", - "rimraf": "^2.2.8", "secure-random": "^1.1.1", "semver": "^5.3.0", "standard": "^11.0.1", From 172538ae7e8fac0fb2113a9ffa3b5dcca0668b67 Mon Sep 17 00:00:00 2001 From: Mani Maghsoudlou Date: Sun, 5 Aug 2018 00:50:31 -0700 Subject: [PATCH 2/4] use fs.existsSync() --- lib/move-sync/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/move-sync/index.js b/lib/move-sync/index.js index b2dbc941..8bfdbc14 100644 --- a/lib/move-sync/index.js +++ b/lib/move-sync/index.js @@ -5,7 +5,6 @@ const path = require('path') const copySync = require('../copy-sync').copySync const removeSync = require('../remove').removeSync const mkdirpSync = require('../mkdirs').mkdirpSync -const pathExistsSync = require('../path-exists').pathExistsSync function moveSync (src, dest, opts) { opts = opts || {} @@ -25,7 +24,7 @@ function doRename (src, dest, overwrite) { removeSync(dest) return rename(src, dest, overwrite) } - if (pathExistsSync(dest)) throw new Error('dest already exists.') + if (fs.existsSync(dest)) throw new Error('dest already exists.') return rename(src, dest, overwrite) } From 1977480dbfd7c0cb3515d6d25e2ff95f14575e62 Mon Sep 17 00:00:00 2001 From: Mani Maghsoudlou Date: Mon, 6 Aug 2018 05:28:14 -0700 Subject: [PATCH 3/4] Remove secure-random from dev-deps (#610) --- lib/remove/__tests__/remove.test.js | 4 ++-- package.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/remove/__tests__/remove.test.js b/lib/remove/__tests__/remove.test.js index 92979d57..5add5997 100644 --- a/lib/remove/__tests__/remove.test.js +++ b/lib/remove/__tests__/remove.test.js @@ -4,7 +4,7 @@ const assert = require('assert') const fs = require('fs') const os = require('os') const path = require('path') -const sr = require('secure-random') +const randomBytes = require('crypto').randomBytes const fse = require(process.cwd()) /* global afterEach, beforeEach, describe, it */ @@ -12,7 +12,7 @@ const fse = require(process.cwd()) let TEST_DIR function buildFixtureDir () { - const buf = sr.randomBuffer(5) + const buf = randomBytes(5) const baseDir = path.join(TEST_DIR, `TEST_fs-extra_remove-${Date.now()}`) fs.mkdirSync(baseDir) diff --git a/package.json b/package.json index 3d4db47a..602ce65d 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,6 @@ "proxyquire": "^2.0.1", "read-dir-files": "^0.1.1", "rimraf": "^2.2.8", - "secure-random": "^1.1.1", "semver": "^5.3.0", "standard": "^11.0.1", "standard-markdown": "^4.0.1" From fe516c3d33a4f37a594e897b5d85d729ef23d0ef Mon Sep 17 00:00:00 2001 From: Mani Maghsoudlou Date: Tue, 7 Aug 2018 04:01:51 -0700 Subject: [PATCH 4/4] docs: refactor to be consistent with node docs (#611) --- docs/copy-sync.md | 2 +- docs/copy.md | 2 +- docs/emptyDir.md | 2 +- docs/ensureDir.md | 2 +- docs/ensureFile.md | 2 +- docs/ensureLink.md | 2 +- docs/ensureSymlink-sync.md | 2 +- docs/ensureSymlink.md | 2 +- docs/move-sync.md | 2 +- docs/move.md | 2 +- docs/outputFile-sync.md | 2 +- docs/outputFile.md | 2 +- docs/outputJson-sync.md | 2 +- docs/outputJson.md | 2 +- docs/readJson-sync.md | 2 +- docs/readJson.md | 2 +- docs/remove.md | 2 +- docs/writeJson-sync.md | 2 +- docs/writeJson.md | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/copy-sync.md b/docs/copy-sync.md index 76bfd477..3fca1330 100644 --- a/docs/copy-sync.md +++ b/docs/copy-sync.md @@ -1,4 +1,4 @@ -# copySync(src, dest, [options]) +# copySync(src, dest[, options]) Copy a file or directory. The directory can have contents. Like `cp -r`. diff --git a/docs/copy.md b/docs/copy.md index e5f8582b..4add5684 100644 --- a/docs/copy.md +++ b/docs/copy.md @@ -1,4 +1,4 @@ -# copy(src, dest, [options, callback]) +# copy(src, dest[, options][, callback]) Copy a file or directory. The directory can have contents. Like `cp -r`. diff --git a/docs/emptyDir.md b/docs/emptyDir.md index 3d129d42..8f26dc10 100644 --- a/docs/emptyDir.md +++ b/docs/emptyDir.md @@ -1,4 +1,4 @@ -# emptyDir(dir, [callback]) +# 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. diff --git a/docs/ensureDir.md b/docs/ensureDir.md index 0d43a145..54fe069d 100644 --- a/docs/ensureDir.md +++ b/docs/ensureDir.md @@ -1,4 +1,4 @@ -# ensureDir(dir, [callback]) +# ensureDir(dir[, callback]) Ensures that the directory exists. If the directory structure does not exist, it is created. Like `mkdir -p`. diff --git a/docs/ensureFile.md b/docs/ensureFile.md index aa8e82ac..a560e966 100644 --- a/docs/ensureFile.md +++ b/docs/ensureFile.md @@ -1,4 +1,4 @@ -# ensureFile(file, [callback]) +# 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**. diff --git a/docs/ensureLink.md b/docs/ensureLink.md index 3f39f07b..7bdddebf 100644 --- a/docs/ensureLink.md +++ b/docs/ensureLink.md @@ -1,4 +1,4 @@ -# ensureLink(srcpath, dstpath, [callback]) +# ensureLink(srcpath, dstpath[, callback]) Ensures that the link exists. If the directory structure does not exist, it is created. diff --git a/docs/ensureSymlink-sync.md b/docs/ensureSymlink-sync.md index 328d4c45..72b39c29 100644 --- a/docs/ensureSymlink-sync.md +++ b/docs/ensureSymlink-sync.md @@ -1,4 +1,4 @@ -# ensureSymlinkSync(srcpath, dstpath, [type]) +# ensureSymlinkSync(srcpath, dstpath[, type]) Ensures that the symlink exists. If the directory structure does not exist, it is created. diff --git a/docs/ensureSymlink.md b/docs/ensureSymlink.md index 39c09568..383c49f0 100644 --- a/docs/ensureSymlink.md +++ b/docs/ensureSymlink.md @@ -1,4 +1,4 @@ -# ensureSymlink(srcpath, dstpath, [type, callback]) +# ensureSymlink(srcpath, dstpath[, type][, callback]) Ensures that the symlink exists. If the directory structure does not exist, it is created. diff --git a/docs/move-sync.md b/docs/move-sync.md index cd701fef..d5153b58 100644 --- a/docs/move-sync.md +++ b/docs/move-sync.md @@ -1,4 +1,4 @@ -# moveSync(src, dest, [options]) +# moveSync(src, dest[, options]) Moves a file or directory, even across devices. diff --git a/docs/move.md b/docs/move.md index 343d10be..5f70853e 100644 --- a/docs/move.md +++ b/docs/move.md @@ -1,4 +1,4 @@ -# move(src, dest, [options, callback]) +# move(src, dest[, options][, callback]) Moves a file or directory, even across devices. diff --git a/docs/outputFile-sync.md b/docs/outputFile-sync.md index 38eee8b6..fc7abdf9 100644 --- a/docs/outputFile-sync.md +++ b/docs/outputFile-sync.md @@ -1,4 +1,4 @@ -# outputFileSync(file, data, [options]) +# 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). diff --git a/docs/outputFile.md b/docs/outputFile.md index 34efdc94..ed9c19d6 100644 --- a/docs/outputFile.md +++ b/docs/outputFile.md @@ -1,4 +1,4 @@ -# outputFile(file, data, [options, callback]) +# 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). diff --git a/docs/outputJson-sync.md b/docs/outputJson-sync.md index ef78f802..c42497cf 100644 --- a/docs/outputJson-sync.md +++ b/docs/outputJson-sync.md @@ -1,4 +1,4 @@ -# outputJsonSync(file, object, [options]) +# outputJsonSync(file, object[, options]) Almost the same as [`writeJsonSync`](writeJson-sync.md), except that if the directory does not exist, it's created. diff --git a/docs/outputJson.md b/docs/outputJson.md index aa265aee..d5a6d7c7 100644 --- a/docs/outputJson.md +++ b/docs/outputJson.md @@ -1,4 +1,4 @@ -# outputJson(file, object, [options, callback]) +# outputJson(file, object[, options][, callback]) Almost the same as [`writeJson`](writeJson.md), except that if the directory does not exist, it's created. diff --git a/docs/readJson-sync.md b/docs/readJson-sync.md index a1356379..1fc6519d 100644 --- a/docs/readJson-sync.md +++ b/docs/readJson-sync.md @@ -1,4 +1,4 @@ -# readJsonSync(file, [options]) +# 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). diff --git a/docs/readJson.md b/docs/readJson.md index baf80ac8..881e7972 100644 --- a/docs/readJson.md +++ b/docs/readJson.md @@ -1,4 +1,4 @@ -# readJson(file, [options, callback]) +# 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). diff --git a/docs/remove.md b/docs/remove.md index bcc49e39..0cdcf7ac 100644 --- a/docs/remove.md +++ b/docs/remove.md @@ -1,4 +1,4 @@ -# remove(path, [callback]) +# remove(path[, callback]) Removes a file or directory. The directory can have contents. Like `rm -rf`. diff --git a/docs/writeJson-sync.md b/docs/writeJson-sync.md index c22459db..b98e0c7d 100644 --- a/docs/writeJson-sync.md +++ b/docs/writeJson-sync.md @@ -1,4 +1,4 @@ -# writeJsonSync(file, object, [options]) +# writeJsonSync(file, object[, options]) Writes an object to a JSON file. diff --git a/docs/writeJson.md b/docs/writeJson.md index 56278029..216d1348 100644 --- a/docs/writeJson.md +++ b/docs/writeJson.md @@ -1,4 +1,4 @@ -# writeJson(file, object, [options, callback]) +# writeJson(file, object[, options][, callback]) Writes an object to a JSON file.