validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

Prevent import * into index.js file so that bundlers can treeshake efficiently.

Open Jme797 opened this issue 4 months ago • 2 comments

Fixes: #2587

Modifies the exports inside index.js so that instead of importing all the code into the file and exporting it as a single object it just exports the functions directly.

This comes with the caveat you can no longer import * like import validator from 'validator' in esm modules because that prevents codesplitting.

If you really want to for whatever reason you can replace that syntax with import * as validator from 'validator'

Though importing specific functions is more efficient using imports like import {isEmail} from 'validator'

Checklist

  • [ ] PR contains only changes related; no stray files, etc.
  • [ ] README updated (where applicable)
  • [ ] Tests written (where applicable)
  • [ ] References provided in PR (where applicable)

Jme797 avatar Sep 17 '25 11:09 Jme797

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 100.00%. Comparing base (6f436be) to head (de9b0c7).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2588   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       115    +1     
  Lines         2536      2535    -1     
  Branches       642       643    +1     
=========================================
- Hits          2536      2535    -1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Sep 17 '25 12:09 codecov[bot]

@Jme797 I'm noticing the test failures in other PRs as well. I think it's a dependency issue, will look into it later

WikiRik avatar Sep 21 '25 05:09 WikiRik