Question
How does this function validate its input — does it throw on bad arguments?
About sindresorhus/escape-string-regexp · 2 messages · last activity 7/6/2026
How does this function validate its input — does it throw on bad arguments?
Yes, the function validates its input and throws on bad arguments.
The validation occurs at the very start of the function [index.js:L2-L4]:
if (typeof string !== 'string') {
throw new TypeError('Expected a string');
}
If you pass anything other than a string, it will throw a TypeError with the message 'Expected a string'. This ensures the function only operates on actual strings before proceeding to the escaping logic.
FOLLOW_UPS:
Want to ask your own question?
Open chat for sindresorhus/escape-string-regexpPublic 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.