diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/jsonfile | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) |
update packages
Diffstat (limited to 'node_modules/jsonfile')
-rw-r--r-- | node_modules/jsonfile/.npmignore | 3 | ||||
-rw-r--r-- | node_modules/jsonfile/CHANGELOG.md | 11 | ||||
-rw-r--r-- | node_modules/jsonfile/README.md | 62 | ||||
-rw-r--r-- | node_modules/jsonfile/index.js | 42 | ||||
-rw-r--r-- | node_modules/jsonfile/package.json | 7 |
5 files changed, 58 insertions, 67 deletions
diff --git a/node_modules/jsonfile/.npmignore b/node_modules/jsonfile/.npmignore deleted file mode 100644 index 874ae5800..000000000 --- a/node_modules/jsonfile/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -test/ -.travis.yml -appveyor.yml diff --git a/node_modules/jsonfile/CHANGELOG.md b/node_modules/jsonfile/CHANGELOG.md index ff0c4e30d..7718857ab 100644 --- a/node_modules/jsonfile/CHANGELOG.md +++ b/node_modules/jsonfile/CHANGELOG.md @@ -1,3 +1,11 @@ +4.0.0 / 2017-07-12 +------------------ + +- **BREAKING:** Remove global `spaces` option. +- **BREAKING:** Drop support for Node 0.10, 0.12, and io.js. +- Remove undocumented `passParsingErrors` option. +- Added `EOL` override option to `writeFile` when using `spaces`. [#89] + 3.0.1 / 2017-07-05 ------------------ @@ -89,12 +97,13 @@ changes it according to docs. [#12][#12] ------------------ * Initial release. +[#89]: https://github.com/jprichardson/node-jsonfile/pull/89 [#45]: https://github.com/jprichardson/node-jsonfile/issues/45 "Reading of UTF8-encoded (w/ BOM) files fails" [#44]: https://github.com/jprichardson/node-jsonfile/issues/44 "Extra characters in written file" [#43]: https://github.com/jprichardson/node-jsonfile/issues/43 "Prettyfy json when written to file" [#42]: https://github.com/jprichardson/node-jsonfile/pull/42 "Moved fs.readFileSync within the try/catch" [#41]: https://github.com/jprichardson/node-jsonfile/issues/41 "Linux: Hidden file not working" -[#40]: https://github.com/jprichardson/node-jsonfile/issues/40 "autocreate folder doesnt work from Path-value" +[#40]: https://github.com/jprichardson/node-jsonfile/issues/40 "autocreate folder doesn't work from Path-value" [#39]: https://github.com/jprichardson/node-jsonfile/pull/39 "Add `throws` option for readFile (async)" [#38]: https://github.com/jprichardson/node-jsonfile/pull/38 "Update README.md writeFile[Sync] signature" [#37]: https://github.com/jprichardson/node-jsonfile/pull/37 "support append file" diff --git a/node_modules/jsonfile/README.md b/node_modules/jsonfile/README.md index 1f214df9b..721685c92 100644 --- a/node_modules/jsonfile/README.md +++ b/node_modules/jsonfile/README.md @@ -57,7 +57,7 @@ console.dir(jsonfile.readFileSync(file)) ### writeFile(filename, obj, [options], callback) -`options`: Pass in any `fs.writeFile` options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces`. +`options`: Pass in any `fs.writeFile` options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces` and override `EOL` string. ```js @@ -84,6 +84,19 @@ jsonfile.writeFile(file, obj, {spaces: 2}, function(err) { }) ``` +**overriding EOL:** + +```js +var jsonfile = require('jsonfile') + +var file = '/tmp/data.json' +var obj = {name: 'JP'} + +jsonfile.writeFile(file, obj, {spaces: 2, EOL: '\r\n'}, function(err) { + console.error(err) +}) +``` + **appending to an existing JSON file:** You can use `fs.writeFile` option `{flag: 'a'}` to achieve this. @@ -101,7 +114,7 @@ jsonfile.writeFile(file, obj, {flag: 'a'}, function (err) { ### writeFileSync(filename, obj, [options]) -`options`: Pass in any `fs.writeFileSync` options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces`. +`options`: Pass in any `fs.writeFileSync` options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces` and override `EOL` string. ```js var jsonfile = require('jsonfile') @@ -123,61 +136,30 @@ var obj = {name: 'JP'} jsonfile.writeFileSync(file, obj, {spaces: 2}) ``` -**appending to an existing JSON file:** - -You can use `fs.writeFileSync` option `{flag: 'a'}` to achieve this. +**overriding EOL:** ```js var jsonfile = require('jsonfile') -var file = '/tmp/mayAlreadyExistedData.json' +var file = '/tmp/data.json' var obj = {name: 'JP'} -jsonfile.writeFileSync(file, obj, {flag: 'a'}) +jsonfile.writeFileSync(file, obj, {spaces: 2, EOL: '\r\n'}) ``` -### spaces - -Global configuration to set spaces to indent JSON files. +**appending to an existing JSON file:** -**default:** `null` +You can use `fs.writeFileSync` option `{flag: 'a'}` to achieve this. ```js var jsonfile = require('jsonfile') -jsonfile.spaces = 4 - -var file = '/tmp/data.json' +var file = '/tmp/mayAlreadyExistedData.json' var obj = {name: 'JP'} -// json file has four space indenting now -jsonfile.writeFile(file, obj, function (err) { - console.error(err) -}) -``` - -Note, it's bound to `this.spaces`. So, if you do this: - -```js -var myObj = {} -myObj.writeJsonSync = jsonfile.writeFileSync -// => this.spaces = null -``` - -Could do the following: - -```js -var jsonfile = require('jsonfile') -jsonfile.spaces = 4 -jsonfile.writeFileSync(file, obj) // will have 4 spaces indentation - -var myCrazyObj = {spaces: 32} -myCrazyObj.writeJsonSync = jsonfile.writeFileSync -myCrazyObj.writeJsonSync(file, obj) // will have 32 space indentation -myCrazyObj.writeJsonSync(file, obj, {spaces: 2}) // will have only 2 +jsonfile.writeFileSync(file, obj, {flag: 'a'}) ``` - License ------- diff --git a/node_modules/jsonfile/index.js b/node_modules/jsonfile/index.js index a28684f60..d1e5827ca 100644 --- a/node_modules/jsonfile/index.js +++ b/node_modules/jsonfile/index.js @@ -19,10 +19,7 @@ function readFile (file, options, callback) { var fs = options.fs || _fs var shouldThrow = true - // DO NOT USE 'passParsingErrors' THE NAME WILL CHANGE!!!, use 'throws' instead - if ('passParsingErrors' in options) { - shouldThrow = options.passParsingErrors - } else if ('throws' in options) { + if ('throws' in options) { shouldThrow = options.throws } @@ -56,10 +53,7 @@ function readFileSync (file, options) { var fs = options.fs || _fs var shouldThrow = true - // DO NOT USE 'passParsingErrors' THE NAME WILL CHANGE!!!, use 'throws' instead - if ('passParsingErrors' in options) { - shouldThrow = options.passParsingErrors - } else if ('throws' in options) { + if ('throws' in options) { shouldThrow = options.throws } @@ -77,6 +71,23 @@ function readFileSync (file, options) { } } +function stringify (obj, options) { + var spaces + var EOL = '\n' + if (typeof options === 'object' && options !== null) { + if (options.spaces) { + spaces = options.spaces + } + if (options.EOL) { + EOL = options.EOL + } + } + + var str = JSON.stringify(obj, options ? options.replacer : null, spaces) + + return str.replace(/\n/g, EOL) + EOL +} + function writeFile (file, obj, options, callback) { if (callback == null) { callback = options @@ -85,14 +96,9 @@ function writeFile (file, obj, options, callback) { options = options || {} var fs = options.fs || _fs - var spaces = typeof options === 'object' && options !== null - ? 'spaces' in options - ? options.spaces : this.spaces - : this.spaces - var str = '' try { - str = JSON.stringify(obj, options ? options.replacer : null, spaces) + '\n' + str = stringify(obj, options) } catch (err) { // Need to return whether a callback was passed or not if (callback) callback(err, null) @@ -106,12 +112,7 @@ function writeFileSync (file, obj, options) { options = options || {} var fs = options.fs || _fs - var spaces = typeof options === 'object' && options !== null - ? 'spaces' in options - ? options.spaces : this.spaces - : this.spaces - - var str = JSON.stringify(obj, options.replacer, spaces) + '\n' + var str = stringify(obj, options) // not sure if fs.writeFileSync returns anything, but just in case return fs.writeFileSync(file, str, options) } @@ -124,7 +125,6 @@ function stripBom (content) { } var jsonfile = { - spaces: null, readFile: readFile, readFileSync: readFileSync, writeFile: writeFile, diff --git a/node_modules/jsonfile/package.json b/node_modules/jsonfile/package.json index 52719edb2..29e783f4f 100644 --- a/node_modules/jsonfile/package.json +++ b/node_modules/jsonfile/package.json @@ -1,6 +1,6 @@ { "name": "jsonfile", - "version": "3.0.1", + "version": "4.0.0", "description": "Easily read/write JSON files.", "repository": { "type": "git", @@ -23,9 +23,12 @@ "devDependencies": { "mocha": "2.x", "rimraf": "^2.4.0", - "standard": "^6.0.8" + "standard": "^10.0.3" }, "main": "index.js", + "files": [ + "index.js" + ], "scripts": { "lint": "standard", "test": "npm run lint && npm run unit", |