UNPKG

2.12 kBTypeScriptView Raw
1import { INPUT_VALIDATION_RULES } from '../constants';
2import { Message } from './errors';
3import { FieldValues } from './fields';
4import { FieldPath, FieldPathValue } from './path';
5export type ValidationValue = boolean | number | string | RegExp;
6export type ValidationRule<TValidationValue extends ValidationValue = ValidationValue> = TValidationValue | ValidationValueMessage<TValidationValue>;
7export type ValidationValueMessage<TValidationValue extends ValidationValue = ValidationValue> = {
8 value: TValidationValue;
9 message: Message;
10};
11export type ValidateResult = Message | Message[] | boolean | undefined;
12export type Validate<TFieldValue, TFormValues> = (value: TFieldValue, formValues: TFormValues) => ValidateResult | Promise<ValidateResult>;
13export type RegisterOptions<TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Partial<{
14 required: Message | ValidationRule<boolean>;
15 min: ValidationRule<number | string>;
16 max: ValidationRule<number | string>;
17 maxLength: ValidationRule<number>;
18 minLength: ValidationRule<number>;
19 validate: Validate<FieldPathValue<TFieldValues, TFieldName>, TFieldValues> | Record<string, Validate<FieldPathValue<TFieldValues, TFieldName>, TFieldValues>>;
20 value: FieldPathValue<TFieldValues, TFieldName>;
21 setValueAs: (value: any) => any;
22 shouldUnregister?: boolean;
23 onChange?: (event: any) => void;
24 onBlur?: (event: any) => void;
25 disabled: boolean;
26 deps: FieldPath<TFieldValues> | FieldPath<TFieldValues>[];
27}> & ({
28 pattern?: ValidationRule<RegExp>;
29 valueAsNumber?: false;
30 valueAsDate?: false;
31} | {
32 pattern?: undefined;
33 valueAsNumber?: false;
34 valueAsDate?: true;
35} | {
36 pattern?: undefined;
37 valueAsNumber?: true;
38 valueAsDate?: false;
39});
40export type InputValidationRules = typeof INPUT_VALIDATION_RULES;
41export type MaxType = InputValidationRules['max'] | InputValidationRules['maxLength'];
42export type MinType = InputValidationRules['min'] | InputValidationRules['minLength'];
43//# sourceMappingURL=validator.d.ts.map
\No newline at end of file