diff --git a/src/utils.ts b/src/utils.ts index 18df81511..9a7f434c4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -173,13 +173,11 @@ export function tempfile(extension = ''): string { } export function escapeStringRegexp(value: string): string { - if (typeof value !== 'string') { - throw new TypeError(`Expected a string instead got: ${typeof value}`); - } - - // Escape characters with special meaning either inside or outside character sets. - // Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar. - return value - .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') - .replace(/-/g, '\\x2d'); + if (typeof value !== 'string') { + throw new TypeError(`Expected a string instead got: ${typeof value}`) + } + + // Escape characters with special meaning either inside or outside character sets. + // Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar. + return value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d') }