Browse Source

Upgrade to jsonfile 4.0.0 for EOL option support

ci/travis-osximage
RyanZim 7 years ago
committed by Ryan Zimmerman
parent
commit
7a9bb173b9
  1. 1
      docs/outputJson-sync.md
  2. 1
      docs/outputJson.md
  3. 1
      docs/writeJson-sync.md
  4. 1
      docs/writeJson.md
  5. 4
      lib/__tests__/promise.test.js
  6. 17
      lib/json/__tests__/jsonfile-integration.test.js
  7. 38
      lib/json/__tests__/promise-support.test.js
  8. 2
      package.json

1
docs/outputJson-sync.md

@ -8,6 +8,7 @@ Almost the same as [`writeJsonSync`](writeJson-sync.md), except that if the dire
- `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)

1
docs/outputJson.md

@ -8,6 +8,7 @@ Almost the same as [`writeJson`](writeJson.md), except that if the directory doe
- `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>`

1
docs/writeJson-sync.md

@ -8,6 +8,7 @@ Writes an object to a JSON file.
- `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)

1
docs/writeJson.md

@ -8,6 +8,7 @@ Writes an object to a JSON file.
- `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>`

4
lib/__tests__/promise.test.js

@ -13,9 +13,7 @@ const methods = [
'move',
'readJson',
'readJSON',
'remove',
'writeJson',
'writeJSON'
'remove'
]
describe('promise support', () => {

17
lib/json/__tests__/jsonfile-integration.test.js

@ -31,4 +31,21 @@ describe('jsonfile-integration', () => {
assert.strictEqual(data, JSON.stringify(obj1) + '\n')
})
})
describe('+ writeJsonSync / EOL', () => {
it('should read a file and parse the json', () => {
const obj1 = {
firstName: 'JP',
lastName: 'Richardson'
}
const file = path.join(TEST_DIR, 'file.json')
fse.writeJsonSync(file, obj1, { spaces: 2, EOL: '\r\n' })
const data = fs.readFileSync(file, 'utf8')
assert.strictEqual(
data,
JSON.stringify(obj1, null, 2).replace(/\n/g, '\r\n') + '\r\n'
)
})
})
})

38
lib/json/__tests__/promise-support.test.js

@ -0,0 +1,38 @@
'use strict'
const fs = require('fs')
const os = require('os')
const fse = require(process.cwd())
const path = require('path')
const assert = require('assert')
/* global afterEach, beforeEach, describe, it */
describe('json promise support', () => {
let TEST_DIR
beforeEach(done => {
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'json')
fse.emptyDir(TEST_DIR, done)
})
afterEach(done => fse.remove(TEST_DIR, done))
;['writeJson', 'writeJSON'].forEach(method => {
describe(method, () => {
it('should support promises', () => {
const obj1 = {
firstName: 'JP',
lastName: 'Richardson'
}
const file = path.join(TEST_DIR, 'promise.json')
return fse[method](file, obj1)
.then(() => {
const data = fs.readFileSync(file, 'utf8')
assert.strictEqual(data, JSON.stringify(obj1) + '\n')
})
})
})
})
})

2
package.json

@ -34,7 +34,7 @@
"license": "MIT",
"dependencies": {
"graceful-fs": "^4.1.2",
"jsonfile": "^3.0.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
},
"devDependencies": {

Loading…
Cancel
Save