RepoPilot

What types does the function expect and return?

About sindresorhus/escape-string-regexp ยท 2 messages ยท last activity 6/29/2026

Question

What types does the function expect and return?

RepoPilot

The escapeStringRegexp function expects a string parameter and returns a string.

This is defined in the TypeScript declaration file [index.d.ts:L16-L17]:

export default function escapeStringRegexp(string: string): string;

The implementation in [index.js:L1-L2] enforces this 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 the return type is string:

expectType<string>(escapeStringRegexp('how much $ for a ๐Ÿฆ„?'));

FOLLOW_UPS:

  • What special characters does the function escape?
  • Does the function handle Unicode characters differently?
  • What is the \x2d escape in the second regex replacement?

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.