import { error } from '../lib/result'; import { ValidationType, ValidatorOptions } from '../lib/types'; export let literal = ( value: A, opts?: ValidatorOptions ): ValidationType => ({ type: 'literal', examples: [value], name: opts?.name, description: opts?.description, validate: input => { if (input != value) { return error([ { code: 'invalid_literal', message: opts?.message ?? `Invalid input, expected ${value}, received ${input}`, received: input, expected: value } ]); } return { success: true, value }; } });