« get me outta code hell

html: implement isHTML with oneOf - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-12-30 15:48:04 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-12-30 15:49:12 -0400
commit10c5021922013d4e6ce269d68290e57d476b2ed2 (patch)
treecfe0006f51ccd06a2bc7b75b5874fcd740e18bfc /src/util
parent42978bf0b5beebb3a49797d3d800a2c3e4b0c5e9 (diff)
html: implement isHTML with oneOf
Diffstat (limited to 'src/util')
-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);