function assertPath(path: string): void { if (typeof path !== 'string') { throw new TypeError('Path must be a string. Received ' + JSON.stringify(path)); } } export function getServiceUrlWithRoute(serviceUrl: string, route: string): string { const url = new URL(serviceUrl); url.pathname = joinPath(url.pathname, route); return url.toString(); } export function joinPath(...paths: string[]): string { if (paths.length === 0) return '/'; return paths.reduce((acc, path) => { assertPath(path); const mappedPath = path.startsWith('/') ? path.slice(1) : path; const endsWithSlash = acc.endsWith('/'); return endsWithSlash ? `${acc}${mappedPath}` : `${acc}/${mappedPath}`; }, '/'); }