RepoPilot

What types does the function expect and return?

About sindresorhus/escape-string-regexp · 2 messages · last activity 8/1/2026

Question

What types does the function expect and return?

RepoPilot

The escapeStringRegexp function expects and returns strings.

According to the TypeScript definition in [index.d.ts:L16-L17], the function signature is:

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

This means:

  • Input: expects a string parameter
  • Output: returns a string

The implementation in [index.js:L1-L4] also enforces this by throwing a TypeError if the input is not a string:

if (typeof string !== 'string') {
    throw new TypeError('Expected a string');
}

The TypeScript tests in [index.test-d.ts:L4] confirm the return type is string via expectType<string>(...).

FOLLOW_UPS:

  • What characters does the function escape?
  • How does the function handle the hyphen character?
  • What are some usage examples shown in tests?

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.