« get me outta code hell

html: tags(), isBlank() - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-04-05 21:23:08 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-04-05 21:23:08 -0300
commitd2b8680d36d31e95840704cbc63116d1ff8b0c09 (patch)
tree0d6b9c52ceaf058e12fc6edf1ddbd0e870ecf6de /src
parent8afc6ec1b57d81d654c56956978ac01ed145c301 (diff)
html: tags(), isBlank()
Diffstat (limited to 'src')
-rw-r--r--src/util/html.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/util/html.js b/src/util/html.js
index be267003..4a0c08e7 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -42,6 +42,25 @@ export function blank() {
   return [];
 }
 
+// Note: This is only guaranteed to return true for blanks (as returned by
+// html.blank()) and false for Tags and Slots (regardless of contents or
+// other properties). Don't depend on this to match any other values.
+export function isBlank(value) {
+  if (value instanceof Tag) {
+    return false;
+  }
+
+  if (value instanceof Slot) {
+    return false;
+  }
+
+  if (!Array.isArray(value)) {
+    return false;
+  }
+
+  return value.length === 0;
+}
+
 export function tag(tagName, ...args) {
   let content;
   let attributes;
@@ -62,6 +81,10 @@ export function tag(tagName, ...args) {
   return new Tag(tagName, attributes, content);
 }
 
+export function tags(content) {
+  return new Tag(null, null, content);
+}
+
 export class Tag {
   #tagName = '';
   #content = null;
@@ -490,7 +513,6 @@ export class Slot {
     const lines = error.stack.split('\n');
     const index = lines.findIndex(line => line.includes(`at ${this.#stackIdentifier}`))
     const setTrace = this.template.getSlotTrace(this.slotName);
-    console.log('index:', index);
     lines.splice(
       index - 1, 2,
       `at Slot("${this.slotName}") (from ${this.#stackTrace})`,