UNPKG

@vitruvius-labs/ts-predicate

Version:
20 lines (19 loc) 641 B
import { itemAssertion } from "./utils/item-assertion.mjs"; import { ValidationError } from "./utils/validation-error.mjs"; import { rethrowUnexpectedError } from "../utils/rethrow-unexpected-error.mjs"; function assertUnion(value, tests) { const errors = []; for (const test of tests) { try { itemAssertion(value, test); } catch (error) { rethrowUnexpectedError(error); errors.push(error); } } if (errors.length === tests.length) { throw new ValidationError("The value does not pass any of the assertion.", errors); } } export { assertUnion };