validateArray()function

validateArray(unsafeArray: PossibleArray<unknown>, validator: Validator<T>): ImmutableArray<T>
ParamType
unsafeArrayPossibleArray<unknown>
The array (or iterable) of potentially invalid items. required
validatorValidator<T>
The validator to validate each item with. required
Return
ImmutableArray<T>
Array with valid items.
Throws
unknown
string if one or more items did not validate (one "index: message" line per failure, joined by newlines).

Validate an array of items with a validator.

  • Returns the original array reference unchanged when every item was already valid (and the input was an array).

Examples

validateArray(["a", "b"], STRING) // ["a", "b"]