How is the function exported? Is it a default export or a named one?
How is the function exported? Is it a default export or a named one?
About sindresorhus/escape-string-regexp · 2 messages · last activity 8/1/2026
The function is exported as a default export.
In index.js:L1, the function is declared directly with export default function escapeStringRegexp(string) { ... }, and it's consumed accordingly in the tests and type definitions:
- Usage in tests:
import escapeStringRegexp from './index.js';[test.js:L2] - Usage in the type test:
import escapeStringRegexp from './index.js';[index.test-d.ts:L2] - Usage in the README:
import escapeStringRegexp from 'escape-string-regexp';[readme.md:L16]
The TypeScript declaration also confirms this with export default function escapeStringRegexp(string: string): string; [index.d.ts:L16-L17].
Additionally, the package.json specifies "exports": "./index.js" [package.json:L15], meaning the module's only export is this default-exported function — there are no named exports.
FOLLOW_UPS:
- What characters does the regex
/[|\\{}()[\]^$+*?.]/gescape? - Why is
-escaped separately with\x2d? - What Node.js versions does this package support?
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.