import { parse } from "tldts"; export default class ApexDomain { static getApexDomain(host: string, replace = true) { try { host = host.toLocaleLowerCase(); if (/((^localhost)|(\.localhost))$/.test(host)) { return { domain: host.split(".").slice(-2).join(".") }; } if(/^\d+\.\d+\.\d+\.\d+$/.test(host)) { return { domain: null }; } const { domain, subdomain } = parse(host); return { domain, subdomain }; } catch (error) { console.error(`Failed to get apex domain for ${host}`); return { domain: null }; } } }