What types does the function expect and return?
What types does the function expect and return?
About sindresorhus/escape-string-regexp · 2 messages · last activity 7/27/2026
The escapeStringRegexp function expects and returns a string.
According to the TypeScript definition in [index.d.ts:L16-L17], the function signature is:
export default function escapeStringRegexp(string: string): string;
The function accepts a single parameter of type string and returns a string. This is also validated at runtime in [index.js:L2-L4], where the function throws a TypeError if the input is not a string:
if (typeof string !== 'string') {
throw new TypeError('Expected a string');
}
The test file confirms this behavior in [index.test-d.ts:L4], which uses expectType<string>() to verify the return type.
FOLLOW_UPS:
- What special characters does the function escape?
- How does the function handle the hyphen character differently?
- Can you show me an example of the function's output?
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.