RepoPilot

What types does the function expect and return?

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

Question

What types does the function expect and return?

RepoPilot

The escapeStringRegexp function expects a string as input 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-L4] enforces this by throwing a TypeError if the input is not a string:

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

FOLLOW_UPS:

  • What RegExp special characters does it escape?
  • How does the function handle Unicode characters?
  • What happens if you pass non-string input?

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.