ZooTools / email-spell-checker

📮 An ultratiny (1.9 KB) and fast JavaScript email checker to reduce users typing a wrong email. Written in TypeScript. Enterprise-grade.
https://zootools.co/tools/email-spell-checker
MIT License
163 stars 12 forks source link

Global domains configuration #19

Open faelsoto opened 1 year ago

faelsoto commented 1 year ago

Current Behavior

From the documentation:

emailSpellChecker.run({
  domains: [...emailSpellChecker.POPULAR_DOMAINS, 'customdomain.com'], // replaces existing domains
  secondLevelDomains: ['domain', 'yetanotherdomain'], // replaces existing SLDs
  topLevelDomains: ['com.au', 'ru'], // replaces existing TLDs
});

Running this snippet throws an Uncaught TypeError: opts.email is undefined exception.

Expected Behavior

A snippet provided in the readme shouldn't fail. Also, the domains, second level domains and top level domains list gets updated globally?

Steps to Reproduce the Problem

  1. Run snippet provided by readme

Environment


We've been using mailcheck but as you already know, it is quite outdated. So I thank your for this project, it was way overdue. The thing that I'm wondering is if it would not be best to let the config be overwritten globally, just as Mailcheck used to do it. If that's not the original idea that's fine, but maybe the docs should reflect it by not including a snippet that won't work.

ferreiro commented 1 year ago

Hey @faelsoto! Glad you are enjoying using the package and sorry you had issues.

Just fixed the code snippet. We were just missing passing an email to the code snippet. Here is the fix: https://github.com/ZooTools/email-spell-checker/blob/main/README.md#adding-your-own-domains

I think overrides global makes sense in case you just want to have custom ones. You can simply import the constant file POPULAR_TLDS and append that to your custom list.

What is missing is that we don't expose the default secondLevelDomains. Would it that be enough if you were having that? Also what's your use case?