1import { getDomain } from "tldts";234567export function extractDomain(url: string): string | null {8 try {9 const normalized = url.startsWith("http") ? url : "https://" + url;10 const parsed = getDomain(normalized);11 return parsed ?? null;12 } catch {13 return null;14 }15}1617181920export function getDisplayDomain(url: string): string {21 try {22 const normalized = url.startsWith("http") ? url : "https://" + url;23 const { hostname } = new URL(normalized);24 return hostname;25 } catch {26 return url;27 }28}2930313233343536373839export function detectHomograph(url: string): boolean {40 try {41 const hostname = new URL(url.includes("://") ? url : `https://${url}`).hostname;42 return (43 44 /[^\x00-\x7F]/.test(hostname) ||45 hostname.split(".").some((l) => l.startsWith("xn--"))46 );47 } catch {48 return false;49 }50}