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

@jrc03c/email-validator

v0.0.5

Published

validates email addresses

Downloads

6

Readme

Installation

npm install --save https://github.com/jrc03c/email-validator

Usage

In Node:

const EmailValidator = require("@jrc03c/email-validator")

In the browser:

<script src="path/to/dist/email-validator.js"></script>

Then:

const validator = new EmailValidator()

validator.load().then(() => {
  const isValid = validator.validate("[email protected]")

  if (isValid) {
    // Yay!
  } else {
    // Uh-oh!
  }
})

By default, the top-level domain list is fetched from IANA. However, if you prefer, you can pass your own URL from which to fetch the list:

validator.load(myListUrl)

As I write this, the Fetch API has not yet been implemented in Node; so this library includes its own version written from scratch. My version definitely doesn't implement the full Fetch API; in fact, it's just useful enough to fetch a plain text file from a URL, and that's all. But I wrote it myself because I didn't want to rely on any third-party libraries. If for some reason you are working in Node and you need to fetch the top-level domain list using a more complicated request (e.g., a POST request, or a request that requires certain headers, etc.), or if you just don't just the way I've written my own fetch function, then you'll need to write your own version or import a library like node-fetch and then do your own fetching:

const EmailValidator = require("@jrc03c/email-validator")
const fetch = require("node-fetch")

fetch(myListUrl, myFancyOptions).then(response => {
  const myFancyList = await response.json()

  // parse the response to retrieve your list, and then:
  const validator = new EmailValidator()
  validator.topLevelDomainList = myFancyList

  const isValid = validator.validate("[email protected]")
  // ...
})

API

EmailValidator

There are no constructor arguments.

Properties

isReady

A read-only property that indicates whether or not a top-level domain list has been loaded into the validator.

topLevelDomainList

A list of top-level domains. (NOTE: I typically think of domains as something like "github.com". But "top-level domains" in this context refers to what I'd otherwise call the "extension" of the domain; i.e., the thing that comes at the end of the domain name, such as "com" in "github.com". So, this top-level domain list should be a list of all such domain name endings.)

Methods

load(url)

Returns a Promise that resolves once a list of top-level domains has been downloaded. Passing a URL into the method is optional. When passed, the top-level domain list will be fetched from the given URL rather than from the default IANA URL. This method is identical to fetchTopLevelDomainList.

fetchTopLevelDomainList(url)

Returns a Promise that resolves once a list of top-level domains has been downloaded. Passing a URL into the method is optional. When passed, the top-level domain list will be fetched from the given URL rather than from the default IANA URL. This method is identical to load.

isValid(email)

Returns a boolean indicating whether or not the given email address is valid. This method is identical to validate.

validate(email)

Returns a boolean indicating whether or not the given email address is valid. This method is identical to isValid.