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}293031323334export function getSecurityOriginDisplay(url: string): string {35 try {36 return new URL(url).origin;37 } catch {38 return url;39 }40}4142434445464748495051export function detectHomograph(url: string): boolean {52 try {53 const hostname = new URL(url.includes("://") ? url : `https://${url}`).hostname;54 return (55 56 /[^\x00-\x7F]/.test(hostname) ||57 hostname.split(".").some((l) => l.startsWith("xn--"))58 );59 } catch {60 return false;61 }62}