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 🙏

© 2026 – Pkg Stats / Ryan Hefner

better-email-validator

v1.0.0

Published

Zero dependency email validator with extra features

Readme

Help

Rate

BETTER-EMAIL-VALIDATOR 📧

Zero-dependency

lightweigh

📨 Email adress validator with extra features 🛠


⚠️ Disclaimer ⚠️

Read license before use it!


How can u help / TODO

It would be awesome if you help with something of this:

  • Add new regexp here
  • Add new domains to build-in whitelist here
  • Test existing prepared regex
  • Test existing tools (methods)
  • Write tests
  • Add new tools for emails
  • Make Readme better (i'll add TypeDoc soon, maybe)
  • Add JSDocs
  • Fix mistakes in Readme
  • Add code examples

You can compile .js files by command yarn build or npm run build

And run example with yarn example or npm run example


Install

npm i better-email-validator

    or

yarn add better-email-validator

Usage

Import

import { RFC5322, RFC822 EmailValidator } from 'better-email-validator';

    or

const { RFC5322, RFC822 EmailValidator } = require('better-email-validator');

RFC

RFC5322 and RFC822 are constant variables which contains implementation of specifications. Both RegExp

EmailValidator

This is main class which contains all methods

Create new instance:

const EV = new EmailValidator({
  // params
});

Params

| Param | Description | Type | Default | | -- | -- | -- | -- | | regex | Main checker. Pass own regexp or use prepared RFC5322 or RFC822 | RegExp | RFC5322 | | dotsRegEx | Regex for checking dots in name | RegExp | /[.](?=.*[@])/g | | allowDots | Is dots allowed in name | boolean | true | | allowTags | Is tags allowed in name (aa+bb@ccc.dd) | boolean | true | | allowSubdomain | Is subdomains allowed in domain | boolean | true | | tagSymbols | List of chars for tags. (Ex.: + for Gmail, - for qmail, etc) | Array | [ '+' ] | | tagRegExPattern | Regex pattern for tags check | string | '(%TAG%.*)@' | | details | false = methods return only boolean. true = object (check IDetails below) | boolean | false | | allowOnlyWhiteList | Allow only whitelisted domains. Check extra/whitelist.ts | boolean | false | | domains | If allowOnlyWhiteList = true, expands it. If not = this array counts as whitelist | Array | [] |

IDetails
interface IDetails {
  result: boolean,
  errorCode: string, // 'ok' if result 'true'
  errorInfo: string, // empty if result 'true'
}

Examples

const EV = new EmailValidator({
  domains: [ 'tab.mk' ],
  allowOnlyWhiteList: true,
  allowDots: false,
  details: true,
});

// domain whitelisted (wl expanded by 'domains')
EV.validate('[email protected]');
// => {
//      result: true,
//      errorCode: 'ok',
//      errorInfo: ''
//    }

// domain not whitelisted
EV.validate('[email protected]');
// => {
//      result: false,
//      errorCode: 'domain',
//      errorInfo: 'unknown.domain'
//    }

// domain whitelisted (from build-in wl), but dots in name
EV.validate('[email protected]');
// => {
//      result: false,
//      errorCode: 'dots',
//      errorInfo: 'Dots count: 4'
//    }

Methods

validate (email: string): string

Checks for |Name|Condition|errorCode| |--|--|--| |subdomain|allowSubdomain === false && checkSubDomain === true|subdomain| |dots|checkDots => 1 && allowDots === false|dots| |tag|checkTags.length && allowTags === false|tag| |whitelist|domains.length && domains.includes|domain| |main regex|regex.test|regex|

success return true or {result: true, errorCode: 'ok', errorInfo: ''} if details enabled

Example:

EV.validate('[email protected]');
// => true

EV.validate('[email protected]'); // with build-in whitelist + details
// => {
//      result: false,
//      errorCode: 'domain',
//      errorInfo: 'aa.aa'
//    }

compare (email1: string, email2: string, strict = true): boolean

Compares two emails with considering instance params. Params can be ignored by passing false as third param

Example:

EV.compare('[email protected]', '[email protected]');
// => false

EV.compare('[email protected]', '[email protected]', false);
// => true

clear (email: string, strict = true): string

Clears email with considering instance params. Params can be ignored by passing false as third param

Example

// allowDots: false
EV.clear('[email protected]');
// => [email protected]

// allowTags: false
EV.clear('[email protected]');
// => [email protected]

EV.clear('[email protected]', false);
// => [email protected]

getDomain (email: string): string

Returns domain from email address

Example:

EV.getDomain('[email protected]');
// => gmail.com

checkSubDomain (email: string): boolean

Returns true if email domain contains subdomain

Example:

EV.getDomain('[email protected]');
// => false

EV.getDomain('[email protected]');
// => true

checkDots (email: string): number

Returns number of dots in name Example:

EV.getDomain('[email protected]');
// => 0

EV.getDomain('[email protected]');
// => 2

checkTags (email: string): string

Returns first found tag in name or empty string if nothing found

Example:

EV.getDomain('[email protected]');
// => ''

// with default settings
EV.getDomain('[email protected]');
// => '+'

// tagSymbols: [ '-', '+' ]
EV.getDomain('[email protected]');
// => '-'
// first match only

removeDots (email: string): string

Returns cleared email from dots Example:

EV.removeDots('[email protected]');
// => '[email protected]'

removeTag (email: string): string

Returns cleared email from tags Example:

EV.removeDots('[email protected]');
// => '[email protected]'

// tagSymbols: [ '-', '+' ]
EV.removeDots('[email protected]');
// => '[email protected]'