« get me outta code hell

validators: looseArrayOf - 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-12-30 08:56:26 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-12-30 16:26:34 -0400
commit7f39e10beee71ea0c45db3ff9b2f6d6ae383bd3b (patch)
tree31f8ea83f9d8cc726223c702fd73ae41d7994f4f /src/data/things
parentdc29162482b70a5ed9fe3c889a8fc29d001c8e80 (diff)
validators: looseArrayOf
Diffstat (limited to 'src/data/things')
-rw-r--r--src/data/things/validators.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/data/things/validators.js b/src/data/things/validators.js
index 27416bb2..d881aac2 100644
--- a/src/data/things/validators.js
+++ b/src/data/things/validators.js
@@ -262,6 +262,16 @@ export function sparseArrayOf(itemValidator) {
   });
 }
 
+export function looseArrayOf(itemValidator) {
+  return validateArrayItems((item, index, array) => {
+    if (item === false || item === null || item === undefined) {
+      return true;
+    }
+
+    return itemValidator(item, index, array);
+  });
+}
+
 export function validateInstanceOf(constructor) {
   const fn = (object) => isInstance(object, constructor);