RepoPilot

What types does the function expect and return?

About sindresorhus/escape-string-regexp · 2 messages · last activity 5/25/2026

Question

What types does the function expect and return?

RepoPilot

The function expects a string parameter and returns a string.

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

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

Additionally, the implementation in [index.js:L1-L4] enforces this contract by checking the input type at runtime:

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

If a non-string value is passed, a TypeError is thrown. The function always returns an escaped string when given valid input.

FOLLOW_UPS:

  • What RegExp characters does the function escape?
  • How does it handle the hyphen character specially?
  • Can you show an example of the function in use?

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.