Socket
Socket
Sign inDemoInstall

parse-json

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-json - npm Package Compare versions

Comparing version 8.0.0 to 8.0.1

45

index.js

@@ -6,29 +6,24 @@ import fallback from 'json-parse-even-better-errors';

export class JSONError extends Error {
name = 'JSONError';
fileName;
codeFrame;
rawCodeFrame;
#message;
constructor(message) {
super(message);
// We cannot pass message to `super()`, otherwise the message accessor will be overridden.
// https://262.ecma-international.org/14.0/#sec-error-message
super();
let _message = message instanceof Error
? message.message
: message;
this.#message = message;
Error.captureStackTrace?.(this, JSONError);
}
Object.defineProperty(this, 'message', {
configurable: true,
enumerable: false,
get() {
return `${_message}${this.fileName ? ` in ${this.fileName}` : ''}${this.codeFrame ? `\n\n${this.codeFrame}\n` : ''}`;
},
set(value) {
_message = value;
},
});
get message() {
const {fileName, codeFrame} = this;
return `${this.#message}${fileName ? ` in ${fileName}` : ''}${codeFrame ? `\n\n${codeFrame}\n` : ''}`;
}
this.name = 'JSONError';
if (Error.captureStackTrace) {
Error.captureStackTrace(this, JSONError);
}
set message(message) {
this.#message = message;
}

@@ -47,3 +42,3 @@ }

const {index, line, column} = match.groups;
let {index, line, column} = match.groups;

@@ -54,3 +49,11 @@ if (line && column) {

return indexToPosition(string, Number(index), {oneBased: true});
index = Number(index);
// The error location can be out of bounds.
if (index === string.length) {
const {line, column} = indexToPosition(string, string.length - 1, {oneBased: true});
return {line, column: column + 1};
}
return indexToPosition(string, index, {oneBased: true});
};

@@ -57,0 +60,0 @@

{
"name": "parse-json",
"version": "8.0.0",
"version": "8.0.1",
"description": "Parse JSON with more helpful errors",

@@ -14,3 +14,7 @@ "license": "MIT",

"type": "module",
"exports": "./index.js",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {

@@ -39,5 +43,5 @@ "node": ">=18"

"@babel/code-frame": "^7.22.13",
"index-to-position": "^0.1.0",
"index-to-position": "^0.1.1",
"json-parse-even-better-errors": "^3.0.0",
"type-fest": "^4.6.0"
"type-fest": "^4.7.1"
},

@@ -44,0 +48,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc