npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

emailvalid

v1.0.4

Published

Email validation with more than 10K disposable/temporary email domains

Downloads

7,606

Readme

Email Validation is a library that validates email addresses and checks againts more than 10K domains used for disposable emails If you want to block disposable email addresses at signup, or if you are a B2B company and want only professional email adresses, this is the solution for you :)

This library does multiple verifications:

  • Email format validation
  • Free email address (@gmail.com, @hotmail.com, @protonmail.com, ...)
  • Disposable email address (@maildrop.cc, @fakemail.net, @trashmail.com, ...)
  • Possible typos in popular email domains

Email Validation has 0 dependency, 100% coverage, and is fully configurable.

Table of Contents

Installation

Install using npm:

npm install emailvalid

or Yarn yarn:

yarn add emailvalid

Usage

Email Validation is initialized with a list of default domains

Simple usage example

const EmailValidation = require('emailvalid')
const ev = new EmailValidation()

// This email will be invalid because it is a free email
const result = ev.check('[email protected]')
console.log(`${result.email} validity: ${result.valid}`)

// This email will be invalid because it is a disposable email
const result2 = ev.check('[email protected]')
console.log(`${result2.email} validity: ${result2.valid}`)

// You can also check for possible typos
const result3 = ev.check('[email protected]')
if (result3.typo) console.log(`Did you mean ${result3.typo}?`)

The output will be an object with some information on the validity (see result section)

Configuration

Email Validation can be configured with more advanced options as an object:

  • whitelist (Array) Add some email domains you want to whitelist (default is [])
  • blacklist (Array) Add some email domains you want to blacklist (default is [])
  • allowFreemail (Boolean) Allow free emails such as @gmail.com, ... (default is false)
  • allowDisposable (Boolean) Allow disposable emails such as @trashmail.com, ... (default is false)

You can for example choose to allow freemails, and add a domain baddomain.com in addition to the preconfigured list

Advanced configuration example

const EmailValidation = require('emailvalid')
const ev = new EmailValidation({ allowFreemail: true, blacklist: ['baddomain.com'] })

// This one should have result.valid = true because we allowed free mails such as gmail.com
ev.check('[email protected]')

// But this one is blacklisted now 
ev.check('[email protected]')

Or if you want to disallow all free mails, except gmail.com :

const ev = new EmailValidation({ whitelist: ['gmail.com'] })

You can check some examples in example.js

Updating options on the fly

In case you need to update options after initialization, you can do it on the fly with different methods:

  • whitelist (Function) Add a new domain to the whitelist
  • blacklist (Function) Add a new domain to the blacklist
  • setOptions (Function) Changes the options
const EmailValidation = require('emailvalid')
const ev = new EmailValidation()

// This adds a new domain as invalid
ev.blacklist('baddomain.com')

// This marks a domain as valid
ev.whitelist('gooddomain.com')

// This changes options to allow freemails
ev.setOptions({ allowFreemail: true })

Result

Email Validation will output an object with the following information:

  • email (String) Email in a standardized format (trimed and lowercased)
  • domain (String) Domain from the email
  • valid (Boolean) Is the email address valid?
  • errors (Array) List of errors if any
  • typo (String) Is there any possible typo in the email?

Errors contains strings and can be one of :

  • invalid Email is not present of format is invalid
  • disposable Email is disposable (and not whitelisted or allowed in parameters)
  • freemail Email is a free mail (and not whitelisted or allowed in parameters)
  • blacklisted Email is blacklisted in parameters

Example :

const EmailValidation = require('emailvalid')
const ev = new EmailValidation()

const result = ev.check('[email protected]')
console.log(result)

// This will return :
// {
//   email: '[email protected]',
//   domain: 'gmail.com'
//   valid: false,
//   errors: ['freemail'],
//   typo: null
// {

Contributions

If you need a simple way to add domains to the list, just run yarn add-domain [DOMAIN] [CATEGORY]

For example yarn add-domain freemail gmail.com

Then feel free to create Pull Requests :)

Licence

MIT License