Library to work against complex domain names, subdomains and URIs
82
Build a hostname parser for a local development environment that supports custom internal domain names.
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 parser should support the following custom hostnames as valid domains:
localhostinternalmycompany.localGiven api.localhost:
api.localhostlocalhostapiGiven admin.dashboard.internal:
admin.dashboard.internalinternaladmin.dashboardGiven app.mycompany.local:
app.mycompany.localmycompany.localappGiven staging.api.mycompany.local:
staging.api.mycompany.localmycompany.localstaging.api@generates
/**
* 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 };api.localhost as domain localhost with subdomain api @testadmin.dashboard.internal as domain internal with subdomain admin.dashboard @testapp.mycompany.local as domain mycompany.local with subdomain app @testProvides URL and hostname parsing capabilities.
Install with Tessl CLI
npx tessl i tessl/npm-tldtsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10