import { Try, failure, success } from '@oats-ts/try' import { IssueTypes, ValidatorConfig } from '@oats-ts/validators' import { Primitive, ValueParser } from '../types' export const enumerationParser = (values: E[]): ValueParser => (value: T, name: string, path: string, config: ValidatorConfig): Try => { if (values.indexOf(value as E) < 0) { const valuesLiteral = values.map((v) => (typeof v === 'string' ? `"${v}"` : `${v}`)).join(',') return failure([ { message: `should be one of ${valuesLiteral}.`, path, severity: 'error', type: IssueTypes.value, }, ]) } return success(value as E) }