aboutsummaryrefslogtreecommitdiff
path: root/node_modules/jsonfile/index.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/jsonfile/index.js
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/jsonfile/index.js')
-rw-r--r--node_modules/jsonfile/index.js42
1 files changed, 21 insertions, 21 deletions
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,