30 lines
547 B
TypeScript
Raw Normal View History

/**
* Toolkit - URL Utilities
*
* URL parsing and manipulation utilities.
* For URL validation, use functions from common/validation.ts
*/
/**
* 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;
}
}