diff options
Diffstat (limited to 'node_modules/parse-json/index.js')
-rw-r--r-- | node_modules/parse-json/index.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/node_modules/parse-json/index.js b/node_modules/parse-json/index.js new file mode 100644 index 0000000..04add8a --- /dev/null +++ b/node_modules/parse-json/index.js @@ -0,0 +1,35 @@ +'use strict'; +var errorEx = require('error-ex'); +var fallback = require('./vendor/parse'); + +var JSONError = errorEx('JSONError', { + fileName: errorEx.append('in %s') +}); + +module.exports = function (x, reviver, filename) { + if (typeof reviver === 'string') { + filename = reviver; + reviver = null; + } + + try { + try { + return JSON.parse(x, reviver); + } catch (err) { + fallback.parse(x, { + mode: 'json', + reviver: reviver + }); + + throw err; + } + } catch (err) { + var jsonErr = new JSONError(err); + + if (filename) { + jsonErr.fileName = filename; + } + + throw jsonErr; + } +}; |