/** * Toolkit - URL Validation * * URL validation and parsing utilities. */ /** * Validate URL format */ export function isValidUrl(url: string): boolean { try { new URL(url); return true; } catch { return false; } } /** * Ensure URL has protocol */ export function ensureProtocol(url: string, protocol = "https"): string { if (!/^https?:\/\//i.test(url)) { return `${protocol}://${url}`; } return url; } /** * Extract hostname from URL */ export function getHostname(url: string): string | null { try { const parsed = new URL(url); return parsed.hostname; } catch { return null; } }