I think using const instead of default function when exporting is better when import.
Imagine I have the equals function. In normal export I normally use(with es6)
import contains from 'validator/lib/contains'
And what about use Object Destructuring like this
import { contains } from 'validator'
Or something more...
import { contains, isAlpha } from 'validator'
If you like this way, I can help sending a pull request.
What do you think?
I don't have an ES6 setup handy, but doesn't the library already support object destructuring? The first way you mentioned is still preferred since it only imports a subset of the library that you're interested in.
It doesn't support named imports, you can only destructure after you import the entire validator object.
import validator from 'validator';
const { contains } = validator;
agree with @hkwu.
we can import the module including the file like:
import contains from 'validator/lib/contains'
however, we can't import other functions. If so, we need to import again another file.
Is this a backwards compatible change? After the change could I both import validator from 'validator' and import { contains } from 'validator'?
As long as you keep the default export, yes.
export {
contains,
isAlpha,
// ...
};
export default validator;
Alright, happy to accept a PR as long as it's backwards compatible.
Closed based on the feedback in https://github.com/chriso/validator.js/pull/597