2025-10-03 14:26:55 +09:00
|
|
|
/**
|
2025-10-08 18:14:12 +09:00
|
|
|
* Toolkit - URL Utilities
|
2025-10-03 14:26:55 +09:00
|
|
|
*
|
2025-10-08 18:14:12 +09:00
|
|
|
* URL parsing and manipulation utilities.
|
|
|
|
|
* For URL validation, use functions from common/validation.ts
|
2025-10-03 14:26:55 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|