(...parts: string[])
| 95 | * ``` |
| 96 | */ |
| 97 | export function joinUrlParts(...parts: string[]): string { |
| 98 | const normalizedParts: string[] = []; |
| 99 | |
| 100 | for (const part of parts) { |
| 101 | if (part === '') { |
| 102 | // Skip any empty parts |
| 103 | continue; |
| 104 | } |
| 105 | |
| 106 | let start = 0; |
| 107 | let end = part.length; |
| 108 | |
| 109 | // Use "Pointers" to avoid intermediate slices |
| 110 | while (start < end && part[start] === '/') { |
| 111 | start++; |
| 112 | } |
| 113 | |
| 114 | while (end > start && part[end - 1] === '/') { |
| 115 | end--; |
| 116 | } |
| 117 | |
| 118 | if (start < end) { |
| 119 | normalizedParts.push(part.slice(start, end)); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | return addLeadingSlash(normalizedParts.join('/')); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Strips `/index.html` from the end of a URL's path, if present. |
no test coverage detected