UNPKG

@vitruvius-labs/ts-predicate

Version:
12 lines (11 loc) 500 B
import { ValidationError } from "./_index.mjs"; function assertEnumValue(value, enum_values, enum_name) { // @ts-expect-error: [].includes() should not care about the type of the parameter. if (!enum_values.includes(value)) { if (enum_name !== undefined) { throw new ValidationError(`The value must be a ${enum_name}.`); } throw new ValidationError(`The value must be one of the following: ${enum_values.join(", ")}.`); } } export { assertEnumValue };