RepoPilot

What types does the function expect and return?

About sindresorhus/escape-string-regexp · 2 messages · last activity 5/18/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]:

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

At runtime, the function also enforces this type constraint in [index.js:L2-L4]:

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

So if you pass anything other than a string, it will throw a TypeError.

FOLLOW_UPS:

  • What RegExp special characters does it escape?
  • How does the function handle edge cases like Unicode?
  • Can you show an example of the escaping output?

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.