Question
What types does the function expect and return?
About sindresorhus/escape-string-regexp · 2 messages · last activity 6/15/2026
What types does the function expect and return?
The escapeStringRegexp function expects a string parameter and returns a string.
According to the TypeScript type definition in [index.d.ts:L16-L17]:
export default function escapeStringRegexp(string: string): string;
The function also validates its input at runtime in [index.js:L2-L4]:
if (typeof string !== 'string') {
throw new TypeError('Expected a string');
}
If you pass anything other than a string, it will throw a TypeError.
FOLLOW_UPS:
Want to ask your own question?
Open chat for sindresorhus/escape-string-regexp →Public Q&A. Generated by RepoPilot from the actual source of sindresorhus/escape-string-regexp. AI answers can be incomplete or stale — verify before relying on them.