summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/patterns.js30
1 files changed, 28 insertions, 2 deletions
diff --git a/common/patterns.js b/common/patterns.js
index 1398961..6f5aa40 100644
--- a/common/patterns.js
+++ b/common/patterns.js
@@ -186,5 +186,31 @@ function* each_url_pattern(url)
}
#EXPORT each_url_pattern
-#EXPORT "https://hydrillabugs.koszko.org/projects/haketilo/wiki/URL_patterns" \
- AS patterns_doc_url
+const patterns_doc_url =
+ "https://hydrillabugs.koszko.org/projects/haketilo/wiki/URL_patterns";
+#EXPORT patterns_doc_url
+
+function reconstruct_url(deco)
+{
+ const domain = deco.domain.join(".");
+ const path = ["", ...deco.path].join("/");
+ const trail = deco.trailing_slash ? "/" : "";
+ return `${deco.proto}://${domain}${path}${trail}`;
+}
+#EXPORT reconstruct_url
+
+function validate_normalize_url_pattern(url_pattern)
+{
+ try {
+ return reconstruct_url(deconstruct_url(url_pattern));
+ } catch(e) {
+ const patterns_doc_link = document.createElement("a");
+ patterns_doc_link.href = patterns_doc_url;
+ patterns_doc_link.innerText = "here";
+ const msg = document.createElement("span");
+ msg.prepend(`'${url_pattern}' is not a valid URL pattern. See `,
+ patterns_doc_link, " for more details.");
+ throw msg;
+ }
+}
+#EXPORT validate_normalize_url_pattern