smashsend/email-spell-checker
Acerca de
📮 An ultratiny (1.9 KB) and fast JavaScript email checker to reduce users typing a wrong email. Written in TypeScript. Enterprise-grade.
Productividad y automatizaciónWhat you can do
- ⚡️ Lightning fast: Highly performant email checking using Sift3 - a fast and accurate string distance algorithm.
- 🔋 Updated: 39+ popular domains, and 66+ modern TLDs out-of-the-box. Frequently updated.
- 🚀 Ridiculously small: 1.8KB (minzip) and 0 external dependencies. We agree, big bundles suck!
- 💙 TypeScript: Fully written in TypeScript, cause we know you love it and we too.
Crecimiento de estrellas medido
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- Recopilando historial
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
README.md
OriginalThe best way to check a misspelled email address in JavaScript
🔐 Reduce failed authentication ⬆️ Increase email delivery ⚡️ Built for speed
@zootools/email-spell-checker
EmailSpellChecker is a lightweight JavaScript module written in TypeScript that suggests the right domain when your users misspell it in an email address.
At SmashSend, an email marketing and referral tool, we validate thousands of misspelled emails daily with EmailSpellChecker and it helped us to reduce bounced emails by 30%.
It's by far the easiest way to reduce misspelled email addresses in your web apps and server.
The features you deserve
We rewrote and improved mailcheck.js, a great module that is no longer maintained (7+ years since the last update) and we fixed critical bugs like this, or this.
- ⚡️ Lightning fast: Highly performant email checking using
Sift3- a fast and accurate string distance algorithm. - 🔋 Updated: 39+ popular domains, and 66+ modern TLDs out-of-the-box. Frequently updated.
- 🚀 Ridiculously small: 1.8KB (minzip) and 0 external dependencies. We agree, big bundles suck!
- 💙 TypeScript: Fully written in TypeScript, cause we know you love it and we too.
- ⚙️ Extensible: Allows you to pass your custom rules and domains. Tweak it as you need.
- 🔨 1-minute migration: Same API and functions as mailcheck so you can switch in a sec!
- 🔐 Unit tested: Cause we'd never use a library without tests :).
Why should you validate email spelling?
Typos in the email will harm your business. Especially email deliverability. Common user misspellings such as “gnail” instead of “gmail” or “yaho” instead of “yahoo” can be used as spam traps by ISPs, and as a result, your emails will be blocked or marked as spam.
Common use cases:
- User authentication (login, signup, email recovery).
- Backend email validation.
- Newsletter subscriptions.
Tutorials
Here are some highly-requested tutorials.
- 🟨 JavaScript: Getting started in 5 minutes
- 🟦 React: Validating email spell in React (coming soon)
- 🟩 Node with Express.js: Validating email spell in Node
If you want to write a tutorial send a PR or create an issue if you want to ask for one.
Getting Started in 5 minutes
Adding EmailSpellChecker to your project takes less than 5 minutes.
It works on any JavaScript framework (Vue, React, Next.JS, Angular, Svelte, etc) as well as your backend server.
Installation
Install with npm:
npm i @zootools/email-spell-checker --save
Install with yarn:
yarn add @zootools/email-spell-checker
Use from a CDN (no build step):
<script type="module">
import emailSpellChecker from 'https://cdn.jsdelivr.net/npm/@zootools/email-spell-checker/+esm';
console.log(emailSpellChecker.run({ email: '[email protected]' })?.full); // [email protected]
</script>
To pin a version, use https://cdn.jsdelivr.net/npm/@zootools/email-spell-checker@1/+esm. See demos/html for a full example.
Basic Example
Using the library is easy. Import it, call the run function with the email you want to validate, and get a suggestion.
import emailSpellChecker from '@zootools/email-spell-checker';
const suggestion = emailSpellChecker.run({
email: '[email protected]'
})
if (suggestion) {
// dev: user made a typo -- handle the suggestion.
// for example: show a message to fix the email.
console.log(suggestion.address); // jorge
console.log(suggestion.domain); // gmail.com
console.log(suggestion.full); // [email protected]
}
Spell checker, not a validator.
runreturns a suggestion when the domain looks like a typo, andundefinedotherwise.undefinedmeans "nothing to suggest". It does not mean the email is valid:run({ email: 'test' })andrun({ email: '[email protected]' })both returnundefined. If you also need syntax or deliverability checks, use a dedicated validation library alongside this one.
Extending Domains
EmailSpellChecker has inbuilt defaults if the domains, secondLevelDomains or topLevelDomains options aren't provided.
The out-of-the-box configuration is the best for 99% of cases. If you are that 1%, here is how you can extend the configuration :).
How the defaults work
Suggestions are checked in this order:
domains(POPULAR_DOMAINS): full domains such asgmail.com. If the whole domain is close to one of these, it is suggested. For example,gmial.com→gmail.com.secondLevelDomains(POPULAR_SLDS): provider names without a TLD (yahoo,hotmail,live,outlook). They match any TLD, which is why big providers with many country domains live here and not indomains. For example,hotmial.co.uk→hotmail.co.ukandoutlok.com→outlook.com.topLevelDomains(POPULAR_TLDS): TLDs such ascomandco.uk, used to fix the ending. For example,example.con→example.com.
If the address already uses a known second-level domain together with a known TLD (e.g. yahoo.fr), nothing is suggested.
Adding your own Domains
You can replace EmailSpellChecker's default domain/TLD suggestions by supplying replacements to EmailSpellChecker.run:
emailSpellChecker.run({
email: '[email protected]',
domains: [...emailSpellChecker.POPULAR_DOMAINS, 'customdomain.com'], // extends the default domains
secondLevelDomains: [...emailSpellChecker.POPULAR_SLDS, 'walla'], // extends the default SLDs
topLevelDomains: ['com.au', 'ru'], // replaces the default TLDs
});
Tests
EmailSpellChecker is tested with Jest, a popular JavaScript testing framework from Facebook with a focus on simplicity.
Run npm test from the command line to run the test suite.
Who uses EmailSpellChecker?
We're putting together a list of happy users of EmailSpellChecker.
Tweet us @ZooToolsHQ and @JGFerreiro if you are interested to appear.
Customer support & updates
Updates
- 🎯 Join our mailing lists to get useful information about this and other useful open source libraries: https://form.waitlistpanda.com/go/8H98mVOzZhwGMalf8nfb
- 📆 Click "Watch repo" on GitHub and ⭐️ the repo to be notified of useful information.
Customer support
- 🤝 Do you have bugs or issues? Email [email protected] or create an issue
Socials
Maintainers
This library is used and maintained by SmashSend: Growth and marketing tools for ambitious teams.
We use this library heavily in SmashSend, a MailChimp alternative for sending viral marketing campaigns.
You can try the checker live on the tool page.
We're hiring!
Badass developer looking for a job? Join the grind!
Made with love by SmashSend
Explorar proyectos relacionados
Cargando…