CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tldts

Library to work against complex domain names, subdomains and URIs

82

1.03x
Overview
Eval results
Files

task.mdevals/scenario-5/

Email Domain Validator

Build a system to validate and analyze email addresses based on their domain information.

Requirements

Create a module that processes email addresses and extracts domain-related information. The system should:

  1. Extract the full registrable domain from email addresses
  2. Identify the public suffix (TLD) of the email domain
  3. Extract the subdomain portion from email domains
  4. Extract the domain name without its suffix
  5. Handle both standard ASCII email addresses and internationalized email addresses with Unicode characters
  6. Validate email addresses by checking if they have valid domains (not IP addresses)

Input and Output

Your module should export a function analyzeEmail(email: string): EmailAnalysis | null that:

  • Takes an email address as input
  • Returns an object with domain information, or null if the email is invalid or uses an IP address

The 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
}

Test Cases

  • Given the email user@example.com, the analyzer returns domain example.com, publicSuffix com, subdomain empty string, domainWithoutSuffix example, and isValidDomain true @test
  • Given the email admin@mail.google.co.uk, the analyzer returns domain google.co.uk, publicSuffix co.uk, subdomain mail, domainWithoutSuffix google, and isValidDomain true @test
  • Given the email user@192.168.1.1, the analyzer returns null because IP addresses are not valid domains @test
  • Given an internationalized email Pelé@example.com, the analyzer correctly extracts domain information @test

Implementation

@generates

API

/**
 * 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 };

Dependencies { .dependencies }

tldts { .dependency }

Provides URL and domain parsing capabilities including email domain extraction.

Install with Tessl CLI

npx tessl i tessl/npm-tldts

tile.json