Validator.js: use const and object destructuring instead of default function

Created on 11 Oct 2016  路  7Comments  路  Source: validatorjs/validator.js

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?

馃檵鈥嶁檪锔廸eature-request

All 7 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smohiuddin picture smohiuddin  路  4Comments

AtomicBorg picture AtomicBorg  路  3Comments

mren picture mren  路  3Comments

galki picture galki  路  3Comments

mfbx9da4 picture mfbx9da4  路  4Comments