email-validator-ultimate
Version:
Advanced email validator ultimate library for Node.js. Includes format checks, MX records, SMTP inbox validation, disposable email detection, and quality scoring. email validation email validator
32 lines (24 loc) • 793 B
text/typescript
export function getQualityScore(options: {
formatValid: boolean,
hasMX: boolean,
disposable: boolean,
generic: boolean,
catchAll: boolean,
smtpCheckResult: boolean
}): number {
let score = 100;
// Invalid format is a hard fail
if (!options.formatValid) return 0;
// MX record is critical
if (!options.hasMX) score -= 40;
// SMTP check failure is also significant
if (!options.smtpCheckResult) score -= 30;
// Disposable emails are very low quality
if (options.disposable) score -= 20;
// Generic role-based addresses (e.g., admin@, info@)
if (options.generic) score -= 10;
// Catch-all domains are less predictable
if (options.catchAll) score -= 5;
// Ensure score doesn't go below 0
return Math.max(0, score);
}