Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use "export default as" syntax for easier ES6 imports and tree shaking purposes #683

Open
mrtnbroder opened this issue Jul 14, 2017 · 5 comments

Comments

@mrtnbroder
Copy link

Currently, you can only use the import isEmail from 'validator/lib/isEmail' syntax to only grab the validators you want, and you have to repeat this for every validator you need in your file.

Easier would be import { isEmail, isNumeric } from 'validator'.

Using export { default as isEmail } from './lib/isEmail' within the index.js file and exporting everything with export default { isEmail, ... }, would allow us an easier way to grab the validators we want, and remove some repetitive code.

This would still work with tree-shaking as you can see here.

@chriso
Copy link
Collaborator

chriso commented Aug 22, 2017

PRs are welcome! If you can do it in a backwards-compatible way then I'd be happy to accept the change.

@SujitSingh
Copy link

SujitSingh commented Oct 17, 2018

For someone who is still looking for this ES6 import format, I have tried this in an Angular project with *.ts files and I am sure same will work in *.js files.

import * as validator from 'validator';

And then, use it like below

validator.isJWT('5j6k-4df5-4cl4t')

@Dunky13
Copy link

Dunky13 commented Apr 22, 2021

4 years later, still a nice to have feature

@ihmpavel
Copy link

ihmpavel commented May 26, 2021

@profnandaa @chriso

Do we still need to make imports/exports backwards-compatible? Does major version update (to 14.x) will not be enough? I will make PR, if import * as validator from 'validator' and import { isEmail, ... } from 'validator' will be accepted.

Or does anyone have any idea, how to accomplish this behavior? Tell me and I will make my best to create PR

@KeithGillette
Copy link

@ihmpavel, is this suggestion to add supported module formats to package.json helpful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants