validateItems()function

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

Validate an iterable set of items with a validator, yielding each valid item.

  • Validation messages for failing items are collected (keyed by index) and thrown together once iteration completes.

@yields Valid items.

Examples

Array.from(validateItems(["a", "b"], STRING)) // ["a", "b"]