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

URL Classifier Service

Build a URL classification service that processes a list of URLs and categorizes them by their domain characteristics.

@generates

Requirements

The service should process an array of URL strings and return classification results for each URL. For each URL, extract and provide:

  1. The full domain name
  2. The subdomain (if any)
  3. The top-level domain (public suffix)
  4. Whether the URL points to an IP address
  5. The hostname

The service should handle various URL formats including:

  • Standard HTTP/HTTPS URLs
  • URLs with ports and paths
  • URLs with authentication credentials
  • Email addresses
  • IPv4 and IPv6 addresses
  • Multi-level subdomains

Test Cases

  • Given "https://api.example.com/users", returns domain "example.com", subdomain "api", public suffix "com", hostname "api.example.com", isIp false @test
  • Given "https://secure.shop.example.co.uk:8080/cart", returns domain "example.co.uk", subdomain "secure.shop", public suffix "co.uk", hostname "secure.shop.example.co.uk", isIp false @test
  • Given "https://192.168.1.1/admin", returns null domain, no subdomain, no public suffix, hostname "192.168.1.1", isIp true @test
  • Given "user@company.org", returns domain "company.org", no subdomain, public suffix "org", hostname "company.org", isIp false @test

API

/**
 * Classification result for a single URL
 */
export interface UrlClassification {
  /** Original URL that was classified */
  url: string;
  /** Full domain name (e.g., "example.com") */
  domain: string | null;
  /** Subdomain portion (e.g., "api" from "api.example.com") */
  subdomain: string | null;
  /** Public suffix/TLD (e.g., "com", "co.uk") */
  publicSuffix: string | null;
  /** Extracted hostname */
  hostname: string | null;
  /** Whether the URL is an IP address */
  isIp: boolean;
}

/**
 * Classifies a list of URLs by extracting domain information
 * @param urls - Array of URL strings to classify
 * @returns Array of classification results
 */
export function classifyUrls(urls: string[]): UrlClassification[];

Dependencies { .dependencies }

tldts { .dependency }

Provides URL and hostname parsing capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-tldts

tile.json