Skip to content

Commit b7f6dff

Browse files
Alisher AripovAlisher Aripov
authored andcommitted
REFACTOR: added types declarations
1 parent 2a00e52 commit b7f6dff

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

dist/types.d.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ComputedRef, Ref, UnwrapNestedRefs, UnwrapRef} from 'vue-demi';
22

3-
export interface IRulesList {
3+
export declare interface IRulesList {
44
required?: (value: string) => boolean;
55
minLength?: (value: string, minLength: number) => boolean;
66
maxLength?: (value: string, maxLength: number) => boolean;
@@ -10,35 +10,36 @@ export interface IRulesList {
1010
date?: (value: string) => boolean;
1111
}
1212

13-
export type TObjectModel = Record<string, { model: TModel; rules: TRule[] }>;
14-
export type TModel = string | number | boolean | null | Date | Object | TObjectModel;
15-
export type TValidateObjectRefModel = Record<string, { model: TModel; rules: TRule[] }>;
13+
export declare type TObjectModel = Record<string, { model: TModel; rules: TRule[] }>;
14+
export declare type TModel = string | number | boolean | null | Date | Object | TObjectModel;
15+
export declare type TValidateObjectRefModel = Record<string, { model: TModel; rules: TRule[] }>;
1616

17-
export type TSimpleRules = 'required' | 'email' | 'numeric' | 'date';
18-
export type THardRules = 'minLength' | 'maxLength' | 'maxValue';
19-
export type TRule = TSimpleRules | { type: THardRules; value: number };
20-
export type TModelRule = 'required' | 'email' | 'numeric' | 'date' | 'minLength' | 'maxLength' | 'maxValue';
17+
export declare type TSimpleRules = 'required' | 'email' | 'numeric' | 'date';
18+
export declare type THardRules = 'minLength' | 'maxLength' | 'maxValue';
19+
export declare type TRule = TSimpleRules | { type: THardRules; value: number };
20+
export declare type TModelRule = 'required' | 'email' | 'numeric' | 'date' | 'minLength' | 'maxLength' | 'maxValue';
2121

22-
export type TValidatedItem<T> = {
22+
export declare type TValidatedItem<T> = {
2323
model: Ref<T>;
2424
isValid: Ref<boolean>;
2525
modelRules: UnwrapRef<Record<TModelRule, boolean>>;
2626
};
2727

28-
export type TRules =
28+
export declare type TRules =
2929
| { [key in TSimpleRules]: Pick<IRulesList, key> }
3030
| {
3131
type: Pick<IRulesList, THardRules>;
3232
rule: TModelRule;
3333
};
3434

35-
export type TValidatedObjectRef<T> = UnwrapNestedRefs<TValidatedReactiveObject<T>> & {
35+
export declare type TValidatedObjectRef<T> = UnwrapNestedRefs<TValidatedReactiveObject<T>> & {
3636
__isValid: ComputedRef<boolean>;
3737
__clean: ComputedRef<UnwrapRef<T>>;
3838
};
3939

40-
export type TValidatedReactiveObject<T> = {
40+
export declare type TValidatedReactiveObject<T> = {
4141
[P in keyof T]: TValidatedItem<T[P]>;
4242
};
4343

44-
export { useValidate, useValidateObject } from "./index"
44+
export declare function useValidate<T>(model: T, rules: TRule[]): UnwrapRef<TValidatedItem<T>>
45+
export declare function useValidateObject<T>(model: TValidateObjectRefModel): UnwrapNestedRefs<TValidatedObjectRef<T>>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "light-vue3-validation",
3-
"version": "1.0.3",
3+
"version": "1.0.5",
44
"private": false,
55
"description": "Form validations for vue 3",
66
"main": "dist/index.js",

0 commit comments

Comments
 (0)