« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/util/html.js37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/util/html.js b/src/util/html.js
index edc210b0..174a515d 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -7,6 +7,10 @@ import {empty, typeAppearance} from '#sugar';
 import * as commonValidators from '#validators';
 
 const {
+  is,
+  isArray,
+  isString,
+  oneOf,
   validateArrayItems,
   validateInstanceOf,
 } = commonValidators;
@@ -1213,26 +1217,19 @@ export const isTag =
 export const isTemplate =
   validateInstanceOf(Template);
 
-export function isHTML(value) {
-  if (typeof value === 'string') {
-    return true;
-  }
-
-  if (value === null || value === undefined || value === false) {
-    return true;
-  }
-
-  if (isBlank(value) || value instanceof Tag || value instanceof Template) {
-    return true;
-  }
+export const isArrayOfHTML =
+  validateArrayItems(value => isHTML(value));
 
-  if (isArrayOfHTML(value)) {
-    return true;
-  }
+export const isHTML =
+  oneOf(
+    is(null, undefined, false),
+    isString,
+    isTag,
+    isTemplate,
 
-  throw new TypeError(
-    `Expected html (tag, template, or blank), got ${typeAppearance(value)}`);
-}
+    value => {
+      isArray(value);
+      return value.length === 0;
+    },
 
-export const isArrayOfHTML =
-  validateArrayItems(isHTML);
+    isArrayOfHTML);