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

    Variable helpersConst

    helpers: {
        exists(value: any): boolean;
        isMissing(value: any): boolean;
        isTrue(value: any): boolean;
        isFalse(value: any): boolean;
        isString(value: unknown): value is string;
        isObject<Value>(value: unknown): value is Record<PropertyKey, Value>;
        hasKeys(value: Record<string, any>, keys: string[]): boolean;
        isArray<Value>(value: unknown): value is Value[];
        isNumeric(value: any): boolean;
        asNumber(value: any): number;
        asBoolean(value: any): boolean | null;
        asDayJS(
            value: any,
            format: OptionType | undefined,
        ): { dateTime: Dayjs; formats: string | string[] | FormatObject };
        compareValues(
            inputValue: unknown,
            expectedValue: any,
        ): { isEqual: boolean; casted: unknown };
        isEmail: (str: string, options?: IsEmailOptions) => boolean;
        isURL: (str: string, options?: IsURLOptions) => boolean;
        isAlpha: (
            str: string,
            locale?: AlphaLocale,
            options?: IsAlphaOptions,
        ) => boolean;
        isAlphaNumeric: (
            str: string,
            locale?: AlphanumericLocale,
            options?: IsAlphanumericOptions,
        ) => boolean;
        isIP: (str: string, version?: IPVersion) => boolean;
        isUUID: (str: string, version?: UUIDVersion) => boolean;
        isAscii: (str: string) => boolean;
        isCreditCard: (str: string, options?: IsCreditCardOptions) => boolean;
        isIBAN: (str: string, options?: IsIBANOptions) => boolean;
        isJWT: (str: string) => boolean;
        isLatLong: (str: string) => boolean;
        isMobilePhone: (
            str: string,
            locale?: MobilePhoneLocale | MobilePhoneLocale[] | "any",
            options?: IsMobilePhoneOptions,
        ) => boolean;
        isPassportNumber: (str: string, countryCode?: string) => boolean;
        isPostalCode: (str: string, locale: PostalCodeLocale | "any") => boolean;
        isSlug: (str: string) => boolean;
        isDecimal: (str: string, options?: IsDecimalOptions) => boolean;
        mobileLocales: MobilePhoneLocale[];
        postalCountryCodes: PostalCodeLocale[];
        passportCountryCodes: readonly [
            "AM",
            "AR",
            "AT",
            "AU",
            "AZ",
            "BE",
            "BG",
            "BR",
            "BY",
            "CA",
            "CH",
            "CY",
            "CZ",
            "DE",
            "DK",
            "DZ",
            "ES",
            "FI",
            "FR",
            "GB",
            "GR",
            "HR",
            "HU",
            "IE",
            "IN",
            "ID",
            "IR",
            "IS",
            "IT",
            "JM",
            "JP",
            "KR",
            "KZ",
            "LI",
            "LT",
            "LU",
            "LV",
            "LY",
            "MT",
            "MZ",
            "MY",
            "MX",
            "NL",
            "NZ",
            "PH",
            "PK",
            "PL",
            "PT",
            "RO",
            "RU",
            "SE",
            "SL",
            "SK",
            "TH",
            "TR",
            "UA",
            "US",
        ];
        isULID(value: unknown): boolean;
        isHexColor: (value: string) => boolean;
        isActiveURL: (url: string) => Promise<boolean>;
        isDistinct: (dataSet: any[], fields?: string | string[]) => boolean;
        getNestedValue(key: string, field: FieldContext): any;
    } = ...

    Collection of utility helpers used across the Vine validation library. These helpers provide type-checking, coercion, and validation functions that are optimized for HTML form data handling.

    Type Declaration

    • exists: function
      • Checks if a value exists (is not null and not undefined). Useful for checking if optional form fields have been provided.

        Parameters

        • value: any

          The value to check

        Returns boolean

        True if value is not null and not undefined

        helpers.exists('hello') // true
        helpers.exists(0) // true
        helpers.exists(null) // false
        helpers.exists(undefined) // false
    • isMissing: function
      • Checks if a value is missing (null or undefined). The inverse of the exists method.

        Parameters

        • value: any

          The value to check

        Returns boolean

        True if value is null or undefined

        helpers.isMissing(null) // true
        helpers.isMissing(undefined) // true
        helpers.isMissing('') // false
        helpers.isMissing(0) // false
    • isTrue: function
      • Checks if a value represents a truthy boolean in HTML form context. Recognizes common HTML form representations of true values.

        Accepted truthy values:

        • true (boolean)
        • 1 (number)
        • "1" (string)
        • "true" (string)
        • "on" (string, for checkboxes)

        Parameters

        • value: any

          The value to check

        Returns boolean

        True if value represents a truthy boolean

        helpers.isTrue(true) // true
        helpers.isTrue('on') // true (checkbox checked)
        helpers.isTrue('1') // true (form input)
        helpers.isTrue('yes') // false
    • isFalse: function
      • Checks if a value represents a falsy boolean in HTML form context. Recognizes common HTML form representations of false values.

        Accepted falsy values:

        • false (boolean)
        • 0 (number)
        • "0" (string)
        • "false" (string)

        Parameters

        • value: any

          The value to check

        Returns boolean

        True if value represents a falsy boolean

        helpers.isFalse(false) // true
        helpers.isFalse('0') // true (form input)
        helpers.isFalse('false') // true (form input)
        helpers.isFalse('no') // false
    • isString: function
      • Type guard that checks if a value is a string. Narrows the TypeScript type to string when returning true.

        Parameters

        • value: unknown

          The value to check

        Returns value is string

        True if value is a string, with type narrowing

        if (helpers.isString(value)) {
        // value is now typed as string
        console.log(value.toUpperCase())
        }
    • isObject: function
      • Type guard that checks if a value is a plain JavaScript object. Excludes null, arrays, and other non-plain objects.

        Type Parameters

        • Value

          The type of values in the object

        Parameters

        • value: unknown

          The value to check

        Returns value is Record<PropertyKey, Value>

        True if value is a plain object, with type narrowing

        helpers.isObject({}) // true
        helpers.isObject([]) // false
        helpers.isObject(null) // false
        helpers.isObject(new Date()) // true (but not recommended for validation)
    • hasKeys: function
      • Checks if an object contains all the specified keys. Useful for validating object structure before processing.

        Parameters

        • value: Record<string, any>

          The object to check

        • keys: string[]

          Array of key names that must exist

        Returns boolean

        True if all keys exist in the object

        helpers.hasKeys({ name: 'John', age: 30 }, ['name']) // true
        helpers.hasKeys({ name: 'John' }, ['name', 'age']) // false
    • isArray: function
      • Type guard that checks if a value is an array. Narrows the TypeScript type to array when returning true.

        Type Parameters

        • Value

          The type of elements in the array

        Parameters

        • value: unknown

          The value to check

        Returns value is Value[]

        True if value is an array, with type narrowing

        if (helpers.isArray(value)) {
        // value is now typed as array
        console.log(value.length)
        }
    • isNumeric: function
      • Checks if a value is numeric (number or string representing a number). Useful for validating form inputs that should contain numeric values.

        Parameters

        • value: any

          The value to check

        Returns boolean

        True if value can be converted to a valid number

        helpers.isNumeric(42) // true
        helpers.isNumeric('42') // true
        helpers.isNumeric('42.5') // true
        helpers.isNumeric('abc') // false
    • asNumber: function
      • Converts a value to a number using JavaScript's Number() constructor. Handles null values explicitly by returning NaN.

        Parameters

        • value: any

          The value to convert to a number

        Returns number

        The numeric representation, or NaN if conversion fails

        helpers.asNumber('42') // 42
        helpers.asNumber('42.5') // 42.5
        helpers.asNumber(null) // NaN
        helpers.asNumber('abc') // NaN
    • asBoolean: function
      • Converts a value to a boolean using HTML form semantics. Returns null for values that cannot be reliably converted.

        Conversion rules:

        • [true, 1, "1", "true", "on"] → true
        • [false, 0, "0", "false"] → false
        • Everything else → null

        Parameters

        • value: any

          The value to convert

        Returns boolean | null

        Boolean value, or null if conversion is ambiguous

        helpers.asBoolean('true') // true
        helpers.asBoolean('on') // true (checkbox checked)
        helpers.asBoolean('false') // false
        helpers.asBoolean('maybe') // null (ambiguous)
    • asDayJS: function
      • Converts a value to a Day.js date object with flexible format support. Handles timestamps, ISO dates, and custom formats with intelligent fallbacks.

        Parameters

        • value: any

          The value to convert to a date (string, number, Date, etc.)

        • format: OptionType | undefined

          Date format(s) to use for parsing. Can be:

          • Array of format strings (e.g., ['YYYY-MM-DD', 'DD/MM/YYYY'])
          • Single format string
          • Object with format and strict parsing options
          • Special values: 'x' for timestamps, 'iso8601' for ISO dates

        Returns { dateTime: Dayjs; formats: string | string[] | FormatObject }

        Object containing the parsed Day.js instance and normalized formats

        // Parse with default formats
        helpers.asDayJS('2023-12-25')
        // { dateTime: dayjs('2023-12-25'), formats: ['YYYY-MM-DD', 'YYYY-MM-DD HH:mm:ss'] }

        // Parse timestamp
        helpers.asDayJS('1703548800000', ['x'])
        // { dateTime: dayjs(1703548800000), formats: ['x'] }

        // Parse with custom format
        helpers.asDayJS('25/12/2023', ['DD/MM/YYYY'])
        // { dateTime: dayjs('25/12/2023', 'DD/MM/YYYY'), formats: ['DD/MM/YYYY'] }

        // ISO date fallback
        helpers.asDayJS('2023-12-25T10:30:00Z', ['iso8601'])
        // { dateTime: dayjs('2023-12-25T10:30:00Z'), formats: ['iso8601'] }
    • compareValues: function
      • Compares two values with intelligent type coercion. The input value is cast to match the type of the expected value for HTML form-friendly comparisons.

        Parameters

        • inputValue: unknown

          The input value to compare

        • expectedValue: any

          The expected value to compare against

        Returns { isEqual: boolean; casted: unknown }

        Object with comparison result and the casted input value

        // Number comparison
        helpers.compareValues('42', 42)
        // { isEqual: true, casted: 42 }

        // Boolean comparison
        helpers.compareValues('true', true)
        // { isEqual: true, casted: true }

        // String comparison (no casting)
        helpers.compareValues('hello', 'world')
        // { isEqual: false, casted: 'hello' }
    • isEmail: (str: string, options?: IsEmailOptions) => boolean

      Validates email addresses using comprehensive rules

    • isURL: (str: string, options?: IsURLOptions) => boolean

      Validates URLs with protocol and domain checking

    • isAlpha: (str: string, locale?: AlphaLocale, options?: IsAlphaOptions) => boolean

      Validates alphabetic characters only

    • isAlphaNumeric: (
          str: string,
          locale?: AlphanumericLocale,
          options?: IsAlphanumericOptions,
      ) => boolean

      Validates alphanumeric characters only

    • isIP: (str: string, version?: IPVersion) => boolean

      Validates IP addresses (IPv4 and IPv6)

    • isUUID: (str: string, version?: UUIDVersion) => boolean

      Validates UUID strings in various formats

    • isAscii: (str: string) => boolean

      Validates ASCII character strings

    • isCreditCard: (str: string, options?: IsCreditCardOptions) => boolean

      Validates credit card numbers using Luhn algorithm

    • isIBAN: (str: string, options?: IsIBANOptions) => boolean

      Validates International Bank Account Numbers

    • isJWT: (str: string) => boolean

      Validates JSON Web Tokens

    • isLatLong: (str: string) => boolean

      Validates latitude/longitude coordinate pairs

    • isMobilePhone: (
          str: string,
          locale?: MobilePhoneLocale | MobilePhoneLocale[] | "any",
          options?: IsMobilePhoneOptions,
      ) => boolean

      Validates mobile phone numbers for various locales

    • isPassportNumber: (str: string, countryCode?: string) => boolean

      Validates passport numbers for supported countries

    • isPostalCode: (str: string, locale: PostalCodeLocale | "any") => boolean

      Validates postal codes for various countries

    • isSlug: (str: string) => boolean

      Validates URL slugs (lowercase, hyphenated strings)

    • isDecimal: (str: string, options?: IsDecimalOptions) => boolean

      Validates decimal numbers

    • mobileLocales: MobilePhoneLocale[]

      Array of supported mobile phone locales/countries

    • postalCountryCodes: PostalCodeLocale[]

      Array of supported postal code country codes

    • passportCountryCodes: readonly [
          "AM",
          "AR",
          "AT",
          "AU",
          "AZ",
          "BE",
          "BG",
          "BR",
          "BY",
          "CA",
          "CH",
          "CY",
          "CZ",
          "DE",
          "DK",
          "DZ",
          "ES",
          "FI",
          "FR",
          "GB",
          "GR",
          "HR",
          "HU",
          "IE",
          "IN",
          "ID",
          "IR",
          "IS",
          "IT",
          "JM",
          "JP",
          "KR",
          "KZ",
          "LI",
          "LT",
          "LU",
          "LV",
          "LY",
          "MT",
          "MZ",
          "MY",
          "MX",
          "NL",
          "NZ",
          "PH",
          "PK",
          "PL",
          "PT",
          "RO",
          "RU",
          "SE",
          "SL",
          "SK",
          "TH",
          "TR",
          "UA",
          "US",
      ]

      Array of supported passport country codes

    • isULID: function
      • Validates if a value is a valid ULID (Universally Unique Lexicographically Sortable Identifier). ULIDs are 26-character strings that are lexicographically sortable and URL-safe.

        Parameters

        • value: unknown

          The value to validate

        Returns boolean

        True if value is a valid ULID

        helpers.isULID('01ARZ3NDEKTSV4RRFFQ69G5FAV') // true
        helpers.isULID('invalid-ulid') // false
        helpers.isULID('7ZZZZZZZZZZZZZZZZZZZZZZZZZ') // true (max valid ULID)
        helpers.isULID('8AAAAAAAAAAAAAAAAAAAAAAAAA') // false (overflow)
    • isHexColor: (value: string) => boolean

      Validates if a value is a valid hexadecimal color code. Requires the '#' prefix and supports 3, 6, or 8 character hex codes.

      helpers.isHexColor('#FF0000') // true (red)
      helpers.isHexColor('#f00') // true (short red)
      helpers.isHexColor('#FF000080') // true (red with alpha)
      helpers.isHexColor('FF0000') // false (missing #)
      helpers.isHexColor('#GGGGGG') // false (invalid hex)
    • isActiveURL: (url: string) => Promise<boolean>

      Validates if a URL has valid DNS records (A or AAAA records). This performs an actual DNS lookup to verify the domain exists.

      await helpers.isActiveURL('https://example.com') // true
      await helpers.isActiveURL('https://nonexistent-domain-12345.com') // false

      This function requires network access and may be slow.
      Consider caching results for better performance.
    • isDistinct: (dataSet: any[], fields?: string | string[]) => boolean

      Check if all the elements inside the dataset are unique.

      In case of an array of objects, you must provide one or more keys for the fields that must be unique across the objects.

      helpers.isDistinct([1, 2, 4, 5]) // true

      // Null and undefined values are ignored
      helpers.isDistinct([1, null, 2, null, 4, 5]) // true

      helpers.isDistinct([
      {
      email: 'foo@bar.com',
      name: 'foo'
      },
      {
      email: 'baz@bar.com',
      name: 'baz'
      }
      ], 'email') // true

      helpers.isDistinct([
      {
      email: 'foo@bar.com',
      tenant_id: 1,
      name: 'foo'
      },
      {
      email: 'foo@bar.com',
      tenant_id: 2,
      name: 'baz'
      }
      ], ['email', 'tenant_id']) // true
    • getNestedValue: function
      • Retrieves a nested value from the validation context. Supports both dot notation for deep access and direct parent access.

        Parameters

        • key: string

          The key or dot-notation path to the value

        • field: FieldContext

          The field context containing data and parent references

        Returns any

        The value at the specified path, or undefined if not found

        // Dot notation for nested access
        helpers.getNestedValue('user.profile.name', field)

        // Direct parent access
        helpers.getNestedValue('confirmPassword', field)

        // Deep object access
        helpers.getNestedValue('config.database.host', field)
    helpers.isString(value) // Type guard for strings
    helpers.asBoolean(value) // Convert to boolean with HTML form semantics
    helpers.isEmail(email) // Validate email addresses