2 const errorEx = require('error-ex');
3 const fallback = require('./vendor/parse');
5 function appendPosition(message) {
6 const posRe = / at (\d+:\d+) in/;
7 const numbers = posRe.exec(message);
8 return message.replace(posRe, ' in') + ':' + numbers[1];
11 const JSONError = errorEx('JSONError', {
12 fileName: errorEx.append('in %s'),
14 message: (shouldAppend, original) => {
16 original[0] = appendPosition(original[0]);
23 module.exports = (input, reviver, filename) => {
24 if (typeof reviver === 'string') {
31 return JSON.parse(input, reviver);
33 fallback.parse(input, {
41 const jsonErr = new JSONError(err);
44 jsonErr.fileName = filename;
45 jsonErr.appendPosition = true;