New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vue3-form-validation

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue3-form-validation - npm Package Compare versions

Comparing version 5.0.6 to 5.0.7

804

dist/vue3-form-validation.d.ts

@@ -1,58 +0,81 @@

import { ComputedRef } from 'vue'
import { Plugin as Plugin_2 } from 'vue'
import { Ref } from 'vue'
import { UnwrapRef } from 'vue'
import { WatchStopHandle } from 'vue'
import { UnwrapRef, Ref, ComputedRef, Plugin } from 'vue'
declare class CancelError extends Error {}
declare type DefaultValidationBehaviorString =
| 'aggressive'
| 'lazy'
| 'lazier'
| 'submit'
| 'force'
| 'change'
declare type ValidationBehaviorString =
| DefaultValidationBehaviorString
| keyof CustomValidationBehaviorFunctions
interface CustomValidationBehaviorFunctions {}
declare type ValidationBehaviorInfo<T = any> = {
/**
* `True` if the paired rule of this behavior has an error.
*/
hasError: boolean
/**
* The touched state of the field.
*/
touched: boolean
/**
* The dirty state of the field.
*/
dirty: boolean
/**
* `True` if the validation was triggered with the `force` flag.
*/
force: boolean
/**
* `True` if the validation was triggered with the `submit` flag.
*/
submit: boolean
/**
* The `$value` property of the field.
*/
value: T
}
declare type ValidationBehaviorFunction = (info: ValidationBehaviorInfo) => any
declare type ValidationBehavior =
| ValidationBehaviorString
| ValidationBehaviorFunction
export declare type Configuration =
keyof UseValidation_CustomValidationBehaviorFunctions extends never
? {
defaultValidationBehavior: ValidationBehaviorString
validationBehavior?: ConfigurationValidationBehavior
}
: {
defaultValidationBehavior: ValidationBehaviorString
validationBehavior: ConfigurationValidationBehavior
}
export declare type ConfigurationValidationBehavior = nDomain.Optional<
{
[K in ValidationBehaviorString]: ValidationBehaviorFunction
},
DefaultValidationBehaviorString
>
declare type ControlledRef<T> = {
silentSet: (value: T) => void
} & Ref<T>
declare function controlledRef<T>(initial: T): ControlledRef<UnwrapRef<T>>
/**
* Configure the validation behavior of `useValidation`.
*
* @param configuration - The form validation configuration
*/
export declare function createValidation(configuration: Configuration): Plugin_2
declare function debounce<TArgs extends unknown[]>(
target: (...args: [...TArgs]) => void,
{
wait,
shouldInvoke
}: {
wait: number
shouldInvoke?: (...args: [...TArgs]) => ShouldInvokeResult
}
): Debounced<TArgs>
declare type Debounced<TArgs extends unknown[]> = {
(...args: [...TArgs]): void
cancel(): void
declare type SimpleRule<TParameter = any> = (...value: TParameter[]) => any
declare type KeyedRule<TParameters extends readonly any[] = any[]> = (
...values: [...TParameters]
) => any
declare type RuleWithKey<T extends readonly any[] = any[]> = {
key: string
rule?: KeyedRule<T>
}
declare type FieldSimpleRule<TParameter = any> =
| SimpleRule<TParameter>
| [
validationBehavior: ValidationBehavior,
rule: SimpleRule<TParameter>,
debounce?: number
]
| [rule: SimpleRule<TParameter>, debounce: number]
declare type FieldRuleWithKey<TParameters extends readonly any[]> =
| RuleWithKey<TParameters>
| [
validationBehavior: ValidationBehavior,
rule: RuleWithKey<TParameters>,
debounce?: number
]
| [rule: RuleWithKey<TParameters>, debounce: number]
declare type FieldRule<
TSimpleParameter,
TKeyedParameters extends readonly any[] = any[]
> =
| FieldSimpleRule<
TSimpleParameter extends any[]
? TSimpleParameter
: UnwrapRef<TSimpleParameter>
>
| FieldRuleWithKey<TKeyedParameters>
declare function deepCopy<T>(toClone: T): T
declare type Key = string | number
declare type DeepIndex<T, Ks extends readonly Key[], R = unknown> = Ks extends [

@@ -68,8 +91,11 @@ infer First,

: T
declare type Optional<T, K extends keyof T> = Partial<Pick<T, K>> &
Omit<T, K> &
(T extends (...args: any[]) => any
? {
(...args: Parameters<T>): ReturnType<T>
}
: unknown)
declare type MaybeRef<T> = T extends Ref<infer V> ? T | V : Ref<T> | T
declare function deepIterator(
obj: object,
predicate?: (value: object) => boolean
): Generator<DeepIteratorResult, void>
declare type DeepIteratorResult = {

@@ -83,13 +109,3 @@ key: string

declare type DefaultValidationBehaviorString =
| 'aggressive'
| 'lazy'
| 'lazier'
| 'submit'
| 'force'
| 'change'
declare function disposeForm(form: Form, deletedFormData: any): void
export declare type Field<
declare type Field<
TValue,

@@ -101,3 +117,3 @@ TExtra extends Record<string, unknown> = Record<string, never>

*/
$value: nDomain.MaybeRef<TValue>
$value: MaybeRef<TValue>
/**

@@ -108,157 +124,20 @@ * Rules to use for validation.

} & (TExtra extends Record<string, never> ? unknown : TExtra)
/**
* Receive the name of every field in `FormData` as a union of strings.
*/
export declare type FieldNames<FormData> = FormData extends (infer TArray)[]
? FieldNames<TArray>
: {
[K in keyof FormData]-?: Exclude<FormData[K], undefined> extends {
$value: any
}
? K
: FieldNames<FormData[K]>
}[keyof FormData]
declare type FieldRule<
TSimpleParameter,
TKeyedParameters extends readonly any[] = any[]
> =
| FieldSimpleRule<
TSimpleParameter extends any[]
? TSimpleParameter
: UnwrapRef<TSimpleParameter>
>
| FieldRuleWithKey<TKeyedParameters>
declare type FieldRuleWithKey<TParameters extends readonly any[]> =
| RuleWithKey<TParameters>
| [
validationBehavior: ValidationBehavior,
rule: RuleWithKey<TParameters>,
debounce?: number
]
| [rule: RuleWithKey<TParameters>, debounce: number]
declare type FieldSimpleRule<TParameter = any> =
| SimpleRule<TParameter>
| [
validationBehavior: ValidationBehavior,
rule: SimpleRule<TParameter>,
debounce?: number
]
| [rule: SimpleRule<TParameter>, debounce: number]
declare class Form {
simpleValidators: Map<number, SimpleValidators>
keyedValidators: Map<string, KeyedValidators>
reactiveFields: Map<number, FormField>
tryGetSimpleValidators: ({
success,
failure
}: {
success(value: SimpleValidators): void
failure?(): void
}) => (key: number) => void
trySetKeyedValidators: ({
success,
failure
}: {
success?(value: KeyedValidators): void
failure?(value: KeyedValidators): void
}) => (key: string, value: KeyedValidators) => void
tryGetKeyedValidators: ({
success,
failure
}: {
success(value: KeyedValidators): void
failure?(): void
}) => (key: string) => void
rulesValidating: Ref<number>
submitting: Ref<boolean>
validating: ComputedRef<boolean>
hasError: ComputedRef<boolean>
errors: ComputedRef<string[]>
registerField(
uid: number,
name: string,
modelValue: unknown,
ruleInfos: RuleInformation[]
): FormField
validate(uid: number, force?: boolean): void
validateAll(names?: readonly nDomain.Key[]): Promise<void>
dispose(uid: number): void
resetFields(): void
getField(uid: number): FormField | undefined
private invokeValidatorsForKeys
private collectValidatorResultsForKeys
private collectValidatorResultsForNames
private isEveryFieldTouched
}
declare class FormField {
watchStopHandle: WatchStopHandle
form: Form
ruleInfos: MappedRuleInformation[]
rulesValidating: Ref<number>
initialModelValue: unknown
uid: number
name: string
touched: Ref<boolean>
dirty: Ref<boolean>
modelValue: Ref<any>
rawErrors: (string | null)[]
errors: ComputedRef<string[]>
validating: ComputedRef<boolean>
hasError: ComputedRef<boolean>
constructor(
form: Form,
uid: number,
name: string,
modelValue: any,
ruleInfos: RuleInformation[]
)
validate(
ruleNumber: number,
modelValues: unknown[],
noThrow: boolean
): Promise<void>
reset(resetValue?: unknown): void
dispose(): void
shouldValidate(ruleNumber: number, force: boolean, submit: boolean): any
private setError
private setupWatcher
}
declare function getResultFormData(
transformedFormData: any,
predicate?: (
value: Omit<nDomain.DeepIteratorResult, 'isLeaf' | 'parent'>
) => unknown
): any
declare const isArray: (x: unknown) => x is any[]
declare const isDefined: <T>(x: T | null | undefined) => x is T
declare const isField: <T>(x: unknown) => x is {
declare type ValidateOptions = {
/**
* The field's default value.
* Set the field touched when called.
*
* @default true
*/
$value: nDomain.MaybeRef<T>
setTouched?: boolean
/**
* Rules to use for validation.
* Validate with the `force` flag set.
*
* @default true
*/
$rules?: FieldRule<T, any[]>[] | undefined
force?: boolean
}
declare const isObject: (x: unknown) => x is Record<Key, any>
declare const isRecord: (x: unknown) => x is Record<Key, any>
declare const isSimpleRule: (
rule: SimpleRule | RuleWithKey
) => rule is SimpleRule<any>
declare const isTransformedField: <T>(x: unknown) => x is {
declare type TransformedField<
TValue,
TExtra extends Record<string, unknown> = Record<string, never>
> = {
/**

@@ -271,3 +150,3 @@ * The unique id of this field.

*/
$value: T
$value: TValue
/**

@@ -310,152 +189,8 @@ * A list of validation error messages local to this field without `null` values.

*/
$validate(options?: ValidateOptions | undefined): void
}
declare type Key = string | number
export declare type KeyedRule<TParameters extends readonly any[] = any[]> = (
...values: [...TParameters]
) => any
declare type KeyedValidator = {
validator: Validator
validatorNotDebounced: ValidatorNotDebounced
meta: {
field: FormField
}
}
declare type KeyedValidators = Set<KeyedValidator>
declare class LinkedList<T> {
first: LinkedListNode<T> | null
last: LinkedListNode<T> | null
count: number
addFirst(value: T): LinkedListNode<T>
addLast(value: T): LinkedListNode<T>
remove(node: LinkedListNode<T>): void
removeFirst(): void
removeLast(): void
nodesForwards(): Generator<LinkedListNode<T>, void, unknown>
nodesBackwards(): Generator<LinkedListNode<T>, void, unknown>
}
declare class LinkedListNode<T> {
value: T
next: LinkedListNode<T> | null
prev: LinkedListNode<T> | null
constructor(value: T)
}
declare function mapFieldRules(
fieldRules: FieldRule<unknown>[]
): RuleInformation[]
declare type MappedRuleInformation = {
promiseCancel: nDomain.PromiseCancel<never>
rule?: SimpleRule
validator: Validator
validatorNotDebounced: ValidatorNotDebounced
validationBehavior: ValidationBehaviorFunction
cancelDebounce: () => void
}
declare type MaybeRef<T> = T extends Ref<infer V> ? T | V : Ref<T> | T
declare namespace nDomain {
export {
deepCopy,
tryGet,
trySet,
path,
set,
uid,
controlledRef,
ControlledRef,
deepIterator,
DeepIteratorResult,
debounce,
Debounced,
isArray,
isDefined,
isObject,
isRecord,
LinkedList,
PromiseCancel,
CancelError,
Key,
MaybeRef,
DeepIndex,
Tuple,
Optional
}
}
declare namespace nForm {
export {
disposeForm,
getResultFormData,
resetFields,
transformFormData,
isField,
isTransformedField,
mapFieldRules,
Form,
FormField,
ValidationError,
isSimpleRule,
FieldRule,
KeyedRule,
SimpleRule,
RuleWithKey,
RuleInformation,
ValidationBehavior,
ValidationBehaviorFunction,
DefaultValidationBehaviorString,
ValidationBehaviorInfo,
ValidationBehaviorString,
Field,
TransformedField,
TransformFormData,
FieldNames,
ResultFormData
}
}
declare type Optional<T, K extends keyof T> = Partial<Pick<T, K>> &
Omit<T, K> &
(T extends (...args: any[]) => any
? {
(...args: Parameters<T>): ReturnType<T>
}
: unknown)
declare function path(path: readonly Key[], obj: Record<Key, unknown>): any
declare class PromiseCancel<T = unknown> {
private promise
private resolve
private reject
isRacing: boolean
constructor()
cancelResolve(value: T | PromiseLike<T>): void
cancelReject(reason?: any): void
race<Ps extends readonly Promise<any>[]>(
...promises: [...Ps]
): Promise<
T | ([...Ps][number] extends PromiseLike<infer U> ? U : [...Ps][number])
>
private assign
}
declare function resetFields(
form: Form,
data: any,
transformedFormData: any
): void
$validate(options?: ValidateOptions): void
} & (TExtra extends Record<string, never> ? unknown : UnwrapRef<TExtra>)
/**
* Unwrap the `$value` property of all fields in `FormData`.
*/
export declare type ResultFormData<FormData> = FormData extends any
declare type ResultFormData<FormData> = FormData extends any
? {

@@ -471,88 +206,18 @@ [K in keyof FormData]: Exclude<FormData[K], undefined> extends {

: never
declare type RuleInformation = {
validationBehavior: ValidationBehaviorFunction
rule: SimpleRule | RuleWithKey
debounce?: number
}
declare type RuleWithKey<T extends readonly any[] = any[]> = {
key: string
rule?: KeyedRule<T>
}
declare function set(obj: any, keys: readonly Key[], value: any): void
declare type ShouldInvokeResult = boolean | void
export declare type SimpleRule<TParameter = any> = (
...value: TParameter[]
) => any
declare type SimpleValidators = {
validators: Validator[]
validatorsNotDebounced: ValidatorNotDebounced[]
meta: {
field: FormField
keys: string[]
rollbacks: (() => void)[]
}
}
export declare type TransformedField<
TValue,
TExtra extends Record<string, unknown> = Record<string, never>
> = {
/**
* The unique id of this field.
*/
$uid: number
/**
* The current field's value.
*/
$value: TValue
/**
* A list of validation error messages local to this field without `null` values.
*/
$errors: string[]
/**
* The field's raw error messages one for each rule and `null` if there is no error.
*/
$rawErrors: (string | null)[]
/**
* `True` while this field has any error.
*/
$hasError: boolean
/**
* `True` while this field has any pending rules.
*/
$validating: boolean
/**
* `True` if the field is touched.
*
* @remarks
* In most cases, this value should be set together with the `blur` event.
* Either through `$validate` or manually.
*/
$touched: boolean
/**
* `True` if the `$value` of this field has changed at least once.
*/
$dirty: boolean
/**
* Validate this field.
*
* @param options - Validate options to use
* @default
* ```
* { setTouched: true, force: true }
* ```
*/
$validate(options?: ValidateOptions): void
} & (TExtra extends Record<string, never> ? unknown : UnwrapRef<TExtra>)
/**
* Receive the name of every field in `FormData` as a union of strings.
*/
declare type FieldNames<FormData> = FormData extends (infer TArray)[]
? FieldNames<TArray>
: {
[K in keyof FormData]-?: Exclude<FormData[K], undefined> extends {
$value: any
}
? K
: FieldNames<FormData[K]>
}[keyof FormData]
/**
* Transforms every field in `FormData` into transformed fields.
*/
export declare type TransformFormData<FormData> = FormData extends any
declare type TransformFormData<FormData> = FormData extends any
? {

@@ -572,41 +237,42 @@ [K in keyof FormData]: Exclude<FormData[K], undefined> extends {

declare function transformFormData(form: Form, formData: object): void
declare class ValidationError extends Error {
constructor()
}
declare const tryGet: <K, V>(
map: Map<K, V>
) => ({
success,
failure
}: {
success(value: V): void
failure?(): void
}) => (key: K) => void
declare const trySet: <K, V>(
map: Map<K, V>
) => ({
success,
failure
}: {
success?(value: V): void
failure?(value: V): void
}) => (key: K, value: V) => void
declare type Tuple<T, N extends number> = number extends N
? T[]
: _Tuple<T, N, []>
declare type _Tuple<
T,
N extends number,
R extends unknown[]
> = R['length'] extends N ? R : _Tuple<T, N, [T, ...R]>
declare function uid(): number
export declare type UseValidation<FormData extends object> = {
/**
* Vue composition function for form validation.
*
* @remarks
* For type inference in `useValidation` make sure to define the structure of your
* form data upfront and pass it as the generic parameter `FormData`.
*
* @param formData - The structure of your form data
*
* @example
* ```
* type FormData = {
* name: Field<string>,
* password: Field<string>
* }
*
* const { form } = useValidation<FormData>({
* name: {
* $value: '',
* $rules: []
* },
* password: {
* $value: '',
* $rules: []
* }
* })
* ```
*/
declare function useValidation<FormData extends object>(
formData: FormData
): UseValidation<FormData>
declare type UseValidation<FormData extends object> = {
/**
* A transformed reactive `formData` object.
* A transformed reactive form data object.
*/
form: nForm.TransformFormData<FormData>
form: TransformFormData<FormData>
/**

@@ -643,3 +309,3 @@ * `True` during validation after calling `validateFields` when there were rules returning a `Promise`.

*/
names?: nForm.FieldNames<FormData>[]
names?: FieldNames<FormData>[]
/**

@@ -657,5 +323,5 @@ * Filter which values to keep in the resulting form data.

predicate?: (
value: Omit<nDomain.DeepIteratorResult, 'isLeaf' | 'parent'>
value: Omit<DeepIteratorResult, 'isLeaf' | 'parent'>
) => unknown
}): Promise<nForm.ResultFormData<FormData>>
}): Promise<ResultFormData<FormData>>
/**

@@ -667,5 +333,5 @@ * Reset all fields to their default value or pass an object to set specific values.

*
* @param formData - `FormData` to set specific values. It has the same structure as the object passed to `useValidation`
* @param formData - Form data to set specific values. It has the same structure as the object passed to `useValidation`
*/
resetFields(formData?: Partial<nForm.ResultFormData<FormData>>): void
resetFields(formData?: Partial<ResultFormData<FormData>>): void
/**

@@ -682,5 +348,5 @@ * Adds a new property to the form data.

path: readonly [...Keys],
value: nDomain.DeepIndex<FormData, Keys> extends (infer TArray)[]
value: DeepIndex<FormData, Keys> extends (infer TArray)[]
? TArray
: nDomain.DeepIndex<FormData, Keys>
: DeepIndex<FormData, Keys>
): void

@@ -695,118 +361,44 @@ /**

declare type ConfigurationValidationBehavior = Optional<
{
[K in ValidationBehaviorString]: ValidationBehaviorFunction
},
DefaultValidationBehaviorString
>
declare type Configuration =
keyof CustomValidationBehaviorFunctions extends never
? {
defaultValidationBehavior: ValidationBehaviorString
validationBehavior?: ConfigurationValidationBehavior
}
: {
defaultValidationBehavior: ValidationBehaviorString
validationBehavior: ConfigurationValidationBehavior
}
/**
* Vue composition function for form validation.
* Configure the validation behavior of `useValidation`.
*
* @remarks
* For type inference in `useValidation` make sure to define the structure of your
* form data upfront and pass it as the generic parameter `FormData`.
*
* @param formData - The structure of your form data
*
* @example
* ```
* type FormData = {
* name: Field<string>,
* password: Field<string>
* }
*
* const { form } = useValidation<FormData>({
* name: {
* $value: '',
* $rules: []
* },
* password: {
* $value: '',
* $rules: []
* }
* })
* ```
* @param configuration - The form validation configuration
*/
export declare function useValidation<FormData extends object>(
formData: FormData
): UseValidation<FormData>
declare function createValidation(configuration: Configuration): Plugin
declare type ValidateOptions = {
/**
* Set the field touched when called.
*
* @default true
*/
setTouched?: boolean
/**
* Validate with the `force` flag set.
*
* @default true
*/
force?: boolean
export {
Configuration,
ConfigurationValidationBehavior,
CustomValidationBehaviorFunctions,
Field,
FieldNames,
KeyedRule,
ResultFormData,
SimpleRule,
TransformFormData,
TransformedField,
UseValidation,
ValidationBehavior,
ValidationBehaviorFunction,
ValidationBehaviorInfo,
ValidationBehaviorString,
ValidationError,
createValidation,
useValidation
}
export declare type ValidationBehavior =
| ValidationBehaviorString
| ValidationBehaviorFunction
export declare type ValidationBehaviorFunction = (
info: ValidationBehaviorInfo
) => any
export declare type ValidationBehaviorInfo<T = any> = {
/**
* `True` if the paired rule of this behavior has an error.
*/
hasError: boolean
/**
* The touched state of the field.
*/
touched: boolean
/**
* The dirty state of the field.
*/
dirty: boolean
/**
* `True` if the validation was triggered with the `force` flag.
*/
force: boolean
/**
* `True` if the validation was triggered with the `submit` flag.
*/
submit: boolean
/**
* The `$value` property of the field.
*/
value: T
}
export declare type ValidationBehaviorString =
| DefaultValidationBehaviorString
| keyof UseValidation_CustomValidationBehaviorFunctions
export declare class ValidationError extends Error {
constructor()
}
declare type Validator = nDomain.Optional<
nDomain.Debounced<ValidatorParameters>,
'cancel'
>
declare type ValidatorNotDebounced = (
...params: ValidatorParameters
) => ValidatorReturn
declare type ValidatorParameters = [
/**
* Type definition is not accurate here but catches invalid use of validators.
* The accurate type would be an array of anything expect Refs.
*/
modelValues: (string | number | Record<string, unknown>)[],
force: boolean,
submit: boolean
]
declare type ValidatorReturn = Promise<void | string> | void
export {}
declare global {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface UseValidation_CustomValidationBehaviorFunctions {}
}
{
"name": "vue3-form-validation",
"version": "5.0.6",
"version": "5.0.7",
"description": "Vue composition function for form validation",

@@ -5,0 +5,0 @@ "author": {

@@ -19,2 +19,2 @@ # Form Validation for Vue 3

### :point_right: [Check out the Examples on StackBlitz](https://stackblitz.com/github/JensDll/vue3-form-validation/tree/main/packages/examples?file=src%2Fmain.ts&title=Form%20Validation%20Examples)
### :point_right: [Check out the Examples on StackBlitz](https://stackblitz.com/edit/github-ukbo8g?file=src%2Fpages%2FHomeForm.vue&title=Form%20Validation%20Examples)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc