aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/utils/url.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web_src/js/utils/url.ts')
-rw-r--r--web_src/js/utils/url.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/web_src/js/utils/url.ts b/web_src/js/utils/url.ts
new file mode 100644
index 0000000000..470ece31b0
--- /dev/null
+++ b/web_src/js/utils/url.ts
@@ -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;
+ }
+}