ConstChecks if a value exists (is not null and not undefined). Useful for checking if optional form fields have been provided.
The value to check
True if value is not null and not undefined
Checks if a value is missing (null or undefined). The inverse of the exists method.
The value to check
True if value is null or undefined
Checks if a value represents a truthy boolean in HTML form context. Recognizes common HTML form representations of true values.
Accepted truthy values:
The value to check
True if value represents a truthy boolean
Checks if a value represents a falsy boolean in HTML form context. Recognizes common HTML form representations of false values.
Accepted falsy values:
The value to check
True if value represents a falsy boolean
Type guard that checks if a value is a string. Narrows the TypeScript type to string when returning true.
The value to check
True if value is a string, with type narrowing
Type guard that checks if a value is a plain JavaScript object. Excludes null, arrays, and other non-plain objects.
The type of values in the object
The value to check
True if value is a plain object, with type narrowing
Checks if an object contains all the specified keys. Useful for validating object structure before processing.
The object to check
Array of key names that must exist
True if all keys exist in the object
Type guard that checks if a value is an array. Narrows the TypeScript type to array when returning true.
The type of elements in the array
The value to check
True if value is an array, with type narrowing
Checks if a value is numeric (number or string representing a number). Useful for validating form inputs that should contain numeric values.
The value to check
True if value can be converted to a valid number
Converts a value to a number using JavaScript's Number() constructor. Handles null values explicitly by returning NaN.
The value to convert to a number
The numeric representation, or NaN if conversion fails
Converts a value to a boolean using HTML form semantics. Returns null for values that cannot be reliably converted.
Conversion rules:
The value to convert
Boolean value, or null if conversion is ambiguous
Converts a value to a Day.js date object with flexible format support. Handles timestamps, ISO dates, and custom formats with intelligent fallbacks.
The value to convert to a date (string, number, Date, etc.)
Date format(s) to use for parsing. Can be:
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'] }
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.
The input value to compare
The expected value to compare against
Object with comparison result and the casted input value
Validates email addresses using comprehensive rules
Validates URLs with protocol and domain checking
Validates alphabetic characters only
Validates alphanumeric characters only
Validates IP addresses (IPv4 and IPv6)
Validates UUID strings in various formats
Validates ASCII character strings
Validates credit card numbers using Luhn algorithm
Validates International Bank Account Numbers
Validates JSON Web Tokens
Validates latitude/longitude coordinate pairs
Validates mobile phone numbers for various locales
Validates passport numbers for supported countries
Validates postal codes for various countries
Validates URL slugs (lowercase, hyphenated strings)
Validates decimal numbers
Array of supported mobile phone locales/countries
Array of supported postal code country codes
Array of supported passport country codes
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.
The value to validate
True if value is a valid ULID
Validates if a value is a valid hexadecimal color code. Requires the '#' prefix and supports 3, 6, or 8 character hex codes.
Validates if a URL has valid DNS records (A or AAAA records). This performs an actual DNS lookup to verify the domain exists.
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
Retrieves a nested value from the validation context. Supports both dot notation for deep access and direct parent access.
The key or dot-notation path to the value
The field context containing data and parent references
The value at the specified path, or undefined if not found
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.