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

Local Development Domain Parser

Build a hostname parser for a local development environment that supports custom internal domain names.

Requirements

Your parser should handle hostnames used in local development environments, such as localhost, internal, and custom company domains. It should correctly identify the domain and subdomain parts even when these hostnames don't appear in the standard public suffix list.

Implement a module that parses development hostnames and extracts:

  • The full hostname
  • The domain portion
  • The subdomain portion (if any)
  • The public suffix (if applicable)

The parser should support the following custom hostnames as valid domains:

  • localhost
  • internal
  • mycompany.local

Example behavior

Given api.localhost:

  • Hostname: api.localhost
  • Domain: localhost
  • Subdomain: api

Given admin.dashboard.internal:

  • Hostname: admin.dashboard.internal
  • Domain: internal
  • Subdomain: admin.dashboard

Given app.mycompany.local:

  • Hostname: app.mycompany.local
  • Domain: mycompany.local
  • Subdomain: app

Given staging.api.mycompany.local:

  • Hostname: staging.api.mycompany.local
  • Domain: mycompany.local
  • Subdomain: staging.api

Implementation

@generates

API

/**
 * Parses a development hostname and extracts domain components.
 *
 * @param {string} hostname - The hostname to parse
 * @returns {object} Object containing:
 *   - hostname: the full hostname
 *   - domain: the registrable domain
 *   - subdomain: the subdomain portion (empty string if none)
 *   - publicSuffix: the public suffix (may be null for custom domains)
 */
function parseDevHostname(hostname) {
  // IMPLEMENTATION HERE
}

module.exports = { parseDevHostname };

Test Cases

  • It correctly parses api.localhost as domain localhost with subdomain api @test
  • It correctly parses admin.dashboard.internal as domain internal with subdomain admin.dashboard @test
  • It correctly parses app.mycompany.local as domain mycompany.local with subdomain app @test

Dependencies { .dependencies }

tldts { .dependency }

Provides URL and hostname parsing capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-tldts

tile.json