Skip to content

Commit

Permalink
Remove error-ex dependency (#43)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
prisis and sindresorhus committed Nov 2, 2023
1 parent c26d16e commit af8e41f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
35 changes: 30 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
import errorEx from 'error-ex';
import fallback from 'json-parse-even-better-errors';
import {codeFrameColumns} from '@babel/code-frame';
import {LinesAndColumns} from 'lines-and-columns';

export const JSONError = errorEx('JSONError', {
fileName: errorEx.append('in %s'),
codeFrame: errorEx.append('\n\n%s\n'),
});
export class JSONError extends Error {
fileName;
codeFrame;
rawCodeFrame;

constructor(message) {
super(message);

let _message = message instanceof Error
? message.message
: message;

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;
},
});

this.name = 'JSONError';

if (Error.captureStackTrace) {
Error.captureStackTrace(this, JSONError);
}
}
}

const generateCodeFrame = (string, location, highlightCode = true) =>
codeFrameColumns(string, {start: location}, {highlightCode});
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
],
"dependencies": {
"@babel/code-frame": "^7.21.4",
"error-ex": "^1.3.2",
"json-parse-even-better-errors": "^3.0.0",
"lines-and-columns": "^2.0.3",
"type-fest": "^3.8.0"
Expand Down

0 comments on commit af8e41f

Please sign in to comment.