mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-02-13 16:13:24 +01:00
add syntax error position dom utility function
This commit is contained in:
parent
5029516523
commit
f6b8b0182d
1 changed files with 10 additions and 0 deletions
|
@ -204,3 +204,13 @@ export const tryDecodeURIComponent = (encodedURIComponent: string): string => {
|
|||
return encodedURIComponent;
|
||||
}
|
||||
};
|
||||
|
||||
export const syntaxErrorPosition = (error: SyntaxError): number | undefined => {
|
||||
const match = error.message.match(/position\s(\d+)\s/);
|
||||
if (!match) return undefined;
|
||||
|
||||
const posStr = match[1];
|
||||
const position = parseInt(posStr, 10);
|
||||
if (Number.isNaN(position)) return undefined;
|
||||
return position;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue