parse-json
Advanced tools
Comparing version 2.0.0 to 2.1.0
22
index.js
'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) { | ||
try { | ||
return JSON.parse(x, reviver); | ||
try { | ||
return JSON.parse(x, reviver); | ||
} catch (err) { | ||
fallback.parse(x, { | ||
mode: 'json', | ||
reviver: reviver | ||
}); | ||
throw err; | ||
} | ||
} catch (err) { | ||
fallback.parse(x, { | ||
mode: 'json', | ||
reviver: reviver | ||
}); | ||
JSONError.call(err); | ||
throw err; | ||
} | ||
}; |
{ | ||
"name": "parse-json", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Parse JSON with more helpful errors", | ||
@@ -34,2 +34,5 @@ "license": "MIT", | ||
], | ||
"dependencies": { | ||
"error-ex": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
@@ -36,0 +39,0 @@ "ava": "0.0.4", |
@@ -29,6 +29,19 @@ # parse-json [![Build Status](https://travis-ci.org/sindresorhus/parse-json.svg?branch=master)](https://travis-ci.org/sindresorhus/parse-json) | ||
/* | ||
SyntaxError: Trailing comma in object at 3:1 | ||
JSONError: Trailing comma in object at 3:1 | ||
} | ||
^ | ||
*/ | ||
try { | ||
parseJson(json); | ||
} catch (err) { | ||
err.fileName = 'foo.json'; | ||
throw err; | ||
} | ||
/* | ||
JSONError: Trailing comma in object at 3:1 in foo.json | ||
} | ||
^ | ||
*/ | ||
``` | ||
@@ -35,0 +48,0 @@ |
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
33070
740
67
0
1
+ Addederror-ex@^1.1.0
+ Addederror-ex@1.3.2(transitive)
+ Addedis-arrayish@0.2.1(transitive)