Adds containsAll validator (#5279)

This commit is contained in:
rodrigobasilio2022 2025-07-30 11:07:12 -03:00 committed by GitHub
parent eede2945ae
commit 8643c868fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -227,6 +227,20 @@ validate.validators.contains = function (value, options, key) {
return key + 'must contain ' + testValue;
}
};
// Custom validator: containsAll
// Checks that all items in testValue are present in value
validate.validators.containsAll = function (value, options, key) {
const testValue = getTestValue(options);
if (!Array.isArray(value) || !Array.isArray(testValue)) {
return `${key} must be an array and test value must be an array.`;
}
const missing = testValue.filter(item => !value.includes(item));
if (missing.length > 0) {
return `${key} must contain all of: ${testValue.join(', ')}. Missing: ${missing.join(', ')}`;
}
};
/**
* @example
* value = 'Attenuation Corrected'