url-helper.ts 379 B

1234567891011121314
  1. export function buildUrlWithDetachRole(mode: string | null) {
  2. return cleanURL(new URL(window.location.href), mode)
  3. }
  4. export function cleanURL(url: URL, mode: string | null) {
  5. let cleanPathname = url.pathname
  6. .replace(/\/(detached|detacher)\/?$/, '')
  7. .replace(/\/$/, '')
  8. if (mode) {
  9. cleanPathname += `/${mode}`
  10. }
  11. url.pathname = cleanPathname
  12. return url
  13. }