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

saksh-email-validator

v2.1.2

Published

A comprehensive email validation module with syntax, domain, blacklist, and SMTP checks.

Downloads

29

Readme

Email Validation Module Overview

This Email Validation Module provides a comprehensive solution for validating email addresses. It includes various features such as syntax validation, domain checks, blacklist checks, disposable email detection, role-based email detection, and SMTP server validation. Additionally, it supports custom validation rules and offers suggestions for correcting common email syntax errors.

Saksh Email Validator Banner

Key Features

Syntax Validation

  • Validates the syntax of an email address using a regular expression.
  • Provides suggestions for correcting common syntax errors.

Domain Checks

  • Checks if the domain of an email address has MX (Mail Exchange) records.
  • Skips SMTP validation for blacklisted domains.

Blacklist Checks

  • Checks if the domain of an email address is blacklisted.
  • Supports custom blacklisted domains.

Disposable Email Detection

  • Detects if an email address is from a disposable email provider.
  • Supports custom disposable domains.

Role-Based Email Detection

  • Detects if an email address is role-based (e.g., [email protected]).
  • Supports custom role-based emails.

SMTP Server Validation

  • Validates the SMTP server for the email domain.
  • Supports custom SMTP ports, connection timeout, and retry settings.

Custom Validation Rules

  • Allows adding custom validation rules to extend the validation logic.

International Email Normalization

  • Normalizes international email addresses to ASCII format using the punycode module.

Example Usage

Here’s an example of how to use the email validation module:

const {
    sakshValidateEmail,
    sakshValidateEmailBatch,
    sakshCache,
    sakshAddCustomValidationRule
} = require('saksh-email-validator');

// Custom validation rule 1: Disallow emails containing "test"
function customRule1(email) {
    return {
        valid: !email.includes('test'),
        reason: 'Emails containing "test" are not allowed.',
        priority: 1 // Higher priority
    };
}

// Custom validation rule 2: Disallow emails from "example.com"
function customRule2(email) {
    const domain = email.split('@')[1];
    return {
        valid: domain !== 'example.com',
        reason: 'Emails from "example.com" are not allowed.',
        priority: 2 // Lower priority
    };
}

// Example email addresses to test
const emails = [
    '[email protected]',
    '[email protected]',
    '[email protected]',
    '[email protected]',
    '[email protected]',
    '[email protected]',
    '[email protected]'
];

// Configuration object
const config = {
    validateMx: true,
    validateSmtp: true,
    blacklistedDomains: [],
    disposableDomains: [],
    roleBasedEmails: [],
    wellKnownDomains: ['sakshamapp.com'],
    customValidationRules: [customRule1, customRule2]
};

// Test the email validation function
async function testEmailValidation() {
    for (const email of emails) {
        const result = await sakshValidateEmail(email, config);
        console.log(`Validation result for ${email}:`, result);
    }
}

testEmailValidation();

function clearCache() {
    sakshCache.flushAll();
    console.log('Cache cleared.');
}

// clearCache()

Detailed Function Descriptions

  • sakshValidateEmailSyntax(email)

    • Description: Validates the syntax of an email address using a regular expression.
    • Parameters: email (string) - The email address to validate.
    • Returns: boolean - Returns true if the email syntax is valid, false otherwise.
  • sakshEmailSyntaxSuggestions(email)

    • Description: Provides suggestions for correcting common email syntax errors.
    • Parameters: email (string) - The email address to suggest corrections for.
    • Returns: string[] - Returns an array of suggested email formats.
  • sakshCheckDomainMXRecords(email)

    • Description: Checks if the domain of an email address has MX records.
    • Parameters: email (string) - The email address to check.
    • Returns: Promise - Resolves to true if the domain has MX records, false otherwise.
  • sakshIsDomainBlacklisted(email, customBlacklistedDomains = [])

    • Description: Checks if the domain of an email address is blacklisted.
    • Parameters:
      • email (string) - The email address to check.
      • customBlacklistedDomains (string[]) - Custom blacklisted domains.
    • Returns: boolean - Returns true if the domain is blacklisted,

Conclusion

This email validation module offers a robust set of features to ensure the validity of email addresses. It is highly configurable and can be extended with custom validation rules to meet specific requirements. The module also provides helpful suggestions for correcting common email errors, making it a comprehensive solution for email validation needs.

Support

susheel2339 at gmail.com