Skip to main content

oneOf

Creates a schema that matches only specified values.

const fishSchema = oneOf(['trout', 'catfish'])();
const fishValidator = validate(fishSchema);

// Returns 'trout'
const trout = fishValidator('trout');

// Throws ValidationError
const salmon = fishValidator('salmon');