14 lines
618 B
TypeScript
14 lines
618 B
TypeScript
export function EscapeStringRegexp(string: string) {
|
|
if (typeof string !== "string") {
|
|
throw new TypeError("Expected a string");
|
|
}
|
|
|
|
// 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 string.replace(/[|\\{}()[\]^$+*?.]/gu, "\\$&").replace(/-/gu, "\\x2d");
|
|
}
|
|
|
|
export function IsRecord(maybeRecord: unknown): maybeRecord is Record<string, unknown> {
|
|
return typeof maybeRecord === "object" && maybeRecord !== null;
|
|
}
|