aboutsummaryrefslogtreecommitdiff
path: root/node_modules/parse-json
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/parse-json')
-rw-r--r--node_modules/parse-json/index.js54
-rw-r--r--node_modules/parse-json/license9
-rw-r--r--node_modules/parse-json/package.json45
-rw-r--r--node_modules/parse-json/readme.md119
4 files changed, 227 insertions, 0 deletions
diff --git a/node_modules/parse-json/index.js b/node_modules/parse-json/index.js
new file mode 100644
index 0000000..c2b9347
--- /dev/null
+++ b/node_modules/parse-json/index.js
@@ -0,0 +1,54 @@
+'use strict';
+const errorEx = require('error-ex');
+const fallback = require('json-parse-even-better-errors');
+const {default: LinesAndColumns} = require('lines-and-columns');
+const {codeFrameColumns} = require('@babel/code-frame');
+
+const JSONError = errorEx('JSONError', {
+ fileName: errorEx.append('in %s'),
+ codeFrame: errorEx.append('\n\n%s\n')
+});
+
+const parseJson = (string, reviver, filename) => {
+ if (typeof reviver === 'string') {
+ filename = reviver;
+ reviver = null;
+ }
+
+ try {
+ try {
+ return JSON.parse(string, reviver);
+ } catch (error) {
+ fallback(string, reviver);
+ throw error;
+ }
+ } catch (error) {
+ error.message = error.message.replace(/\n/g, '');
+ const indexMatch = error.message.match(/in JSON at position (\d+) while parsing/);
+
+ const jsonError = new JSONError(error);
+ if (filename) {
+ jsonError.fileName = filename;
+ }
+
+ if (indexMatch && indexMatch.length > 0) {
+ const lines = new LinesAndColumns(string);
+ const index = Number(indexMatch[1]);
+ const location = lines.locationForIndex(index);
+
+ const codeFrame = codeFrameColumns(
+ string,
+ {start: {line: location.line + 1, column: location.column + 1}},
+ {highlightCode: true}
+ );
+
+ jsonError.codeFrame = codeFrame;
+ }
+
+ throw jsonError;
+ }
+};
+
+parseJson.JSONError = JSONError;
+
+module.exports = parseJson;
diff --git a/node_modules/parse-json/license b/node_modules/parse-json/license
new file mode 100644
index 0000000..fa7ceba
--- /dev/null
+++ b/node_modules/parse-json/license
@@ -0,0 +1,9 @@
+MIT License
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/parse-json/package.json b/node_modules/parse-json/package.json
new file mode 100644
index 0000000..de073fd
--- /dev/null
+++ b/node_modules/parse-json/package.json
@@ -0,0 +1,45 @@
+{
+ "name": "parse-json",
+ "version": "5.2.0",
+ "description": "Parse JSON with more helpful errors",
+ "license": "MIT",
+ "repository": "sindresorhus/parse-json",
+ "funding": "https://github.com/sponsors/sindresorhus",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "https://sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "scripts": {
+ "test": "xo && nyc ava"
+ },
+ "files": [
+ "index.js",
+ "vendor"
+ ],
+ "keywords": [
+ "parse",
+ "json",
+ "graceful",
+ "error",
+ "message",
+ "humanize",
+ "friendly",
+ "helpful",
+ "string"
+ ],
+ "dependencies": {
+ "@babel/code-frame": "^7.0.0",
+ "error-ex": "^1.3.1",
+ "json-parse-even-better-errors": "^2.3.0",
+ "lines-and-columns": "^1.1.6"
+ },
+ "devDependencies": {
+ "ava": "^1.4.1",
+ "nyc": "^14.1.1",
+ "xo": "^0.24.0"
+ }
+}
diff --git a/node_modules/parse-json/readme.md b/node_modules/parse-json/readme.md
new file mode 100644
index 0000000..5363097
--- /dev/null
+++ b/node_modules/parse-json/readme.md
@@ -0,0 +1,119 @@
+# parse-json
+
+> Parse JSON with more helpful errors
+
+## Install
+
+```
+$ npm install parse-json
+```
+
+## Usage
+
+```js
+const parseJson = require('parse-json');
+
+const json = '{\n\t"foo": true,\n}';
+
+
+JSON.parse(json);
+/*
+undefined:3
+}
+^
+SyntaxError: Unexpected token }
+*/
+
+
+parseJson(json);
+/*
+JSONError: Unexpected token } in JSON at position 16 while parsing near '{ "foo": true,}'
+
+ 1 | {
+ 2 | "foo": true,
+> 3 | }
+ | ^
+*/
+
+
+parseJson(json, 'foo.json');
+/*
+JSONError: Unexpected token } in JSON at position 16 while parsing near '{ "foo": true,}' in foo.json
+
+ 1 | {
+ 2 | "foo": true,
+> 3 | }
+ | ^
+*/
+
+
+// You can also add the filename at a later point
+try {
+ parseJson(json);
+} catch (error) {
+ if (error instanceof parseJson.JSONError) {
+ error.fileName = 'foo.json';
+ }
+
+ throw error;
+}
+/*
+JSONError: Unexpected token } in JSON at position 16 while parsing near '{ "foo": true,}' in foo.json
+
+ 1 | {
+ 2 | "foo": true,
+> 3 | }
+ | ^
+*/
+```
+
+## API
+
+### parseJson(string, reviver?, filename?)
+
+Throws a `JSONError` when there is a parsing error.
+
+#### string
+
+Type: `string`
+
+#### reviver
+
+Type: `Function`
+
+Prescribes how the value originally produced by parsing is transformed, before being returned. See [`JSON.parse` docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter
+) for more.
+
+#### filename
+
+Type: `string`
+
+Filename displayed in the error message.
+
+### parseJson.JSONError
+
+Exposed for `instanceof` checking.
+
+#### fileName
+
+Type: `string`
+
+The filename displayed in the error message.
+
+#### codeFrame
+
+Type: `string`
+
+The printable section of the JSON which produces the error.
+
+---
+
+<div align="center">
+ <b>
+ <a href="https://tidelift.com/subscription/pkg/npm-parse-json?utm_source=npm-parse-json&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
+ </b>
+ <br>
+ <sub>
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
+ </sub>
+</div>