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

URL Classification Tool

Build a URL classification tool that analyzes website URLs to determine their top-level domain (TLD) type and categorize them for reporting purposes.

Requirements

Your tool should process a list of URLs and extract their public suffixes (TLDs) to generate classification reports.

Core Functionality

Implement a URL classifier that:

  1. Extracts the public suffix (TLD) from each URL
  2. Determines whether each TLD is an official ICANN TLD or a private suffix
  3. Groups URLs by their TLD type
  4. Generates a summary report showing the count of URLs for each unique TLD

Input

Your function should accept an array of URL strings. URLs may include:

  • Standard web URLs (http://, https://)
  • URLs with subdomains
  • URLs with various TLD types (single-level like .com, multi-level like .co.uk)
  • URLs pointing to cloud service domains (e.g., AWS S3, GitHub Pages)

Output

Return an object with the following structure:

  • icannTlds: An object mapping ICANN TLD names to their counts
  • privateTlds: An object mapping private suffix names to their counts
  • unclassified: An array of URLs that could not be classified

Edge Cases

Handle the following scenarios:

  • Invalid URLs or hostnames should be added to the unclassified array
  • IP addresses should be added to the unclassified array
  • URLs without recognizable TLDs should be handled gracefully

Implementation

@generates

API

/**
 * Classifies URLs by their public suffix (TLD) type.
 *
 * @param {string[]} urls - Array of URLs to classify
 * @returns {Object} Classification results with icannTlds, privateTlds, and unclassified
 */
function classifyUrls(urls) {
  // IMPLEMENTATION HERE
}

module.exports = { classifyUrls };

Test Cases

  • Given an array of standard .com and .org domains, it correctly extracts and counts ICANN TLDs @test
  • Given URLs with multi-level TLDs like .co.uk and .gov.au, it correctly identifies them as ICANN TLDs @test
  • Given URLs with private suffixes like s3.amazonaws.com and github.io, it correctly categorizes them as private TLDs @test
  • Given an array containing IP addresses, it adds them to the unclassified array @test

Dependencies { .dependencies }

tldts { .dependency }

Provides URL parsing and public suffix extraction capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-tldts

tile.json