json-parse-even-better-errors
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -92,1 +92,7 @@ 'use strict' | ||
parseJson.JSONParseError = JSONParseError | ||
parseJson.noExceptions = (txt, reviver) => { | ||
try { | ||
return JSON.parse(stripBOM(txt), reviver) | ||
} catch (e) {} | ||
} |
{ | ||
"name": "json-parse-even-better-errors", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "JSON.parse with context information on error", | ||
@@ -12,3 +12,3 @@ "main": "index.js", | ||
"postversion": "npm publish", | ||
"postpublish": "git push --follow-tags", | ||
"prepublishOnly": "git push --follow-tags", | ||
"test": "tap", | ||
@@ -15,0 +15,0 @@ "snap": "tap" |
@@ -23,4 +23,5 @@ # json-parse-even-better-errors [![npm version](https://img.shields.io/npm/v/json-parse-even-better-errors.svg)](https://npm.im/json-parse-even-better-errors) [![license](https://img.shields.io/npm/l/json-parse-even-better-errors.svg)](https://npm.im/json-parse-even-better-errors) [![Travis](https://img.shields.io/travis/npm/json-parse-even-better-errors.svg)](https://travis-ci.org/npm/json-parse-even-better-errors) [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/npm/json-parse-even-better-errors?svg=true)](https://ci.appveyor.com/project/npm/json-parse-even-better-errors) [![Coverage Status](https://coveralls.io/repos/github/npm/json-parse-even-better-errors/badge.svg?branch=latest)](https://coveralls.io/github/npm/json-parse-even-better-errors?branch=latest) | ||
parseJson('"foo"') | ||
parseJson('"foo"') // returns the string 'foo' | ||
parseJson('garbage') // more useful error message | ||
parseJson.noExceptions('garbage') // returns undefined | ||
``` | ||
@@ -31,2 +32,4 @@ | ||
* Like JSON.parse, but the errors are better. | ||
* Strips a leading byte-order-mark that you sometimes get reading files. | ||
* Has a `noExceptions` method that returns undefined rather than throwing. | ||
@@ -40,2 +43,7 @@ ### API | ||
#### <a name="parse"></a> `parse.noExceptions(txt, reviver = null)` | ||
Works just like `JSON.parse`, but will return `undefined` rather than | ||
throwing an error. | ||
#### <a name="jsonparseerror"></a> `class JSONParseError(er, text, context = 20, caller = null)` | ||
@@ -42,0 +50,0 @@ |
8560
83
60