diff options
author | claudiahdz <cghr1990@gmail.com> | 2020-02-19 00:17:29 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-05-08 04:11:51 +0300 |
commit | b9bc4f04019a9c8af266e28d95d38f0d1e25d1f7 (patch) | |
tree | 0c262a7fa0f4f1a0e6b16ac578491a5aaa92b7bc /node_modules/json-parse-even-better-errors | |
parent | 0a30b0d8a1c448b6d89d781ad81f46117d014953 (diff) |
pacote@11.0.0
Diffstat (limited to 'node_modules/json-parse-even-better-errors')
5 files changed, 265 insertions, 0 deletions
diff --git a/node_modules/json-parse-even-better-errors/CHANGELOG.md b/node_modules/json-parse-even-better-errors/CHANGELOG.md new file mode 100644 index 000000000..dfd67330a --- /dev/null +++ b/node_modules/json-parse-even-better-errors/CHANGELOG.md @@ -0,0 +1,50 @@ +# Change Log + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## 2.0.0 + +* Add custom error classes + +<a name="1.0.2"></a> +## [1.0.2](https://github.com/npm/json-parse-even-better-errors/compare/v1.0.1...v1.0.2) (2018-03-30) + + +### Bug Fixes + +* **messages:** More friendly messages for non-string ([#1](https://github.com/npm/json-parse-even-better-errors/issues/1)) ([a476d42](https://github.com/npm/json-parse-even-better-errors/commit/a476d42)) + + + +<a name="1.0.1"></a> +## [1.0.1](https://github.com/npm/json-parse-even-better-errors/compare/v1.0.0...v1.0.1) (2017-08-16) + + +### Bug Fixes + +* **license:** oops. Forgot to update license.md ([efe2958](https://github.com/npm/json-parse-even-better-errors/commit/efe2958)) + + + +<a name="1.0.0"></a> +# 1.0.0 (2017-08-15) + + +### Features + +* **init:** Initial Commit ([562c977](https://github.com/npm/json-parse-even-better-errors/commit/562c977)) + + +### BREAKING CHANGES + +* **init:** This is the first commit! + + + +<a name="0.1.0"></a> +# 0.1.0 (2017-08-15) + + +### Features + +* **init:** Initial Commit ([9dd1a19](https://github.com/npm/json-parse-even-better-errors/commit/9dd1a19)) diff --git a/node_modules/json-parse-even-better-errors/LICENSE.md b/node_modules/json-parse-even-better-errors/LICENSE.md new file mode 100644 index 000000000..cb6c4a624 --- /dev/null +++ b/node_modules/json-parse-even-better-errors/LICENSE.md @@ -0,0 +1,25 @@ +Copyright 2017 Kat Marchán +Copyright npm, Inc. and Contributors + +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. + +--- + +This library is a fork of 'better-json-errors' by Kat Marchán, extended and +distributed under the terms of the MIT license above. diff --git a/node_modules/json-parse-even-better-errors/README.md b/node_modules/json-parse-even-better-errors/README.md new file mode 100644 index 000000000..631035f9a --- /dev/null +++ b/node_modules/json-parse-even-better-errors/README.md @@ -0,0 +1,51 @@ +# 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) + +[`json-parse-even-better-errors`](https://github.com/npm/json-parse-even-better-errors) is a Node.js library for +getting nicer errors out of `JSON.parse()`, including context and position of the parse errors. + +## Install + +`$ npm install --save json-parse-even-better-errors` + +## Table of Contents + +* [Example](#example) +* [Features](#features) +* [Contributing](#contributing) +* [API](#api) + * [`parse`](#parse) + +### Example + +```javascript +const parseJson = require('json-parse-even-better-errors') + +parseJson('"foo"') +parseJson('garbage') // more useful error message +``` + +### Features + +* Like JSON.parse, but the errors are better. + +### API + +#### <a name="parse"></a> `parse(txt, reviver = null, context = 20)` + +Works just like `JSON.parse`, but will include a bit more information when an +error happens. This throws a `JSONParseError`. + +#### <a name="jsonparseerror"></a> `class JSONParseError(er, text, context = 20, caller = null)` + +Extends the JavaScript `SyntaxError` class to parse the message and provide +better metadata. + +Pass in the error thrown by the built-in `JSON.parse`, and the text being +parsed, and it'll parse out the bits needed to be helpful. + +`context` defaults to 20. + +Set a `caller` function to trim internal implementation details out of the +stack trace. When calling `parseJson`, this is set to the `parseJson` +function. If not set, then the constructor defaults to itself, so the +stack trace will point to the spot where you call `new JSONParseError`. diff --git a/node_modules/json-parse-even-better-errors/index.js b/node_modules/json-parse-even-better-errors/index.js new file mode 100644 index 000000000..a6354e81d --- /dev/null +++ b/node_modules/json-parse-even-better-errors/index.js @@ -0,0 +1,75 @@ +'use strict' + +const parseError = (e, txt, context) => { + if (!txt) { + return { + message: e.message + ' while parsing empty string', + position: 0, + } + } + const badToken = e.message.match(/^Unexpected token.*position\s+(\d+)/i) + const errIdx = badToken ? +badToken[1] + : e.message.match(/^Unexpected end of JSON.*/i) ? txt.length - 1 + : null + + if (errIdx !== null && errIdx !== undefined) { + const start = errIdx <= context ? 0 + : errIdx - context + + const end = errIdx + context >= txt.length ? txt.length + : errIdx + context + + const slice = (start === 0 ? '' : '...') + + txt.slice(start, end) + + (end === txt.length ? '' : '...') + + const near = txt === slice ? '' : 'near ' + + return { + message: e.message + ` while parsing ${near}'${slice}'`, + position: errIdx, + } + } else { + return { + message: e.message + ` while parsing '${txt.slice(0, context * 2)}'`, + position: 0, + } + } +} + +class JSONParseError extends SyntaxError { + constructor (er, txt, context, caller) { + context = context || 20 + const metadata = parseError(er, txt, context) + super(metadata.message) + Object.assign(this, metadata) + this.code = 'EJSONPARSE' + this.systemError = er + Error.captureStackTrace(this, caller || this.constructor) + } + get name () { return this.constructor.name } + set name (n) {} + get [Symbol.toStringTag] () { return this.constructor.name } +} + +const parseJson = (txt, reviver, context) => { + context = context || 20 + try { + return JSON.parse(txt, reviver) + } catch (e) { + if (typeof txt !== 'string') { + const isEmptyArray = Array.isArray(txt) && txt.length === 0 + throw Object.assign(new TypeError( + `Cannot parse ${isEmptyArray ? 'an empty array' : String(txt)}` + ), { + code: 'EJSONPARSE', + systemError: e, + }) + } + + throw new JSONParseError(e, txt, context, parseJson) + } +} + +module.exports = parseJson +parseJson.JSONParseError = JSONParseError diff --git a/node_modules/json-parse-even-better-errors/package.json b/node_modules/json-parse-even-better-errors/package.json new file mode 100644 index 000000000..de383dac7 --- /dev/null +++ b/node_modules/json-parse-even-better-errors/package.json @@ -0,0 +1,64 @@ +{ + "_from": "json-parse-even-better-errors@^2.0.1", + "_id": "json-parse-even-better-errors@2.0.1", + "_inBundle": false, + "_integrity": "sha512-XFY2Mbnmg+8r7MRsxfArVkZcfjxGlF/NjM3LsPXVeCX/GBF/1FTCv+idHBYC4qLPtK7q8HC8bapLoWqnhP/bXw==", + "_location": "/json-parse-even-better-errors", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "json-parse-even-better-errors@^2.0.1", + "name": "json-parse-even-better-errors", + "escapedName": "json-parse-even-better-errors", + "rawSpec": "^2.0.1", + "saveSpec": null, + "fetchSpec": "^2.0.1" + }, + "_requiredBy": [ + "/read-package-json-fast" + ], + "_resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.0.1.tgz", + "_shasum": "ed0009e0f5e7eb21ae0675d0d34782cc7a53c60e", + "_spec": "json-parse-even-better-errors@^2.0.1", + "_where": "/Users/claudiahdz/npm/cli/node_modules/read-package-json-fast", + "author": { + "name": "Kat Marchán", + "email": "kzm@zkat.tech" + }, + "bugs": { + "url": "https://github.com/npm/json-parse-even-better-errors/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "JSON.parse with context information on error", + "devDependencies": { + "tap": "^14.6.5" + }, + "files": [ + "*.js" + ], + "homepage": "https://github.com/npm/json-parse-even-better-errors#readme", + "keywords": [ + "JSON", + "parser" + ], + "license": "MIT", + "main": "index.js", + "name": "json-parse-even-better-errors", + "repository": { + "type": "git", + "url": "git+https://github.com/npm/json-parse-even-better-errors.git" + }, + "scripts": { + "postpublish": "git push --follow-tags", + "postversion": "npm publish", + "preversion": "npm t", + "snap": "tap", + "test": "tap" + }, + "tap": { + "check-coverage": true + }, + "version": "2.0.1" +} |