Question
What types does the function expect and return?
About sindresorhus/escape-string-regexp · 2 messages · last activity 7/6/2026
What types does the function expect and return?
Based on the TypeScript definitions in [index.d.ts:L16-L17], the escapeStringRegexp function has the following type signature:
export default function escapeStringRegexp(string: string): string;
Parameter: Expects a string
Return type: Returns a string
The implementation in [index.js:L1-L4] enforces this at runtime by throwing a TypeError if the input is not a string:
if (typeof string !== 'string') {
throw new TypeError('Expected a string');
}
The type test in [index.test-d.ts:L4] confirms this contract by verifying the return value is typed as string.
FOLLOW_UPS:
Want to ask your own question?
Open chat for sindresorhus/escape-string-regexpPublic 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.