« get me outta code hell

html: tweak attribute validators, actually enable singlet validator - 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-12-30 09:49:34 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-12-30 16:26:35 -0400
commit973a229843ef16f5056c69fc84d89ef5e0a6b49c (patch)
tree21e832b4c14abbdbf56e43cd655e78be6a788d1b /src
parent22e074bad12a25993c884b53f0d460a408efa814 (diff)
html: tweak attribute validators, actually enable singlet validator
Diffstat (limited to 'src')
-rw-r--r--src/util/html.js108
1 files changed, 54 insertions, 54 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 7ba49ae2..dd6c3b05 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -13,6 +13,7 @@ const {
   isNumber,
   isString,
   isSymbol,
+  looseArrayOf,
   oneOf,
   validateAllPropertyValues,
   validateArrayItems,
@@ -149,60 +150,6 @@ export const validators = {
   },
 };
 
-const isAttributeKey =
-  oneOf(isString, isSymbol);
-
-const isAttributeValue =
-  oneOf(isString, isNumber, isBoolean, isArray);
-
-const isAttributesAdditionPair = pair => {
-  isArray(pair);
-
-  if (pair.length !== 2) {
-    throw new TypeError(`Expected attributes pair to have two items`);
-  }
-
-  withAggregate(({push}) => {
-    try {
-      isAttributeKey(pair[0]);
-    } catch (caughtError) {
-      push(new Error(`Error validating key`, {cause: caughtError}));
-    }
-
-    try {
-      isAttributeValue(pair[1]);
-    } catch (caughtError) {
-      push(new Error(`Error validating value`, {cause: caughtError}));
-    }
-  });
-
-  return true;
-};
-
-const isAttributesAdditionSingletValue = value =>
-  oneOf(
-    validators.isTemplate,
-    validateAllPropertyValues(isAttributeValue),
-    validateArrayItems(
-      oneOf(
-        is(null, undefined, false),
-        isAttributesAdditionSingletValue)));
-
-const isAttributesAdditionSinglet = singlet => {
-  isArray(singlet);
-
-  if (singlet.length !== 1) {
-    throw new TypeError(`Expected attributes singlet to have one item`);
-  }
-
-  isAttributesAdditionSingletValue(singlet[0]);
-
-  return true;
-}
-
-const isAttributesAddition =
-  oneOf(isAttributesAdditionSinglet, isAttributesAdditionPair);
-
 export function blank() {
   return [];
 }
@@ -1396,3 +1343,56 @@ export const isHTML =
     },
 
     isArrayOfHTML);
+
+export const isAttributeKey =
+  oneOf(isString, isSymbol);
+
+export const isAttributeValue =
+  oneOf(
+    isString, isNumber, isBoolean, isArray,
+    isTag, isTemplate);
+
+export const isAttributesAdditionPair = pair => {
+  isArray(pair);
+
+  if (pair.length !== 2) {
+    throw new TypeError(`Expected attributes pair to have two items`);
+  }
+
+  withAggregate(({push}) => {
+    try {
+      isAttributeKey(pair[0]);
+    } catch (caughtError) {
+      push(new Error(`Error validating key`, {cause: caughtError}));
+    }
+
+    try {
+      isAttributeValue(pair[1]);
+    } catch (caughtError) {
+      push(new Error(`Error validating value`, {cause: caughtError}));
+    }
+  });
+
+  return true;
+};
+
+export const isAttributesAdditionSingletValue =
+  oneOf(
+    validateInstanceOf(Template),
+    validateAllPropertyValues(isAttributeValue),
+    looseArrayOf(value => isAttributesAdditionSingletValue(value)));
+
+export const isAttributesAdditionSinglet = singlet => {
+  isArray(singlet);
+
+  if (singlet.length !== 1) {
+    throw new TypeError(`Expected attributes singlet to have one item`);
+  }
+
+  isAttributesAdditionSingletValue(singlet[0]);
+
+  return true;
+}
+
+export const isAttributesAddition =
+  oneOf(isAttributesAdditionSinglet, isAttributesAdditionPair);