@vinejs/vine - v4.0.0-next.1
    Preparing search index...

    Type Alias Validator<Options>

    Validator: (
        value: unknown,
        options: Options,
        field: FieldContext,
    ) => any | Promise<any>

    Function signature for validation logic. Validators receive the current field value, runtime options, and field context, and either return a transformed value or throw an error for invalid input.

    Type Parameters

    • Options extends any

      The type of options passed to the validator

    Type Declaration

      • (value: unknown, options: Options, field: FieldContext): any | Promise<any>
      • Parameters

        • value: unknown

          The current value being validated

        • options: Options

          Configuration options for the validation

        • field: FieldContext

          Context information about the field being validated

        Returns any | Promise<any>

        The validated/transformed value or a Promise resolving to it

    Should throw an error if validation fails

    const minLengthValidator: Validator<{ length: number }> = (
    value,
    { length },
    field
    ) => {
    if (typeof value === 'string' && value.length >= length) {
    return value
    }
    throw new Error(`Minimum length is ${length}`)
    }