validateArray()function
validateArray(unsafeArray: PossibleArray<unknown>, validator: Validator<T>): ImmutableArray<T>
| Param | Type | |
|---|---|---|
unsafeArray | PossibleArray<unknown> | The array (or iterable) of potentially invalid items. required |
validator | Validator<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"]