summaryrefslogtreecommitdiffstats
path: root/web_src/js/utils/url.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--web_src/js/utils/url.js15
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 0000000..470ece3
--- /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;
+ }
+}