summaryrefslogtreecommitdiffstats
path: root/web_src/js/utils/url.js
blob: 470ece31b0ed85cfc8bfc99d31b23f6dc60e9649 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export function pathEscapeSegments(s) {
  return s.split('/').map(encodeURIComponent).join('/');
}

function stripSlash(url) {
  return url.endsWith('/') ? url.slice(0, -1) : url;
}

export function isUrl(url) {
  try {
    return stripSlash((new URL(url).href)).trim() === stripSlash(url).trim();
  } catch {
    return false;
  }
}