UNPKG

@yobta/validator

Version:
12 lines (11 loc) 342 B
import { rule } from '../rule/rule.js'; export const oneOfMessage = items => `It should be one of: ${items}`; export const oneOf = (items, message = oneOfMessage) => rule((input = '') => { if (items.has(input)) { return input; } if (input === '') { return undefined; } throw new Error(message(items)); });