parse-json
Advanced tools
Comparing version 2.1.0 to 2.2.0
16
index.js
@@ -9,3 +9,8 @@ 'use strict'; | ||
module.exports = function (x, reviver) { | ||
module.exports = function (x, reviver, filename) { | ||
if (typeof reviver === 'string') { | ||
filename = reviver; | ||
reviver = null; | ||
} | ||
try { | ||
@@ -23,5 +28,10 @@ try { | ||
} catch (err) { | ||
JSONError.call(err); | ||
throw err; | ||
var jsonErr = new JSONError(err); | ||
if (filename) { | ||
jsonErr.fileName = filename; | ||
} | ||
throw jsonErr; | ||
} | ||
}; |
{ | ||
"name": "parse-json", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Parse JSON with more helpful errors", | ||
@@ -35,3 +35,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"error-ex": "^1.1.0" | ||
"error-ex": "^1.2.0" | ||
}, | ||
@@ -38,0 +38,0 @@ "devDependencies": { |
@@ -19,2 +19,3 @@ # parse-json [![Build Status](https://travis-ci.org/sindresorhus/parse-json.svg?branch=master)](https://travis-ci.org/sindresorhus/parse-json) | ||
JSON.parse(json); | ||
@@ -28,2 +29,3 @@ /* | ||
parseJson(json); | ||
@@ -36,2 +38,12 @@ /* | ||
parseJson(json, 'foo.json'); | ||
/* | ||
JSONError: Trailing comma in object at 3:1 in foo.json | ||
} | ||
^ | ||
*/ | ||
// you can also add the filename at a later point | ||
try { | ||
@@ -43,3 +55,2 @@ parseJson(json); | ||
} | ||
/* | ||
@@ -54,3 +65,3 @@ JSONError: Trailing comma in object at 3:1 in foo.json | ||
### parseJson(input, [reviver]) | ||
### parseJson(input, [reviver], [filename]) | ||
@@ -68,5 +79,11 @@ #### input | ||
#### filename | ||
Type: `string` | ||
Filename displayed in the error message. | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
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
33466
747
84
Updatederror-ex@^1.2.0