Initial pass
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
# 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.
|
||||
|
||||
<a name="1.0.2"></a>
|
||||
## [1.0.2](https://github.com/zkat/json-parse-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/zkat/json-parse-better-errors/issues/1)) ([a476d42](https://github.com/zkat/json-parse-better-errors/commit/a476d42))
|
||||
|
||||
|
||||
|
||||
<a name="1.0.1"></a>
|
||||
## [1.0.1](https://github.com/zkat/json-parse-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/zkat/json-parse-better-errors/commit/efe2958))
|
||||
|
||||
|
||||
|
||||
<a name="1.0.0"></a>
|
||||
# 1.0.0 (2017-08-15)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **init:** Initial Commit ([562c977](https://github.com/zkat/json-parse-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/zkat/json-parse-better-errors/commit/9dd1a19))
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
Copyright 2017 Kat Marchán
|
||||
|
||||
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.
|
||||
+46
File diff suppressed because one or more lines are too long
+38
@@ -0,0 +1,38 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = parseJson
|
||||
function 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
|
||||
const errorMessage = 'Cannot parse ' +
|
||||
(isEmptyArray ? 'an empty array' : String(txt))
|
||||
throw new TypeError(errorMessage)
|
||||
}
|
||||
const syntaxErr = e.message.match(/^Unexpected token.*position\s+(\d+)/i)
|
||||
const errIdx = syntaxErr
|
||||
? +syntaxErr[1]
|
||||
: e.message.match(/^Unexpected end of JSON.*/i)
|
||||
? txt.length - 1
|
||||
: null
|
||||
if (errIdx != null) {
|
||||
const start = errIdx <= context
|
||||
? 0
|
||||
: errIdx - context
|
||||
const end = errIdx + context >= txt.length
|
||||
? txt.length
|
||||
: errIdx + context
|
||||
e.message += ` while parsing near '${
|
||||
start === 0 ? '' : '...'
|
||||
}${txt.slice(start, end)}${
|
||||
end === txt.length ? '' : '...'
|
||||
}'`
|
||||
} else {
|
||||
e.message += ` while parsing '${txt.slice(0, context * 2)}'`
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"[email protected]",
|
||||
"C:\\Users\\Administrator\\Documents\\setup-python"
|
||||
]
|
||||
],
|
||||
"_development": true,
|
||||
"_from": "[email protected]",
|
||||
"_id": "[email protected]",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==",
|
||||
"_location": "/json-parse-better-errors",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "[email protected]",
|
||||
"name": "json-parse-better-errors",
|
||||
"escapedName": "json-parse-better-errors",
|
||||
"rawSpec": "1.0.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.0.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/parse-json"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz",
|
||||
"_spec": "1.0.2",
|
||||
"_where": "C:\\Users\\Administrator\\Documents\\setup-python",
|
||||
"author": {
|
||||
"name": "Kat Marchán",
|
||||
"email": "[email protected]"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/zkat/json-parse-better-errors/issues"
|
||||
},
|
||||
"config": {
|
||||
"nyc": {
|
||||
"exclude": [
|
||||
"node_modules/**",
|
||||
"test/**"
|
||||
]
|
||||
}
|
||||
},
|
||||
"description": "JSON.parse with context information on error",
|
||||
"devDependencies": {
|
||||
"nyc": "^10.3.2",
|
||||
"standard": "^9.0.2",
|
||||
"standard-version": "^4.1.0",
|
||||
"tap": "^10.3.3",
|
||||
"weallbehave": "^1.2.0",
|
||||
"weallcontribute": "^1.0.8"
|
||||
},
|
||||
"files": [
|
||||
"*.js"
|
||||
],
|
||||
"homepage": "https://github.com/zkat/json-parse-better-errors#readme",
|
||||
"keywords": [
|
||||
"JSON",
|
||||
"parser"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "json-parse-better-errors",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zkat/json-parse-better-errors.git"
|
||||
},
|
||||
"scripts": {
|
||||
"postrelease": "npm publish && git push --follow-tags",
|
||||
"prerelease": "npm t",
|
||||
"pretest": "standard",
|
||||
"release": "standard-version -s",
|
||||
"test": "tap -J --coverage test/*.js",
|
||||
"update-coc": "weallbehave -o . && git add CODE_OF_CONDUCT.md && git commit -m 'docs(coc): updated CODE_OF_CONDUCT.md'",
|
||||
"update-contrib": "weallcontribute -o . && git add CONTRIBUTING.md && git commit -m 'docs(contributing): updated CONTRIBUTING.md'"
|
||||
},
|
||||
"version": "1.0.2"
|
||||
}
|
||||
Reference in New Issue
Block a user