« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/html.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/html.js')
-rw-r--r--src/html.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/html.js b/src/html.js
index 4cac9525..cde86a5c 100644
--- a/src/html.js
+++ b/src/html.js
@@ -296,6 +296,14 @@ export function isBlank(content) {
   return false;
 }
 
+export function ifelse(options) {
+  for (const option of options) {
+    if (!isBlank(option)) return option;
+  }
+
+  return blank();
+}
+
 export const validators = {
   isBlank(value) {
     if (!isBlank(value)) {
@@ -411,6 +419,37 @@ export function escape(string, {attribute = false} = {}) {
   return string;
 }
 
+export function permit(string, adjustment) {
+  if (typeof string === 'string') {
+    if (string.length) {
+      return new Tag(null, null, adjust(string, adjustment));
+    } else {
+      return blank();
+    }
+  } else if (string === null) {
+    return blank();
+  } else {
+    throw new TypeError(`expected string or null`);
+  }
+}
+
+export function adjust(string, {
+  inline = false,
+  strip = false,
+} = {}) {
+  // zalgo
+
+  if (inline || strip) {
+    string = string.replace(/<br\/?>/g, ' ');
+  }
+
+  if (strip) {
+    string = striptags(string);
+  }
+
+  return string;
+}
+
 export class Tag {
   #tagName = '';
   #content = null;