RepoPilot

What types does the function expect and return?

About sindresorhus/escape-string-regexp · 2 messages · last activity 7/20/2026

Question

What types does the function expect and return?

RepoPilot

The function escapeStringRegexp expects a string as input and returns a string.

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

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

The function enforces this at runtime as well. If a non-string value is passed, it throws a TypeError, as shown in [index.js:L2-L4]:

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

FOLLOW_UPS:

  • What special characters does the function escape?
  • How does the function handle Unicode characters?
  • What are the test cases for this function?

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.