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

isValid method? #50

Open
niftylettuce opened this issue Feb 4, 2020 · 4 comments
Open

isValid method? #50

niftylettuce opened this issue Feb 4, 2020 · 4 comments

Comments

@niftylettuce
Copy link

Other packages such as isemail, @hapi/address, and validator seem to have validation bugs. Parsing packages such as addressparser in nodemailer/lib/addressparser also seem to have issues when parsing certain addresses. It would be useful if this package exposed a simple isValid method which returned true or false. I'm assuming this could be a simple wrapper around parseOneAddress method which checked if the return value had a typeof with value of "Object" - but I haven't looked close enough yet to determine if that's the case.

@niftylettuce
Copy link
Author

It looks like this is the case. I don't write TypeScript and not sure if you would accept this PR.

@jackbearheart
Copy link
Owner

Yes, @niftylettuce , that is accurate. In your code, you could write !!parseOneAddress(...) to get this functionality.

I would accept such a PR! I would like to do two things: 1) add a function parseOneMailbox that is exactly like parseOneAddress except it looks for one mailbox instead of one address (ts return type ParsedMailbox | null) 2) add function isMailbox(m) { return !!parseOneMailbox(m); } (ts return type boolean). Happy to receive a PR like that or I'll get around to it someday.

@niftylettuce
Copy link
Author

I don't write nor support TypeScript so unfortunately cannot contribute

@xemlock
Copy link

xemlock commented Nov 5, 2020

@niftylettuce Watch out when using parseOneAddress for email validation, as current version (v3.1.0) can't properly handle invalid domains - see #53.

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

3 participants