Library to work against complex domain names, subdomains and URIs
82
Build a system to validate and analyze email addresses based on their domain information.
Create a module that processes email addresses and extracts domain-related information. The system should:
Your module should export a function analyzeEmail(email: string): EmailAnalysis | null that:
null if the email is invalid or uses an IP addressThe EmailAnalysis object should have the following structure:
interface EmailAnalysis {
domain: string | null; // The registrable domain (e.g., 'example.co.uk')
publicSuffix: string | null; // The TLD (e.g., 'co.uk')
subdomain: string | null; // The subdomain portion (e.g., 'mail')
domainWithoutSuffix: string | null; // Domain name only (e.g., 'example')
isValidDomain: boolean; // true if domain is valid, false if IP
}user@example.com, the analyzer returns domain example.com, publicSuffix com, subdomain empty string, domainWithoutSuffix example, and isValidDomain true @testadmin@mail.google.co.uk, the analyzer returns domain google.co.uk, publicSuffix co.uk, subdomain mail, domainWithoutSuffix google, and isValidDomain true @testuser@192.168.1.1, the analyzer returns null because IP addresses are not valid domains @testPelé@example.com, the analyzer correctly extracts domain information @test@generates
/**
* Analyzes an email address and extracts domain information.
*
* @param {string} email - The email address to analyze
* @returns {EmailAnalysis | null} Domain analysis or null if invalid
*/
function analyzeEmail(email) {
// IMPLEMENTATION HERE
}
module.exports = { analyzeEmail };Provides URL and domain parsing capabilities including email domain extraction.
Install with Tessl CLI
npx tessl i tessl/npm-tldtsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10