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

URL Subdomain Analyzer

Build a URL subdomain analyzer that processes a list of URLs and extracts subdomain information from each one.

Requirements

Your analyzer should:

  1. Accept a list of URLs or hostnames as input
  2. Extract the subdomain from each URL/hostname
  3. Return a structured result containing:
    • The original URL/hostname
    • The extracted subdomain (empty string if no subdomain exists)
    • A flag indicating if the input was valid
  4. Handle various URL formats including:
    • Full URLs with protocols (http://, https://)
    • Plain hostnames without protocols
    • URLs with paths, query strings, and fragments
    • Multi-level subdomains (e.g., "a.b.c.example.com")

Test Cases

  • Given URL "https://www.google.com", the subdomain should be "www" @test
  • Given hostname "fr.google.com", the subdomain should be "fr" @test
  • Given URL "https://api.staging.example.co.uk/path", the subdomain should be "api.staging" @test
  • Given URL "https://example.com", the subdomain should be "" (empty string) @test
  • Given an array of URLs ["https://www.example.com", "blog.example.org", "https://example.net"], it should return an array with subdomains ["www", "blog", ""] @test

Implementation

@generates

API

/**
 * Analyzes a single URL or hostname and extracts subdomain information
 *
 * @param {string} url - The URL or hostname to analyze
 * @returns {Object} Analysis result with { url, subdomain, isValid }
 */
function analyzeSubdomain(url) {
  // IMPLEMENTATION HERE
}

/**
 * Analyzes multiple URLs or hostnames and extracts subdomain information
 *
 * @param {string[]} urls - Array of URLs or hostnames to analyze
 * @returns {Object[]} Array of analysis results
 */
function analyzeSubdomains(urls) {
  // IMPLEMENTATION HERE
}

module.exports = {
  analyzeSubdomain,
  analyzeSubdomains,
};

Dependencies { .dependencies }

tldts { .dependency }

Provides URL parsing and subdomain extraction capabilities.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-tldts

tile.json