RepoPilot

How does this function validate its input — does it throw on bad arguments?

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

Question

How does this function validate its input — does it throw on bad arguments?

RepoPilot

Yes, the function validates its input and throws on bad arguments. Looking at [index.js:L1-L4], the function includes a type check:

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

If the argument is not a string, it throws a TypeError with the message "Expected a string". This ensures the function only accepts string inputs and fails fast with a clear error if called with other types like numbers, objects, or null.

FOLLOW_UPS:

  • What characters does the function escape?
  • How are hyphens handled differently than other 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.