From 7f39e10beee71ea0c45db3ff9b2f6d6ae383bd3b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 30 Dec 2023 08:56:26 -0400 Subject: validators: looseArrayOf --- src/data/things/validators.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/data/things') 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); -- cgit 1.3.0-6-gf8a5