export const joinUrl = (baseUrl: string, pathOrUrl: string): string => { if (/^https?:\/\//i.test(pathOrUrl)) { return pathOrUrl; } const normalizedBase = baseUrl.replace(/\/+$/, ""); const normalizedPath = pathOrUrl.startsWith("/") ? pathOrUrl : `/${pathOrUrl}`; return `${normalizedBase}${normalizedPath}`; }; export const getBaseUrl = (absoluteUrl: string): string => { try { const url = new URL(absoluteUrl); return `${url.protocol}//${url.host}`; } catch { return absoluteUrl; } };