diff options
Diffstat (limited to 'web_src/js/utils/url.js')
-rw-r--r-- | web_src/js/utils/url.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/web_src/js/utils/url.js b/web_src/js/utils/url.js new file mode 100644 index 00000000..470ece31 --- /dev/null +++ b/web_src/js/utils/url.js @@ -0,0 +1,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; + } +} |