Socket
Socket
Sign inDemoInstall

@jrc03c/email-validator

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @jrc03c/email-validator

validates email addresses


Version published
Weekly downloads
2
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Install

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

Use

In Node:

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

In the browser:

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

Then:

emailValidator.fetchTopLevelDomainList().then(() => {
  const isValid = emailValidator.validate("someone@example.com")

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

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

emailValidator.fetchTopLevelDomainList(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 => {
  // parse the response to retrieve your list, and then:
  emailValidator.topLevelDomainList = myFancyList

  const isValid = emailValidator.validate("someone@example.com")
  // ...
})

FAQs

Last updated on 13 May 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc