Function validateIf

  • Validate an input given a condition

    Type Parameters

    • T

      The validated type

    Parameters

    • condition: boolean

      The validation condition

    • input: unknown

      The raw input

    • parsed: unknown

      The parsed input

    • reason: string

      The failure message

    Returns Validated<T>

    Example

    validateIf(true, "1", 1, "Not a number") >>
    {
    valid: true,
    input: "1",
    parsed: 1,
    error: null,
    };