add syntax error position dom utility function

This commit is contained in:
Ajay Bura 2024-12-22 07:52:04 +05:30
parent 5029516523
commit f6b8b0182d

View file

@ -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;
};