overleaf-cep/services/web/frontend/js/shared/utils/url-helper.ts
Alf Eaton a8a61db23e Convert shared utils modules to TypeScript (#22665)
GitOrigin-RevId: de40a0aaba35336ec59499a047356b0b9d161b38
2025-01-14 09:04:50 +00:00

14 lines
379 B
TypeScript

export function buildUrlWithDetachRole(mode: string | null) {
return cleanURL(new URL(window.location.href), mode)
}
export function cleanURL(url: URL, mode: string | null) {
let cleanPathname = url.pathname
.replace(/\/(detached|detacher)\/?$/, '')
.replace(/\/$/, '')
if (mode) {
cleanPathname += `/${mode}`
}
url.pathname = cleanPathname
return url
}