Function isOneOf

  • Validate an input is one of a list of options

    Type Parameters

    • T

      The validated type

    Parameters

    • options: readonly T[]

      The valid options

    Returns Validator<T>

    Example

    isOneOf([1, 2, 3])(1) >>
    {
    valid: true,
    parsed: 1,
    };

    isOneOf([1, 2, 3])(4) >>
    {
    valid: false,
    error: "Not one of [1, 2, 3]: 4",
    };