« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-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);
 }