Updated the files.

This commit is contained in:
Batuhan Berk Başoğlu 2024-02-08 19:38:41 -05:00
parent 1553e6b971
commit 753967d4f5
23418 changed files with 3784666 additions and 0 deletions

54
my-app/node_modules/parse-json/index.js generated vendored Executable file
View file

@ -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;

9
my-app/node_modules/parse-json/license generated vendored Executable file
View file

@ -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.

View file

@ -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))

View file

@ -0,0 +1,25 @@
Copyright 2017 Kat Marchán
Copyright npm, Inc.
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.

View file

@ -0,0 +1,96 @@
# json-parse-even-better-errors
[`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.
It also preserves the newline and indentation styles of the JSON data, by
putting them in the object or array in the `Symbol.for('indent')` and
`Symbol.for('newline')` properties.
## 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"') // returns the string 'foo'
parseJson('garbage') // more useful error message
parseJson.noExceptions('garbage') // returns undefined
```
### Features
* 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.
* Attaches the newline character(s) used to the `Symbol.for('newline')`
property on objects and arrays.
* Attaches the indentation character(s) used to the `Symbol.for('indent')`
property on objects and arrays.
## Indentation
To preserve indentation when the file is saved back to disk, use
`data[Symbol.for('indent')]` as the third argument to `JSON.stringify`, and
if you want to preserve windows `\r\n` newlines, replace the `\n` chars in
the string with `data[Symbol.for('newline')]`.
For example:
```js
const txt = await readFile('./package.json', 'utf8')
const data = parseJsonEvenBetterErrors(txt)
const indent = Symbol.for('indent')
const newline = Symbol.for('newline')
// .. do some stuff to the data ..
const string = JSON.stringify(data, null, data[indent]) + '\n'
const eolFixed = data[newline] === '\n' ? string
: string.replace(/\n/g, data[newline])
await writeFile('./package.json', eolFixed)
```
Indentation is determined by looking at the whitespace between the initial
`{` and `[` and the character that follows it. If you have lots of weird
inconsistent indentation, then it won't track that or give you any way to
preserve it. Whether this is a bug or a feature is debatable ;)
### 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, and attaches a `Symbol.for('indent')` and
`Symbol.for('newline')` on objects and arrays. This throws a
`JSONParseError`.
#### <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)`
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`.

View file

@ -0,0 +1,121 @@
'use strict'
const hexify = char => {
const h = char.charCodeAt(0).toString(16).toUpperCase()
return '0x' + (h.length % 2 ? '0' : '') + h
}
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[2]
: e.message.match(/^Unexpected end of JSON.*/i) ? txt.length - 1
: null
const msg = badToken ? e.message.replace(/^Unexpected token ./, `Unexpected token ${
JSON.stringify(badToken[1])
} (${hexify(badToken[1])})`)
: e.message
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: msg + ` while parsing ${near}${JSON.stringify(slice)}`,
position: errIdx,
}
} else {
return {
message: msg + ` 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 kIndent = Symbol.for('indent')
const kNewline = Symbol.for('newline')
// only respect indentation if we got a line break, otherwise squash it
// things other than objects and arrays aren't indented, so ignore those
// Important: in both of these regexps, the $1 capture group is the newline
// or undefined, and the $2 capture group is the indent, or undefined.
const formatRE = /^\s*[{\[]((?:\r?\n)+)([\s\t]*)/
const emptyRE = /^(?:\{\}|\[\])((?:\r?\n)+)?$/
const parseJson = (txt, reviver, context) => {
const parseText = stripBOM(txt)
context = context || 20
try {
// get the indentation so that we can save it back nicely
// if the file starts with {" then we have an indent of '', ie, none
// otherwise, pick the indentation of the next line after the first \n
// If the pattern doesn't match, then it means no indentation.
// JSON.stringify ignores symbols, so this is reasonably safe.
// if the string is '{}' or '[]', then use the default 2-space indent.
const [, newline = '\n', indent = ' '] = parseText.match(emptyRE) ||
parseText.match(formatRE) ||
[, '', '']
const result = JSON.parse(parseText, reviver)
if (result && typeof result === 'object') {
result[kNewline] = newline
result[kIndent] = indent
}
return result
} catch (e) {
if (typeof txt !== 'string' && !Buffer.isBuffer(txt)) {
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, parseText, context, parseJson)
}
}
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
// because the buffer-to-string conversion in `fs.readFileSync()`
// translates it to FEFF, the UTF-16 BOM.
const stripBOM = txt => String(txt).replace(/^\uFEFF/, '')
module.exports = parseJson
parseJson.JSONParseError = JSONParseError
parseJson.noExceptions = (txt, reviver) => {
try {
return JSON.parse(stripBOM(txt), reviver)
} catch (e) {}
}

View file

@ -0,0 +1,33 @@
{
"name": "json-parse-even-better-errors",
"version": "2.3.1",
"description": "JSON.parse with context information on error",
"main": "index.js",
"files": [
"*.js"
],
"scripts": {
"preversion": "npm t",
"postversion": "npm publish",
"prepublishOnly": "git push --follow-tags",
"test": "tap",
"snap": "tap"
},
"repository": "https://github.com/npm/json-parse-even-better-errors",
"keywords": [
"JSON",
"parser"
],
"author": {
"name": "Kat Marchán",
"email": "kzm@zkat.tech",
"twitter": "maybekatz"
},
"license": "MIT",
"devDependencies": {
"tap": "^14.6.5"
},
"tap": {
"check-coverage": true
}
}

45
my-app/node_modules/parse-json/package.json generated vendored Executable file
View file

@ -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"
}
}

119
my-app/node_modules/parse-json/readme.md generated vendored Executable file
View file

@ -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>