From bbff7403fbf46f9ad92240ac213df8d30ef31b64 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 Sep 2018 02:56:13 +0200 Subject: update packages --- node_modules/jsonfile/index.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'node_modules/jsonfile/index.js') 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, -- cgit v1.2.3