1
0
mirror of https://github.com/thangisme/notes.git synced 2024-12-23 00:06:33 -05:00
notes/node_modules/parse-json/index.js
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00

36 lines
589 B
JavaScript

'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;
}
};