(base: string, path: string)
| 2 | |
| 3 | // Joins a base URL and a path, collapsing/inserting a single slash at the seam. |
| 4 | export function joinURL(base: string, path: string): string { |
| 5 | if (base === '' || base === '/') |
| 6 | return path === '' ? '/' : path |
| 7 | if (path === '' || path === '/') |
| 8 | return base |
| 9 | |
| 10 | const baseHasTrailing = base.endsWith('/') |
| 11 | const pathHasLeading = path.startsWith('/') |
| 12 | |
| 13 | if (baseHasTrailing && pathHasLeading) |
| 14 | return base + path.slice(1) |
| 15 | if (!baseHasTrailing && !pathHasLeading) |
| 16 | return `${base}/${path}` |
| 17 | return base + path |
| 18 | } |
| 19 | |
| 20 | // Only `undefined` is treated as "absent". Empty strings, 0, and false coerce |
| 21 | // through `String(...)` and land on the wire — e.g. `{ name: '' }` becomes |
no test coverage detected