Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 authored Mar 29, 2022
1 parent 1649f11 commit 2a1cee8
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

0 comments on commit 2a1cee8

Please sign in to comment.