Skip to content

Commit

Permalink
Update code point
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 22, 2023
1 parent 3763b7a commit 39b4a2b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {codeFrameColumns} from '@babel/code-frame';
import indexToPosition from 'index-to-position';

const getCodePoint = character => {
const codePoint = character.codePointAt(0).toString(16).toUpperCase();
return '0x' + (codePoint.length % 2 ? '0' : '') + codePoint;
};
const getCodePoint = character => `\\u{${character.codePointAt(0).toString(16)}}`;

export class JSONError extends Error {
name = 'JSONError';
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const NODE_JS_VERSION = Number(process.versions.node.split('.')[0]);

const errorMessageRegex = (() => {
if (NODE_JS_VERSION < 20) {
return /Unexpected token "}"\(0x7D\)/;
return /Unexpected token "}"\(\\u{61\}\)/;
}

if (NODE_JS_VERSION < 21) {
Expand Down Expand Up @@ -125,7 +125,7 @@ test('Unexpected tokens', t => {
if (NODE_JS_VERSION === 18) {
t.is(firstLine, 'Unexpected token "a"(0x61) in JSON at position 0');
} else {
t.is(firstLine, 'Unexpected token "a"(0x61), "a" is not valid JSON');
t.is(firstLine, 'Unexpected token "a"(\\u{61}), "a" is not valid JSON');
}
}
});

0 comments on commit 39b4a2b

Please sign in to comment.