Clean up the oopsie. Rebuild the blank exercises.

This commit is contained in:
Michael Frank
2021-05-09 00:39:21 +12:00
parent b984cb4c6f
commit d28d80c46f
1565 changed files with 27186 additions and 199003 deletions
+60 -24
View File
@@ -1,20 +1,19 @@
# parse-json [![Build Status](https://travis-ci.org/sindresorhus/parse-json.svg?branch=master)](https://travis-ci.org/sindresorhus/parse-json)
# parse-json
> Parse JSON with more helpful errors
## Install
```
$ npm install --save parse-json
$ npm install parse-json
```
## Usage
```js
var parseJson = require('parse-json');
var json = '{\n\t"foo": true,\n}';
const parseJson = require('parse-json');
const json = '{\n\t"foo": true,\n}';
JSON.parse(json);
@@ -28,45 +27,59 @@ SyntaxError: Unexpected token }
parseJson(json);
/*
JSONError: Trailing comma in object at 3:1
}
^
JSONError: Unexpected token } in JSON at position 16 while parsing near '{ "foo": true,}'
1 | {
2 | "foo": true,
> 3 | }
| ^
*/
parseJson(json, 'foo.json');
/*
JSONError: Trailing comma in object at 3:1 in 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
// You can also add the filename at a later point
try {
parseJson(json);
} catch (err) {
err.fileName = 'foo.json';
throw err;
} catch (error) {
if (error instanceof parseJson.JSONError) {
error.fileName = 'foo.json';
}
throw error;
}
/*
JSONError: Trailing comma in object at 3:1 in foo.json
}
^
JSONError: Unexpected token } in JSON at position 16 while parsing near '{ "foo": true,}' in foo.json
1 | {
2 | "foo": true,
> 3 | }
| ^
*/
```
## API
### parseJson(input, [reviver], [filename])
### parseJson(string, reviver?, filename?)
#### input
Throws a `JSONError` when there is a parsing error.
#### string
Type: `string`
#### reviver
Type: `function`
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.
@@ -77,7 +90,30 @@ Type: `string`
Filename displayed in the error message.
### parseJson.JSONError
## License
Exposed for `instanceof` checking.
MIT © [Sindre Sorhus](http://sindresorhus.com)
#### 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>