parse-json
Advanced tools
Comparing version 3.0.0 to 4.0.0
27
index.js
'use strict'; | ||
const errorEx = require('error-ex'); | ||
const fallback = require('./vendor/parse'); | ||
const fallback = require('json-parse-better-errors'); | ||
function appendPosition(message) { | ||
const posRe = / at (\d+:\d+) in/; | ||
const numbers = posRe.exec(message); | ||
return message.replace(posRe, ' in') + ':' + numbers[1]; | ||
} | ||
const JSONError = errorEx('JSONError', { | ||
fileName: errorEx.append('in %s'), | ||
appendPosition: { | ||
message: (shouldAppend, original) => { | ||
if (shouldAppend) { | ||
original[0] = appendPosition(original[0]); | ||
} | ||
return original; | ||
} | ||
} | ||
fileName: errorEx.append('in %s') | ||
}); | ||
@@ -33,6 +19,3 @@ | ||
} catch (err) { | ||
fallback.parse(input, { | ||
mode: 'json', | ||
reviver | ||
}); | ||
fallback(input, reviver); | ||
@@ -42,7 +25,7 @@ throw err; | ||
} catch (err) { | ||
err.message = err.message.replace(/\n/g, ''); | ||
const jsonErr = new JSONError(err); | ||
if (filename) { | ||
jsonErr.fileName = filename; | ||
jsonErr.appendPosition = true; | ||
} | ||
@@ -49,0 +32,0 @@ |
{ | ||
"name": "parse-json", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Parse JSON with more helpful errors", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "xo && ava" | ||
"test": "xo && nyc ava" | ||
}, | ||
@@ -36,8 +36,10 @@ "files": [ | ||
"dependencies": { | ||
"error-ex": "^1.3.1" | ||
"error-ex": "^1.3.1", | ||
"json-parse-better-errors": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"nyc": "^11.2.1", | ||
"xo": "*" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3742
2
3
4
27
1
+ Addedjson-parse-better-errors@1.0.2(transitive)