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-1/

Domain Suffix Analyzer

Build a utility that analyzes domain names to extract their public suffix and registrable domain, using domain parsing rules.

Background

Domain names are structured hierarchically with public suffixes (like com, co.uk) that indicate where domains can be registered. Different domains have different suffix structures:

  • Simple: example.com has suffix com
  • Multi-level: example.co.uk has suffix co.uk
  • Complex regions: Some regions use patterns where many subdomains are valid suffixes

Requirements

Create a utility that:

  1. Takes a domain name (hostname) as input

  2. Identifies the public suffix (the "TLD" part where domains can be registered)

  3. Extracts the registrable domain (the suffix plus one additional label to the left)

  4. Handles multi-level public suffixes correctly (like co.uk, gov.au)

  5. Returns structured information about the domain including:

    • The full hostname
    • The public suffix
    • The registrable domain
    • The subdomain (everything before the registrable domain)

Example Behavior

Your utility should handle these cases correctly:

InputPublic SuffixRegistrable DomainSubdomain
example.comcomexample.com(empty)
www.example.comcomexample.comwww
api.www.example.comcomexample.comapi.www
example.co.ukco.ukexample.co.uk(empty)
www.example.co.ukco.ukexample.co.ukwww
blog.example.gov.augov.auexample.gov.aublog

The utility should use a reliable domain parsing library that understands the Public Suffix List (which contains rules for all valid public suffixes including wildcards and exceptions).

Implementation

@generates

Your implementation should correctly parse domains and extract the relevant components using proper domain parsing that respects the Public Suffix List rules (including wildcards and exceptions).

Tests

  • Parsing a simple single-level TLD domain (e.g., example.com) extracts correct suffix and registrable domain @test
  • Parsing a multi-level TLD domain (e.g., example.co.uk) extracts correct suffix and registrable domain @test
  • Extracting subdomain works correctly for domains with subdomains @test
  • Parsing works correctly for domains under wildcard rules in the Public Suffix List @test

API

/**
 * Result of parsing a domain name
 */
export interface DomainInfo {
  hostname: string;
  publicSuffix: string | null;
  domain: string | null; // The registrable domain
  subdomain: string | null;
}

/**
 * Parses a domain name and extracts its components
 * @param hostname - The domain name to parse
 * @returns Domain information including suffix, registrable domain, and subdomain
 */
export function parseDomain(hostname: string): DomainInfo;

Dependencies { .dependencies }

tldts { .dependency }

Provides domain parsing and Public Suffix List utilities.

Install with Tessl CLI

npx tessl i tessl/npm-tldts

tile.json