| 1 | export function appendPathToUrlIfNotPresent( |
| 2 | urlString: string, |
| 3 | pathWithoutSlash: string, |
| 4 | ) { |
| 5 | const url = new URL(urlString); |
| 6 | if (!url.pathname.endsWith("/")) { |
| 7 | url.pathname += "/"; |
| 8 | } |
| 9 | if (!url.pathname.endsWith(pathWithoutSlash + "/")) { |
| 10 | url.pathname += pathWithoutSlash + "/"; |
| 11 | } |
| 12 | if (url.search) { |
| 13 | return url.toString(); |
| 14 | } |
| 15 | // append slash at the end |
| 16 | return url.toString(); |
| 17 | } |