(url: string)
| 38 | * @returns The URL string, modified if needed. |
| 39 | */ |
| 40 | export function stripTrailingSlash(url: string): string { |
| 41 | // Find the index of the first occurrence of `#`, `?`, or the end of the string. |
| 42 | // This marks the start of the query string, fragment, or the end of the URL path. |
| 43 | const pathEndIdx = url.search(/#|\?|$/); |
| 44 | // Check if the character before `pathEndIdx` is a trailing slash. |
| 45 | // If it is, remove the trailing slash and return the modified URL. |
| 46 | // Otherwise, return the URL as is. |
| 47 | return url[pathEndIdx - 1] === '/' ? url.slice(0, pathEndIdx - 1) + url.slice(pathEndIdx) : url; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Normalizes URL parameters by prepending with `?` if needed. |
no test coverage detected
searching dependent graphs…