UNPKG

domain-info-fetcher

Version:

A powerful TypeScript/JavaScript tool for comprehensive domain analysis, featuring detailed WHOIS data with registration dates, registrars, and domain status. Offers SSL certificate extraction (with PEM support), DNS records, and server details. Includes

56 lines (55 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatDomain = formatDomain; exports.extractSubdomain = extractSubdomain; exports.getRootDomain = getRootDomain; exports.checkDomain = checkDomain; exports.dateToTimestamp = dateToTimestamp; /** * Formats a given domain to `example.com` format. * - Strips protocol and leading www * - Removes trailing slash * - Lowercases the domain */ function formatDomain(domain) { return domain .replace(/^(https?:\/\/)?(www\.)?/i, "") .replace(/\/$/, "") .toLowerCase(); } /** * Extracts the subdomain from a given domain. * Returns null if no subdomain is present. */ function extractSubdomain(domain) { const formattedDomain = formatDomain(domain); const parts = formattedDomain.split("."); if (parts.length > 2) { return parts[0]; } return null; } /** * Gets the root domain (e.g., example.com) from a domain that may include a subdomain. */ function getRootDomain(domain) { const formattedDomain = formatDomain(domain); const parts = formattedDomain.split("."); if (parts.length > 2) { return parts.slice(-2).join("."); } return formattedDomain; } /** * Checks if the given domain is valid. */ function checkDomain(domain) { const domainParts = domain.split("."); return domainParts.length > 1 && domainParts[0].length > 0; } /** * Converts a date string to a timestamp. */ function dateToTimestamp(dateString) { return new Date(dateString).getTime(); }