UNPKG

792 BTypeScriptView Raw
1/**
2 * @name useSValidation
3 * @author Fajar Rizky Hidayat <fajarrizkyhidayat@gmail.com>
4 */
5
6type EventValidation<T = any> = {
7 ctr?: AbortController;
8 data?: Partial<T>;
9 parser?: (value: any) => void;
10};
11
12type UseSValidationProps<T> = {
13 service?: (event?: EventValidation<T>) => any;
14 data: T;
15 message?: Record<string, (params: any) => string>;
16 param?: {
17 type: string;
18 path: string;
19 };
20};
21
22interface UseSValidation<T> {
23 processing: boolean;
24 error: (key?: keyof T) => boolean;
25 message: (key: keyof T) => string;
26 clear: () => void;
27 cancel: () => void;
28 validate: (option?: {
29 service?: (event?: EventValidation<T>) => any;
30 }) => Promise<boolean>;
31}
32
33export default function useSValidation<T = any>(
34 props: UseSValidationProps<T>
35): UseSValidation<T>;