RepoPilot

How is the function exported? Is it a default export or a named one?

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

Question

How is the function exported? Is it a default export or a named one?

RepoPilot

The function is exported as a default export.

In index.js:L1, the function is declared directly with export default function escapeStringRegexp(string) {...}, making it the module's default export.

This is confirmed in several other places:

  • The TypeScript type declaration mirrors this with export default function escapeStringRegexp(string: string): string; [index.d.ts:L16-L17]
  • All usage examples import it as a default import: import escapeStringRegexp from 'escape-string-regexp'; (seen in the README usage section, [readme.md:L14-L23], and in the test files [test.js:L1-L2] and [index.test-d.ts:L1-L2])
  • The package.json exports field points to ./index.js [package.json:L14], which is the module containing that default export.

So there's no named export — consumers always import it as the default, e.g. import escapeStringRegexp from 'escape-string-regexp'.

FOLLOW_UPS:

  • What characters does escapeStringRegexp actually escape?
  • Why is - escaped differently than other characters?
  • What Node.js versions does this package support?

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.