« get me outta code hell

data: split arrayOf validator into {strict,sparse}ArrayOf - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-07-15 19:46:30 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-15 19:46:30 -0300
commit537448501439aaa68485e2ac436941656d7250e8 (patch)
tree11bf102a859acf326a8b9d66192c8e4898f7c331 /src/data/things
parentb493cc4b426910ecfa662f904bc0e01fee236c7a (diff)
data: split arrayOf validator into {strict,sparse}ArrayOf
Diffstat (limited to 'src/data/things')
-rw-r--r--src/data/things/validators.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/data/things/validators.js b/src/data/things/validators.js
index 14092102..1754adf3 100644
--- a/src/data/things/validators.js
+++ b/src/data/things/validators.js
@@ -195,10 +195,20 @@ export function validateArrayItems(itemValidator) {
   };
 }
 
-export function arrayOf(itemValidator) {
+export function strictArrayOf(itemValidator) {
   return validateArrayItems(itemValidator);
 }
 
+export function sparseArrayOf(itemValidator) {
+  return validateArrayItems(item => {
+    if (item === false || item === null) {
+      return true;
+    }
+
+    return itemValidator(item);
+  });
+}
+
 export function validateInstanceOf(constructor) {
   return (object) => isInstance(object, constructor);
 }