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

isISO8601 is not a function when import a subset #688

Closed
tphan18 opened this issue Jul 27, 2017 · 5 comments
Closed

isISO8601 is not a function when import a subset #688

tphan18 opened this issue Jul 27, 2017 · 5 comments

Comments

@tphan18
Copy link

tphan18 commented Jul 27, 2017

Description

const isISO8601 = require('validator/lib/isISO8601');
isISO8601('2016-01-20T12:31:12.123Z') // TypeError: isISO8601 is not a function

validator.isISO8601(str) works fine.

@hkwu
Copy link
Contributor

hkwu commented Aug 7, 2017

Make sure to do require('...').default if you aren't using import.

@galtalmor
Copy link

It doesn't work with import either for this validator, unlike other validators.

@tphan18
Copy link
Author

tphan18 commented Aug 7, 2017

I haven't tested the solution from @hkwu, but if it works, the behavior is not consistent with the rests.

@hkwu
Copy link
Contributor

hkwu commented Aug 7, 2017

Hmm, yeah must be the add-module-exports plugin. Personally think it shouldn't be doing this at all, now we have some files that require .default and some that don't.

@chriso
Copy link
Collaborator

chriso commented Aug 22, 2017

So this appears to be due to multiple exports in the same ./src/lib/ file.

Notice how the isEmail validator doesn't export its regular expressions, while isISO8601 does:

> require('validator/lib/isEmail')
[Function: isEmail]
> require('validator/lib/isISO8601')
{ iso8601: /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/,
  default: [Function] }

It's an easy fix.

@chriso chriso closed this as completed in b3e45da Aug 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants