### VineTuple Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineTuple.html Example demonstrating how to create and use a VineTuple schema for validation. ```APIDOC ## Example ```javascript const schema = vine.tuple([ vine.string(), vine.number(), vine.boolean() ]) const result = await vine.validate({ schema, data: ['hello', 42, true] }) ``` ``` -------------------------------- ### VineUnionOfTypes Examples Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index._internal_.VineUnionOfTypes.html Examples demonstrating how to use vine.unionOfTypes to create schemas for different scenarios. ```APIDOC ## Examples ### Example 1: Basic Types ```typescript const schema = vine.unionOfTypes([ vine.string(), vine.number(), vine.boolean() ]) ``` ### Example 2: Object Types with Discriminators ```typescript const schema = vine.unionOfTypes([ vine.object({ type: vine.literal('user'), name: vine.string() }), vine.object({ type: vine.literal('admin'), permissions: vine.array(vine.string()) }) ]) ``` ``` -------------------------------- ### VineEnum Example Usage Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineEnum.html Example demonstrating how to create and use a VineEnum schema for validation. ```APIDOC ## Example ```typescript const schema = vine.enum(['active', 'inactive', 'pending'] as const) const result = await vine.validate({ schema, data: 'active' // Must be one of the defined values }) ``` ``` -------------------------------- ### Example Usage of ConstructableLiteralSchema Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/interfaces/src_types.ConstructableLiteralSchema.html An example demonstrating how to implement the ConstructableLiteralSchema interface for a number schema. ```APIDOC class NumberSchema implements ConstructableLiteralSchema { [ITYPE]: number | undefined [OTYPE]: number [COTYPE]: number [PARSE](propertyName: string, refs: RefsStore, options: ParserOptions) { return { type: 'literal', subtype: 'number', propertyName, validations: [] } } clone() { return new NumberSchema() } } ``` -------------------------------- ### CreditCardOptions Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.CreditCardOptions.html Example of how to define CreditCardOptions to accept Visa, Mastercard, and Amex. ```typescript const options: CreditCardOptions = { provider: ['visa', 'mastercard', 'amex'] } ``` -------------------------------- ### VineCamelCaseObject Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index._internal_.VineCamelCaseObject.html Example demonstrating how to use the camelCase() method to convert snake_case keys to camelCase in the output schema. ```APIDOC ## Example ```javascript const schema = vine.object({ first_name: vine.string(), last_name: vine.string() }).camelCase() // Output will have: { firstName: string, lastName: string } ``` ``` -------------------------------- ### ValidationRule Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.ValidationRule.html An example demonstrating how to create a ValidationRule for checking the minimum length of a field. ```APIDOC ## Example ```typescript const minLengthRule: ValidationRule<{ length: number }> = { validator: minLengthValidator, name: 'minLength', isAsync: false, implicit: false } ``` ``` -------------------------------- ### VineLiteral Example Usage Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineLiteral.html An example demonstrating how to create and use a VineLiteral schema to validate an exact string value. ```APIDOC ## Example ```javascript const schema = vine.literal('admin') const result = await vine.validate({ schema, data: 'admin' }) ``` ``` -------------------------------- ### StringSchema Implementation Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.MetaModifier.html Illustrates a basic implementation of a ConstructableSchema for strings. This example shows how to define the ITYPE, OTYPE, COTYPE, and PARSE properties required by Vine.js schemas. ```typescript class StringSchema implements ConstructableSchema { [ITYPE]: string | undefined [OTYPE]: string [COTYPE]: string [PARSE](propertyName: string, refs: RefsStore, options: ParserOptions) { return { type: 'literal', subtype: 'string' } } clone() { return new StringSchema() } } ``` -------------------------------- ### VineRecord Examples Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineRecord.html Illustrates how to define and use VineRecord schemas for validating objects with dynamic keys. ```APIDOC ## Example 1: Simple Number Values ```javascript const schema = vine.record(vine.number()) const result = await vine.validate({ schema, data: { a: 1, b: 2, c: 3 } }) ``` ## Example 2: Complex Object Values ```javascript const schema = vine.record( vine.object({ name: vine.string(), age: vine.number() }) ) ``` ``` -------------------------------- ### DateEqualsOptions Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.DateEqualsOptions.html Demonstrates how to configure options for date equality comparison, specifying the unit of time for comparison and the expected date format. ```typescript const options: DateEqualsOptions = { compare: 'day', // Compare only the day part format: 'YYYY-MM-DD' } ``` -------------------------------- ### Example Usage of VATOptions Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.VATOptions.html Illustrates how to instantiate VATOptions with specific country codes for validation. ```typescript const options: VATOptions = { countryCode: ['FR', 'CH', 'VE'] } ``` -------------------------------- ### EmailOptions Configuration Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.EmailOptions.html Demonstrates how to configure EmailOptions for validation. Use this to specify domain restrictions, top-level domain requirements, and blacklisted hosts. ```typescript const options: EmailOptions = { allow_display_name: false, require_tld: true, host_blacklist: ['tempmail.com'] } ``` -------------------------------- ### VineAny Example Usage Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineAny.html Demonstrates how to use the VineAny schema to validate data that can accept any value. ```APIDOC ## Example Usage ### Description This example shows how to create a schema using `vine.any()` and then validate arbitrary data against it. ### Code ```javascript const schema = vine.any() const result = await vine.validate({ schema, data: 'any value, including objects and arrays' }) ``` ``` -------------------------------- ### ValidationError Example Usage Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.ValidationError.html Example demonstrating how to catch and use a ValidationError. ```APIDOC ```javascript try { await vine.validate({ schema, data }); } catch (error) { if (error instanceof ValidationError) { console.log(error.messages); // Structured validation errors console.log(error.status); // HTTP 422 } } ``` ``` -------------------------------- ### VineAccepted HTML Checkbox Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineAccepted.html Demonstrates how an HTML checkbox maps to the VineAccepted schema, where 'on' is accepted. ```APIDOC ## Example (HTML Form) ```html ``` When checked, sends "on" which is accepted by VineAccepted. ``` -------------------------------- ### VineAccepted Example Usage Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineAccepted.html Illustrates how to use VineAccepted within a schema object for terms acceptance. ```APIDOC ## Example ```javascript const schema = vine.object({ termsAccepted: vine.accepted(), newsletter: vine.accepted().optional() }) ``` ``` -------------------------------- ### HTML Form Checkbox Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineAccepted.html This example shows how an HTML form checkbox maps to the vine.accepted() validator. When checked, the browser typically sends 'on', which is accepted by the validator. ```html // HTML form checkbox // // When checked, sends "on" which is accepted ``` -------------------------------- ### Example of Uppercase Transformer Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.Transformer.html An example demonstrating how to create an uppercase transformer. This transformer takes a string schema and returns a string, converting the input value to uppercase. ```typescript const uppercaseTransformer: Transformer = (value) => { return value.toUpperCase() } ``` -------------------------------- ### NullableModifier Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.NullableModifier.html Demonstrates how to use the .nullable() method to create a schema that accepts strings or null. ```APIDOC ## Example ```javascript const schema = vine.string().nullable() // Accepts: "hello", null // Rejects: undefined, 123 ``` ``` -------------------------------- ### Vine.js Group Conditional Schema Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/functions/index._internal_.group.html This example demonstrates how to use `vine.group` with `vine.group.if` and `vine.group.else` to conditionally apply schema rules. Use this when you need to validate different properties based on a specific condition. ```javascript vine.group([ vine.group.if((value) => value.role === 'admin', { admin_key: vine.string() }), vine.group.else({ user_key: vine.string() }) ]) ``` -------------------------------- ### VineBoolean Example Usage Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineBoolean.html Demonstrates how to use the VineBoolean schema to validate a string input, which will be converted to a boolean. ```APIDOC ## Example ```javascript const schema = vine.boolean() const result = await vine.validate({ schema, data: "true" // Will be converted to true }) ``` ``` -------------------------------- ### Example: Custom Rule for Non-Empty String Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.BaseType.html This example shows how to use the use method with createRule to add a custom validation that checks if a string has a length greater than zero. ```typescript vine.string().use(vine.createRule((value) => { return value.length > 0})) ``` -------------------------------- ### Example: Custom String Trimming Parser Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.BaseType.html This example demonstrates using the parse method to trim whitespace from a string value before it's validated. ```typescript vine.string().parse((value) => { return typeof value === 'string' ? value.trim() : value}) ``` -------------------------------- ### VineNativeEnum Examples Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineNativeEnum.html Demonstrates how to use VineNativeEnum with TypeScript enums and object literals. ```APIDOC #### Example enum Status { Active = 'active', Inactive = 'inactive' } const schema = vine.nativeEnum(Status) #### Example const Colors = { RED: 'red', BLUE: 'blue', GREEN: 'green' } as const const schema = vine.nativeEnum(Colors) ``` -------------------------------- ### VineNull Example Usage Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineNull.html Example demonstrating how to use VineNull within a union type for validation. ```APIDOC ## Example ```javascript const schema = vine.union([ vine.string(), vine.null() ]) const result = await vine.validate({ schema, data: null }) ``` ``` -------------------------------- ### SchemaTypes Usage Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.SchemaTypes.html Demonstrates how to use SchemaTypes as a generic constraint for a validation function. ```APIDOC ## SchemaTypes Usage Example ### Description This example shows how to define a generic function `validateSchema` that accepts any schema type conforming to `SchemaTypes`. This ensures type safety when working with different schema definitions. ### Function Signature ```typescript function validateSchema(schema: T, data: any) ``` ### Parameters - **schema** (T): The schema object to validate against. `T` must extend `SchemaTypes`. - **data** (any): The data to be validated. ### Example Usage ```typescript // Assuming 'MySchema' is a valid schema type extending SchemaTypes // import { MySchema } from './schemas'; // const mySchema: MySchema = ...; // const myData = { ... }; // validateSchema(mySchema, myData); ``` * Defined in [src/types.ts:428](https://github.com/vinejs/vine/blob/main/src/types.ts#L428) ``` -------------------------------- ### Example Usage of UnionNoMatchCallback Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.UnionNoMatchCallback.html An example demonstrating how to define a UnionNoMatchCallback to throw a custom error when no union variant matches the input value. ```APIDOC ## Example ```typescript const noMatchCallback: UnionNoMatchCallback = (value, field) => { throw new Error(`No union variant matched for field ${field.name}`) } ``` ``` -------------------------------- ### Example CompilerNodes Literal Node Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.CompilerNodes.html Illustrates the structure of a literal node within Vine.js compiler nodes. This specific example defines a string literal node for a 'name' property. ```typescript const node: CompilerNodes = { type: 'literal', subtype: 'string', propertyName: 'name', validations: [] } ``` -------------------------------- ### Example: NumberSchema Implementation Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/interfaces/src_types.ConstructableLiteralSchema.html Demonstrates how to implement the ConstructableLiteralSchema interface for a number type. This class defines the input, output, and camelCase output types, along with the parsing logic. ```typescript class NumberSchema implements ConstructableLiteralSchema { [ITYPE]: number | undefined [OTYPE]: number [COTYPE]: number [PARSE](propertyName: string, refs: RefsStore, options: ParserOptions) { return { type: 'literal', subtype: 'number', propertyName, validations: [] } } clone() { return new NumberSchema() } } ``` -------------------------------- ### Create SimpleMessagesProvider with Minimal Configuration Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.SimpleMessagesProvider.html Instantiate SimpleMessagesProvider with only required messages and optional field names. This is useful for basic internationalization setups. ```typescript new SimpleMessagesProvider({ 'required': 'The {{ field }} field is required' }, { 'user_name': 'Username' }) ``` -------------------------------- ### MobileOptions Type Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.MobileOptions.html Demonstrates how to define MobileOptions for mobile number validation, including specifying locales and enabling strict mode. ```typescript const options: MobileOptions = { locale: ['en-US', 'en-GB'], strictMode: true } ``` -------------------------------- ### Initialize SimpleMessagesProvider Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/guides/custom_error_messages.md Configure custom error messages for various validation rules and field combinations using the SimpleMessagesProvider. This setup applies globally. ```typescript import vine, { SimpleMessagesProvider } from '@vinejs/vine' vine.messagesProvider = new SimpleMessagesProvider({ // Applicable for all fields 'required': 'The {{ field }} field is required', 'string': 'The value of {{ field }} field must be a string', 'email': 'The value is not a valid email address', // Error message for the username field 'username.required': 'Please choose a username for your account', }) ``` -------------------------------- ### Schema with Global Date Transformation Applied Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/types/date.md An example schema where `vine.date()` fields automatically yield Luxon DateTime instances due to a globally configured transformation. ```typescript import vine from '@vinejs/vine' const schema = vine.object({ checkinDate: vine.date(), checkoutDate: vine.date(), bookingDate: vine.date() }) ``` -------------------------------- ### Get Field Path Example Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/guides/field_context.md Illustrates how getFieldPath() provides a runtime-specific path for array members, unlike wildCardPath. ```typescript // Given the following schema const schema = vine.object({ contacts: vine.array( vine.object({ email: vine.string() }) ) }) /** * The return value of "getFieldPath" will be * - "contacts.0.email" * - "contacts.1.email" * - and so on */ /** * The value of "wildCardPath" will be * - "contacts.*.email" */ ``` -------------------------------- ### Implementing the VALIDATION Symbol Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/variables/index.symbols.VALIDATION.html This example shows how a custom rule class, MinLengthRule, implements the VALIDATION symbol. It returns an object containing the rule implementation and its options, allowing VineJS to process it. ```typescript class MinLengthRule { [VALIDATION]() { return { rule: minLengthRule, options: this.length } } } ``` -------------------------------- ### TransformModifier Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index._internal_.TransformModifier.html Example of how to use the transform modifier to convert a validated string to uppercase. ```APIDOC ## Example ```javascript const schema = vine.string().transform((value) => value.toUpperCase()) // Input: "hello" -> Output: "HELLO" ``` ``` -------------------------------- ### CamelCase Type Alias Examples Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/index._internal_.CamelCase.html Demonstrates the usage of the CamelCase type alias with different string literal inputs. It shows how snake_case, kebab-case, and PascalCase strings are converted to camelCase. ```typescript type Result1 = CamelCase<'user_name'> // 'userName' type Result2 = CamelCase<'first-name'> // 'firstName' type Result3 = CamelCase<'FirstName'> // 'firstName' ``` -------------------------------- ### VineAny Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineAny.html Demonstrates the constructor for the VineAny class, showing how to initialize it with optional field options and validations. This allows for customization of behavior like bail mode and nullability. ```typescript new VineAny( options?: Partial, validations?: Validation[], ): VineAny ``` -------------------------------- ### Install VineJS using pnpm Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/guides/getting_started.md Install the VineJS package in your Node.js project using pnpm. ```sh pnpm add @vinejs/vine ``` -------------------------------- ### Install VineJS using yarn Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/guides/getting_started.md Install the VineJS package in your Node.js project using yarn. ```sh yarn add @vinejs/vine ``` -------------------------------- ### Install VineJS using npm Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/guides/getting_started.md Install the VineJS package in your Node.js project using npm. ```sh npm i @vinejs/vine ``` -------------------------------- ### Vine Class Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.Vine.html Initializes a new instance of the Vine class, applying all registered instance properties and binding functions to the instance context. ```APIDOC ## constructor ### Description Constructor that applies all registered instance properties to the new instance. This method iterates through the instanceMacros set and assigns each property to the instance, binding functions to the instance context. ### Returns - Vine ### Defined in node_modules/@poppinss/macroable/build/index.d.ts:120 ``` -------------------------------- ### VineNativeFile Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineNativeFile.html Creates a new VineNativeFile instance with optional field options and initial validations. ```APIDOC ## constructor new VineNativeFile ### Description Creates a new VineNativeFile instance. ### Parameters * `options` (Partial) - Optional - Field options like bail mode and nullability * `validations` (Validation[]) - Optional - Initial set of validations to apply ### Returns VineNativeFile ``` -------------------------------- ### Union of Distinct Types (Recommended) Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/types/union.md This example demonstrates the recommended way to create a union for a `health_check` field that accepts either a URL string or a boolean using `vine.unionOfTypes`. This method simplifies schema definition by automatically handling type checks. ```typescript const schema = vine.object({ health_check: vine.unionOfTypes([ vine.boolean(), vine.string().url(), ]) }) ``` -------------------------------- ### Get Compiled Schema and Refs Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineValidator.html Use toJSON to get a JSON-serializable object of the compiled schema and refs. This is useful for caching or debugging. ```typescript const compiled = validator.toJSON() console.log(compiled.schema) console.log(compiled.refs) ``` -------------------------------- ### Define and Pre-compile a User Registration Schema Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/guides/pre_compiling.md Define a schema for user registration and then pre-compile it using `vine.compile`. This creates an optimized validation function. ```typescript import vine from '@vinejs/vine' const schema = vine.schema({ username: vine.string(), email: vine.string().email(), password: vine.string().min(8).max(32).confirmed() }) export const validate = vine.compile(schema) ``` -------------------------------- ### Example Validator: Minimum Length Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.Validator.html An example of a custom validator that checks if a string's length meets a minimum requirement. It throws an error if the condition is not met. ```typescript const minLengthValidator: Validator<{ length: number }> = (value, { length }, field) => { if (typeof value === 'string' && value.length >= length) { return value } throw new Error(`Minimum length is ${length}`) } ``` -------------------------------- ### VineRecord Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineRecord.html Creates a new VineRecord instance. You can define the schema for the record's values and optionally provide field options and initial validations. ```APIDOC ## constructor ### Description Creates a new VineRecord instance with value schema and optional configuration. ### Parameters * **schema**: The schema to validate each record value. * **options** (Optional): Field options like bail mode and nullability. * **validations** (Optional): Initial set of validations to apply. ### Returns VineRecord ``` -------------------------------- ### VineOptional Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineOptional.html Creates a new VineOptional instance. It can be initialized with partial field options and an array of validations. ```APIDOC ## constructor ### Description Creates a new VineOptional instance. ### Parameters * `options` (Partial) - Optional. Field options like bail mode and nullability. * `validations` (Array>) - Optional. Initial set of validations to apply. ### Returns VineOptional ### Overrides [ConditionalValidations](index.ConditionalValidations.html).[constructor](index.ConditionalValidations.html#constructor) ``` -------------------------------- ### VineObject Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineObject.html Creates a new VineObject instance. You can define properties, set field options like bail mode and nullability, and provide initial validations. ```APIDOC ## constructor ### Description Creates a new VineObject instance with property schemas and optional configuration. ### Parameters * **properties**: Record[] Initial set of validations to apply ### Returns VineObject<[Properties](#properties), [Input](#input), [Output](#output), [CamelCaseOutput](#camelcaseoutput)> ### Throws Error if properties is not provided ``` -------------------------------- ### startsWith Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineString.html Ensures the value starts with a specified substring. This method is chainable. ```APIDOC ## startsWith(substring: string) ### Description Ensures the value starts with a specified substring. ### Parameters * **substring** (string) - Required - The required starting substring. ### Returns VineString This string schema instance for method chaining. ### Example ```javascript vine.string().startsWith('https://') ``` ``` -------------------------------- ### [PARSE](propertyName, refs, options) Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index._internal_.NullableModifier.html Compiles to compiler node. ```APIDOC ## [PARSE](propertyName, refs, options) ### Description Compiles to compiler node. ### Method "[PARSE]"(propertyName: string, refs: RefsStore, options: ParserOptions): FieldNode & {} & { subtype: string } ### Parameters * propertyName: string * refs: RefsStore * options: [ParserOptions](../types/src_types.ParserOptions.html) ### Returns FieldNode & {} & { subtype: string } ### Example ```typescript // This method is typically used internally by Vine.js // Example usage is not directly applicable for external users. ``` ``` -------------------------------- ### AlphaNumericOptions Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.AlphaNumericOptions.html Define AlphaNumericOptions to allow spaces and underscores in alphanumeric validation. ```typescript const options: AlphaNumericOptions = { allowSpaces: true, allowUnderscores: true } ``` -------------------------------- ### [PARSE] Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.OptionalModifier.html Compiles the schema into compiler nodes. This method implements `ConstructableSchema.[PARSE]`. ```APIDOC ## [PARSE] ### Description Compiles to compiler node. ### Method ```typescript "[PARSE]"(propertyName: string, refs: RefsStore, options: ParserOptions): CompilerNodes[] ``` ### Parameters * **propertyName** (string) - The name of the property being parsed. * **refs** (RefsStore) - The references store. * **options** (ParserOptions) - The parser options. ### Returns * CompilerNodes[] - An array of compiler nodes. ``` -------------------------------- ### VineEnum Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineEnum.html Creates a new VineEnum instance with the specified allowed values. You can provide an array of allowed values or a function that returns the array. Optional field options and initial validations can also be provided. ```APIDOC ## constructor ### Signature ```typescript new VineEnum(values: Values | ((field: FieldContext) => Values), options?: FieldOptions, validations?: Validation[]): VineEnum ``` ### Parameters * **values** (Values | ((field: FieldContext) => Values)) - Required - Array of allowed values or function returning allowed values. * **options** (FieldOptions) - Optional - Field options like bail mode and nullability. * **validations** (Validation[]) - Optional - Initial set of validations to apply. ### Returns * VineEnum ``` -------------------------------- ### [PARSE](propertyName, refs, options) Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index._internal_.OptionalModifier.html Compiles the schema into a compiler node for parsing. ```APIDOC ## [PARSE](propertyName, refs, options) ### Description Compiles to compiler node. ### Method ```typescript "[PARSE]"( propertyName: string, refs: RefsStore, options: ParserOptions ): FieldNode & {} & { subtype: string } ``` ### Parameters * **propertyName** (string) - The name of the property being parsed. * **refs** (RefsStore) - The references store. * **options** (ParserOptions) - The parser options. ### Returns * FieldNode & {} & { subtype: string } - The compiled field node. ``` -------------------------------- ### clone(): this Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineOptional.html Creates a clone of the current VineOptional schema instance, copying all applied options and validations. ```APIDOC ## clone() ### Description Clones the VineOptional schema type. The applied options and validations are copied to the new instance. ### Returns this A cloned instance of this VineOptional schema. ``` -------------------------------- ### VineAccepted Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineAccepted.html Creates a new VineAccepted instance. It can optionally accept field options and initial validations. ```APIDOC ## constructor ### Description Creates a new VineAccepted instance. ### Parameters #### Parameters - **options** (Partial) - Optional - Field options like bail mode and nullability - **validations** (Validation[]) - Optional - Initial set of validations to apply ### Returns VineAccepted ``` -------------------------------- ### Validate String Starts With Substring Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/types/string.md Use `startsWith` to verify that a string begins with a specific substring. ```typescript vine.object({ email: vine .string() .startsWith('+91') }) ``` -------------------------------- ### VineString Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineString.html Creates a new VineString instance with optional configuration for field options and initial validations. ```APIDOC ## constructor ### Description Creates a new VineString instance with optional configuration. ### Parameters * `options` (FieldOptions) - Optional - Field options like bail mode and nullability * `validations` (Validation[]) - Optional - Initial set of validations to apply ### Returns VineString ``` -------------------------------- ### PassportOptions Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.PassportOptions.html Defines an object conforming to the PassportOptions type, specifying an array of country codes for validation. ```typescript const options: PassportOptions = { countryCode: ['US', 'GB', 'CA'] } ``` -------------------------------- ### VineBoolean Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineBoolean.html Initializes a new VineBoolean instance. You can provide options for bail mode, nullability, and strict type checking, along with an initial set of validations. ```APIDOC ## constructor ### Description Creates a new VineBoolean instance with optional configuration. ### Parameters * `options` (Partial & { strict?: boolean }) - Optional. Field options like bail mode, nullability and strict mode. * `validations` (Validation[]) - Optional. Initial set of validations to apply. ### Returns VineBoolean ``` -------------------------------- ### EnumSatisfies EnumLike Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.EnumLike.html Demonstrates how a TypeScript enum satisfies the EnumLike type. This is useful for validation purposes. ```typescript enum Status { ACTIVE = 'active', INACTIVE = 'inactive' } // Status satisfies EnumLike ``` -------------------------------- ### VineDate Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineDate.html Creates a new VineDate instance with optional configuration for field options and initial validations. ```APIDOC ## constructor ### Description Creates a new VineDate instance with optional configuration. ### Parameters * `options` (Partial & DateFieldOptions) - Optional - Field options including date formats and nullability. * `validations` (Validation[]) - Optional - Initial set of validations to apply. ### Returns VineDate - An instance of VineDate. ``` -------------------------------- ### Create a New VineEnum Instance Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineEnum.html Instantiate VineEnum by providing an array of allowed values or a function that returns them. Optional field options and initial validations can also be supplied. ```typescript new VineEnum(values: Values | ((field: FieldContext) => Values), options?: FieldOptions, validations?: Validation[]): VineEnum ``` -------------------------------- ### Implement RuleBuilder Interface Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/interfaces/src_types.RuleBuilder.html Example of implementing the RuleBuilder interface. This class converts its configuration into a validation object. ```typescript class MinLengthBuilder implements RuleBuilder { constructor(private length: number) {} [VALIDATION](): Validation<{ length: number }> { return { rule: minLengthRule, options: { length: this.length } } } } ``` -------------------------------- ### Applying Validation Rules with .use() Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/interfaces/src_types.WithCustomRules.html Shows how to apply predefined or custom validation rules to a schema instance using the .use() method. Rules are processed sequentially as they are added, allowing for complex validation chains. ```typescript schema.use(minLength({ length: 3 }))schema.use(myCustomRule({ strict: true })) ``` -------------------------------- ### ValidationFields Type Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.ValidationFields.html Demonstrates how to define field name mappings for error messages using the ValidationFields type. ```typescript const fields: ValidationFields = { 'user.email': 'Email Address', 'user.name': 'Full Name' } ``` -------------------------------- ### VineNumber Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineNumber.html Creates a new VineNumber instance with optional configuration. ```APIDOC ## constructor ### Description Creates a new VineNumber instance with optional configuration. ### Parameters * `options` (Partial & { strict?: boolean }) - Optional - Field options like bail mode, nullability and strict mode. * `validations` (Validation[]) - Optional - Initial set of validations to apply. ### Returns VineNumber ``` -------------------------------- ### Define a ValidationRule Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.ValidationRule.html Example of how to define a ValidationRule, combining a validator function with metadata like name, async status, and implicit execution. ```typescript const minLengthRule: ValidationRule<{ length: number }> = { validator: minLengthValidator, name: 'minLength', isAsync: false, implicit: false } ``` -------------------------------- ### Create a New VineValidator Instance Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineValidator.html Instantiate a VineValidator with a schema and configuration options. Ensure all required options like messagesProvider and errorReporter are provided. ```typescript new VineValidator( schema, options ) ``` -------------------------------- ### Define Any Schema - Vine.js Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index._internal_.SchemaBuilder.html Use the any method to create a schema that accepts any value without validation. Use sparingly as it bypasses type safety. ```javascript vine.any() // Accepts any value: string, number, object, etc. ``` -------------------------------- ### Create and Validate Schema with Vine Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.Vine.html Instantiate the Vine class and use its fluent API to define an object schema with string and number types. Then, validate input data against this schema. ```typescript const vine = new Vine() const schema = vine.object({ name: vine.string(), age: vine.number() }) const result = await vine.validate({ schema, data: { name: 'John', age: 30 } }) ``` -------------------------------- ### [PARSE](propertyName, refs, options) Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.NullableModifier.html Compiles the schema into compiler nodes, delegating to the parent schema and setting the allowNull flag. ```APIDOC ## [PARSE](propertyName, refs, options) ### Description Compiles to compiler node by delegating to the parent schema and setting the allowNull flag. ### Method ```typescript "[PARSE]"(propertyName: string, refs: RefsStore, options: ParserOptions): CompilerNodes[] ``` ### Parameters #### Parameters - **propertyName** (string) - Required - Name of the property being compiled. - **refs** (RefsStore) - Required - Reference store for the compiler. - **options** (ParserOptions) - Required - Parser options. ### Returns - **CompilerNodes[]**: Compiled compiler node with null support. ``` -------------------------------- ### Custom Error Reporter Implementation Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/interfaces/src_types.ErrorReporterContract.html Example of implementing the ErrorReporterContract interface. This shows how to define custom logic for reporting and creating validation errors. ```typescript class CustomErrorReporter implements ErrorReporterContract { report(message: string, rule: string, field: FieldContext) { // Custom error reporting logic } createError(): ValidationError { return new ValidationError(this.getErrors()) } } ``` -------------------------------- ### VineAny Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineAny.html Creates a new VineAny instance. You can optionally provide field options and an initial set of validations. ```APIDOC ## constructor VineAny ### Description Creates a new VineAny instance with optional configuration. ### Parameters #### Parameters - **options** (Partial) - Optional - Field options like bail mode and nullability - **validations** (Validation[]) - Optional - Initial set of validations to apply ### Returns VineAny ``` -------------------------------- ### Custom Key Validation for Record Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/types/record.md Use validateKeys to apply custom validation logic to the keys of a record. This example ensures all keys are numeric. ```typescript { colors: vine .record(vine.string().hexCode()) .validateKeys((keys, field) => { const nonNumericKey = keys.find((key) => !vine.helpers.isNumber(key)) if (!!nonNumericKey) { field.report( 'Color scale must be a valid number', // message 'record.keys.number', // error id field ) } }) } ``` -------------------------------- ### Omitting specific properties from an object schema Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineObject.html Use `omit()` to get a cloned copy of object properties, excluding the keys provided in the argument. ```typescript const userSchema = vine.object({ name: vine.string(), email: vine.string().email(), password: vine.string() }) const withoutPassword = userSchema.omit(['password']) ``` -------------------------------- ### clone() Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineString.html Clones the VineString schema type, copying applied options and validations to a new instance. ```APIDOC ## clone() ### Description Clones the VineString schema type. The applied options and validations are copied to the new instance. ### Method `clone()` ### Response A cloned instance of this VineString schema. ``` -------------------------------- ### Getting object properties Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineObject.html Use `getProperties()` to retrieve a cloned copy of all properties defined in the object schema. Object groups are excluded from the result. ```typescript const properties = schema.getProperties() ``` -------------------------------- ### SchemaBuilder Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index._internal_.SchemaBuilder.html Initializes a new SchemaBuilder instance. This constructor applies all registered instance properties (macros) to the new instance, binding functions to the instance context. ```APIDOC ## constructor ### Description Constructor that applies all registered instance properties to the new instance. This method iterates through the instanceMacros set and assigns each property to the instance, binding functions to the instance context. ### Returns SchemaBuilder ### Defined in node_modules/@poppinss/macroable/build/index.d.ts:120 ``` -------------------------------- ### Serialize Messages Provider to JSON Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.SimpleMessagesProvider.html Use this method to get a JSON-compatible representation of the messages provider. This is useful for debugging, logging, or transferring configuration. ```typescript const config = provider.toJSON()console.log(config)// { messages: { required: "..." }, fields: { user_name: "Username" } } ``` -------------------------------- ### Basic VineRecord Usage Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineRecord.html Demonstrates how to create a VineRecord schema for an object where all values are numbers. This is useful for validating dynamic key-value pairs with a consistent value type. ```typescript const schema = vine.record(vine.number()) const result = await vine.validate({ schema, data: { a: 1, b: 2, c: 3 } }) ``` -------------------------------- ### Manual Date Transformation with Luxon Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/types/date.md Demonstrates manually transforming validated JavaScript Date objects into Luxon DateTime instances for each date field in a schema. This is the approach without global transformations. ```typescript import vine from '@vinejs/vine' import { DateTime } from 'luxon' const schema = vine.object({ checkinDate: vine.date().transform((value) => DateTime.fromJSDate(value)), checkoutDate: vine.date().transform((value) => DateTime.fromJSDate(value)), bookingDate: vine.date().transform((value) => DateTime.fromJSDate(value)) }) ``` -------------------------------- ### Define Enum Schema with Dynamic Values Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.Vine.html Use this to validate input against a set of values determined dynamically at runtime, for example, based on user roles. ```javascript vine.enum((field) => getUserRoles(field.meta.userId)) ``` -------------------------------- ### UndefinedOptional Type Transformation Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.UndefinedOptional.html This example demonstrates how the UndefinedOptional utility type converts a type with potentially undefined properties into one where those properties are truly optional. ```typescript type Before = { name: string; age?: number | undefined } type After = UndefinedOptional// After = { name: string; age?: number } ``` -------------------------------- ### VineAccepted Class Methods Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineAccepted.html This section details the methods available on the VineAccepted schema class, allowing for schema manipulation and validation configuration. ```APIDOC ## clone() ### Description Clones the VineAccepted schema type. The applied options and validations are copied to the new instance. ### Method clone(): this ### Returns this - A cloned instance of this VineAccepted schema. ### Overrides BaseLiteralType.clone ``` ```APIDOC ## toJSONSchema() ### Description Transforms your schema type into JSONSchema7. ### Method toSJSONSchema(): JSONSchema7 ### Returns JSONSchema7 ### Inherited from BaseLiteralType.toJSONSchema ``` ```APIDOC ## parse(callback: ParseFn) ### Description 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 it. ### Method parse(callback: ParseFn): this ### Parameters * **callback**: ParseFn - The function to parse the input value. ### Returns this ### Inherited from BaseLiteralType.parse ``` ```APIDOC ## use(validation: Validation | RuleBuilder) ### Description Adds a validation rule to the schema's validation chain. Rules are executed in the order they are added. ### Method use(validation: Validation | RuleBuilder): this ### Parameters * **validation**: Validation | RuleBuilder - The validation rule or rule builder to add. ### Returns this - This schema instance for method chaining. ### Example ```javascript vine.string().use(minLength({ length: 3 })) vine.number().use(customRule({ strict: true })) ``` ### Inherited from BaseLiteralType.use ``` ```APIDOC ## bail(state: boolean) ### Description Enable/disable bail mode for this field. In bail mode, field validations stop after the first error. ### Method bail(state: boolean): VineAccepted ### Parameters * **state**: boolean - Whether to enable bail mode. ### Returns VineAccepted - This schema instance for method chaining. ### Example ```javascript vine.string().bail(false) // Continue validation after first error vine.number().bail(true) // Stop after first error (default) ``` ### Inherited from BaseLiteralType.bail ``` ```APIDOC ## optional() ### Description Mark the field under validation as optional. An optional field allows both null and undefined values. ### Method optional(): OptionalModifier ### Returns OptionalModifier ### Inherited from BaseLiteralType.optional ``` -------------------------------- ### VineTuple Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineTuple.html Creates a new VineTuple instance with position-specific schemas. It accepts an array of schemas, optional field options, and initial validations. ```APIDOC ## constructor ### Description Creates a new VineTuple instance with position-specific schemas. ### Parameters * **schemas** (Array) - Required - Array of schemas defining validation for each tuple position. * **options** (FieldOptions) - Optional - Field options like bail mode and nullability. * **validations** (Array>) - Optional - Initial set of validations to apply. ### Returns VineTuple ``` -------------------------------- ### Validating a VineTuple Schema Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineTuple.html Example of validating data against a VineTuple schema. The schema defines a string, a number, and a boolean as the expected types for the tuple elements. ```typescript const schema = vine.tuple([ vine.string(), vine.number(), vine.boolean() ]) const result = await vine.validate({ schema, data: ['hello', 42, true] }) ``` -------------------------------- ### Define and Validate a Boolean Schema Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineBoolean.html Use vine.boolean() to create a schema for boolean validation. This example shows how to validate a string input, which will be converted to a boolean. ```typescript const schema = vine.boolean() const result = await vine.validate({ schema, data: "true" // Will be converted to true }) ``` -------------------------------- ### Clone a schema and make it nullable Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/guides/schema_101.md Call the `clone` method on a schema to create a fresh instance. This allows you to configure it separately, for example, by making it nullable. ```typescript const userSchema = vine.object({ username: vine.string() }) const postSchema = vine.object({ title: vine.string(), // highlight-start author: userSchema.clone().nullable() // highlight-end }) ``` -------------------------------- ### Custom JSONAPIErrorReporter Implementation Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/guides/error_reporter.md An example of a custom error reporter that formats errors according to the JSONAPI specification. It collects errors and creates a ValidationError instance. ```typescript import { errors } from '@vinejs/vine' import { FieldContext, ErrorReporterContract } from '@vinejs/vine/types' export class JSONAPIErrorReporter implements ErrorReporterContract { /** * A flag to know if one or more errors have been * reported */ hasErrors: boolean = false /** * A collection of errors. Feel free to give accurate types * to this property */ errors: any[] = [] /** * VineJS call the report method */ report( message: string, rule: string, field: FieldContext, meta?: any ) { this.hasErrors = true /** * Collecting errors as per the JSONAPI spec */ this.errors.push({ code: rule, detail: message, source: { pointer: field.wildCardPath }, ...(meta ? { meta } : {}) }) } /** * Creates and returns an instance of the * ValidationError class */ createError() { return new errors.E_VALIDATION_ERROR(this.errors) } } ``` -------------------------------- ### Literal Type Usage Example Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.Literal.html Demonstrates assigning different literal types to a variable typed as Literal. These primitive values are suitable for strict equality comparisons. ```typescript const value: Literal = 'hello' const numberValue: Literal = 42 const boolValue: Literal = true ``` -------------------------------- ### date() Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index._internal_.SchemaBuilder.html Defines a datetime value schema with optional parsing options. It returns a VineDate schema instance. ```APIDOC ## date() ### Description Define a datetime value schema with optional parsing options. ### Parameters #### Optional Parameters - **options** ([DateFieldOptions](../types/src_types.DateFieldOptions.html)) - Configuration options for date validation. This can include `formats` (string[]) for specifying expected date formats. ### Returns [VineDate](index.VineDate.html) A VineDate schema instance. ### Example ```javascript vine.date({ formats: ['YYYY-MM-DD'] }) ``` ``` -------------------------------- ### Parse Input Value with Default Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/guides/schema_101.md Mutate input values before validation using the `parse` method. This example sets a default role if the input value is falsy. ```typescript function assignDefaultRole(value: unknown) { if (!value) { return 'guest' } return value } const schema = vine.object({ role: vine.string().parse(assignDefaultRole) }) ``` -------------------------------- ### VineArray Constructor Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineArray.html Creates a new VineArray instance. You can specify the schema for array elements, field options, and initial validations. ```APIDOC ## constructor * new VineArray(schema: Schema, options?: FieldOptions, validations?: Validation[]): VineArray[] ### Description Creates a new VineArray instance with element schema and optional configuration. ### Parameters * **schema**: Schema - The schema to validate each array element * **options**: FieldOptions - Optional field options like bail mode and nullability * **validations**: Validation[] - Optional initial set of validations to apply ### Returns VineArray ``` -------------------------------- ### Basic Schema Validation Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/guides/getting_started.md Define a validation schema for user registration data and validate it. This example shows basic string, email, and password validation with confirmation. ```ts import vine from '@vinejs/vine' const schema = vine.object({ username: vine.string(), email: vine.string().email(), password: vine .string() .minLength(8) .maxLength(32) .confirmed() }) const data = { username: 'virk', email: 'virk@example.com', password: 'secret', password_confirmation: 'secret', } const output = await vine.validate({ schema, data }) console.log(output) ``` -------------------------------- ### [PARSE](propertyName, refs, options) Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index._internal_.VineCamelCaseObject.html Compiles the schema type into a compiler node, enabling camelCase conversion. ```APIDOC ## [PARSE](propertyName, refs, options) ### Description Compiles the schema type into a compiler node, specifically enabling camelCase conversion for property names. ### Method `[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): ObjectNode` ### Parameters #### Path Parameters * **propertyName** (string) - Required - Name of the property being compiled. * **refs** (RefsStore) - Required - Reference store for the compiler. * **options** ([ParserOptions](../types/src_types.ParserOptions.html)) - Required - Parser options. ### Returns `ObjectNode` - A compiled object node with camelCase conversion applied. ### Overrides [BaseType.[PARSE]](index.BaseType.html#parse) ``` -------------------------------- ### Access Parent in Array Member Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/guides/field_context.md Provides an example of checking if a field is an array member and accessing its parent array using the field's name as the index. ```typescript vine.createRule((value, options, field) => { if (field.isArrayMember) { console.log(field.parent[field.name]) } }) ``` -------------------------------- ### Ensure String Starts With Substring Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineString.html Ensures the string value begins with a specified substring. This is commonly used for validating prefixes like URLs or specific identifiers. ```typescript vine.string().startsWith('https://') ``` -------------------------------- ### Use the vine.money() schema builder method Source: https://github.com/vinejs/vinejs.dev/blob/main/content/docs/extend/custom_schema_types.md Shows the final usage of the custom 'money' schema type via the extended Vine.js schema builder API. ```typescript const schema = vine.object({ product_id: vine.string(), amount: vine.money(), }) ``` -------------------------------- ### Implement IS_OF_TYPE for StringSchema Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/variables/index.symbols.IS_OF_TYPE.html Example of how to implement the IS_OF_TYPE symbol within a custom schema class to check if a value is a string. This is used by union schemas to match variants. ```typescript class StringSchema { [IS_OF_TYPE](value: unknown) { return typeof value === 'string' } } ``` -------------------------------- ### Define a VineJS Parser Function Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/types/src_types.Parser.html Example of defining a parser function that trims whitespace from string inputs. Parsers are used to preprocess values before they are validated by a VineJS schema. ```typescript const trimParser: Parser = (value) => { return typeof value === 'string' ? value.trim() : value } ``` -------------------------------- ### clone() Source: https://github.com/vinejs/vinejs.dev/blob/main/public/api/classes/index.VineEnum.html Clones the VineEnum schema type. The applied options and validations are copied to the new instance. ```APIDOC ## clone() ### Description Clones the VineEnum schema type. The applied options and validations are copied to the new instance. ### Method clone() ### Returns this - A cloned instance of this VineEnum schema. ```