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

    Class VineArray<Schema>

    VineArray represents an array schema type in the validation pipeline. It validates arrays and their elements using a nested schema, with support for length constraints, uniqueness checks, and element filtering.

    const schema = vine.array(vine.string().email())
    .minLength(1)
    .maxLength(10)
    .distinct()

    const result = await vine.validate({
    schema,
    data: ['user1@example.com', 'user2@example.com']
    })

    Type Parameters

    • Schema extends SchemaTypes

      The schema type for validating array elements

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    rules: {
        compact: (...options: [options?: undefined]) => Validation<undefined>;
        notEmpty: (...options: [options?: undefined]) => Validation<undefined>;
        distinct: (
            ...options: [options: { fields?: string | string[] }],
        ) => Validation<{ fields?: string | string[] }>;
        minLength: (
            ...options: [options: { min: number }],
        ) => Validation<{ min: number }>;
        maxLength: (
            ...options: [options: { max: number }],
        ) => Validation<{ max: number }>;
        fixedLength: (
            ...options: [options: { size: number }],
        ) => Validation<{ size: number }>;
    } = ...

    Static collection of all available validation rules for arrays

    "[UNIQUE_NAME]": string = 'vine.array'

    Unique name identifier for union type resolution

    "[ITYPE]": Schema[typeof ITYPE][]

    Define the input type of the schema for TypeScript inference

    "[OTYPE]": Schema[typeof OTYPE][]

    The output value type of the field after validation. The property points to a type only and not the real value.

    "[COTYPE]": Schema[typeof COTYPE][]

    Type marker for camelCase output type inference

    Methods

    • Type checker function to determine if a value is an array. Required for "unionOfTypes" functionality.

      Parameters

      • value: unknown

        The value to check

      Returns value is any[]

      True if the value is an array

    • Ensure array elements are distinct/unique.

      Parameters

      • Optionalfields: string | string[]

        Optional field names to check for uniqueness in object arrays

      Returns VineArray<Schema>

      This array schema instance for method chaining

    • Clones the VineArray schema type. The applied options and validations are copied to the new instance.

      Returns this

      A cloned instance of this VineArray schema

    • Compiles to array data type for the validation compiler.

      Parameters

      • propertyName: string

        Name of the property being compiled

      • refs: RefsStore

        Reference store for the compiler

      • options: ParserOptions

        Parser options

      Returns ArrayNode

      Compiled array node for validation

    • Define a method to parse the input value. The method is invoked before any validation and hence you must perform type-checking to know the value you are working with.

      Parameters

      • callback: ParseFn

        Parser function to transform the input value

      Returns this

      This schema instance for method chaining

      vine.string().parse((value) => {
      return typeof value === 'string' ? value.trim() : value
      })