adaptform 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/FieldOptions.d.ts +23 -0
- package/dist/core/Form.d.ts +13 -0
- package/dist/core/FormField.d.ts +23 -0
- package/dist/core/date/DateTimeField.d.ts +18 -0
- package/dist/core/number/NumberField.d.ts +13 -0
- package/dist/core/string/StringField.d.ts +18 -0
- package/dist/index.d.ts +6 -111
- package/package.json +2 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface FormFieldOptions {
|
|
2
|
+
isRequired?: boolean;
|
|
3
|
+
validators?: Array<(value: any) => string | null>;
|
|
4
|
+
}
|
|
5
|
+
export interface StringFieldOptions extends FormFieldOptions {
|
|
6
|
+
minLength?: number;
|
|
7
|
+
maxLength?: number;
|
|
8
|
+
regex?: RegExp | string;
|
|
9
|
+
mask?: string;
|
|
10
|
+
example?: string;
|
|
11
|
+
returnWithMask?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface NumberFieldOptions extends FormFieldOptions {
|
|
14
|
+
min?: number;
|
|
15
|
+
max?: number;
|
|
16
|
+
example?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface DateTimeFieldOptions extends FormFieldOptions {
|
|
19
|
+
mode?: "date" | "datetime";
|
|
20
|
+
min?: Date | string | number;
|
|
21
|
+
max?: Date | string | number;
|
|
22
|
+
example?: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare abstract class Form<TFields extends Record<string, any> = any> {
|
|
2
|
+
private readonly _errors;
|
|
3
|
+
protected get declaredFields(): (keyof TFields)[];
|
|
4
|
+
checkValid(): boolean;
|
|
5
|
+
get valueObject(): Record<keyof TFields, any>;
|
|
6
|
+
get valueArray(): any[];
|
|
7
|
+
get errors(): Record<string, any>;
|
|
8
|
+
set errors(errors: Record<string, any>);
|
|
9
|
+
set fields(values: Partial<Record<keyof TFields, any>>);
|
|
10
|
+
setFieldValue<K extends keyof TFields>(key: K, value: any): void;
|
|
11
|
+
getFieldValue<K extends keyof TFields>(key: K): any;
|
|
12
|
+
reset(): this;
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FormFieldOptions } from './FieldOptions';
|
|
2
|
+
export declare abstract class FormField<Value = any, ClearValue = Value> {
|
|
3
|
+
protected _value: Value | null;
|
|
4
|
+
protected defaultValue: Value | null;
|
|
5
|
+
protected _error: string | null;
|
|
6
|
+
isRequired: boolean;
|
|
7
|
+
isValid: boolean | null;
|
|
8
|
+
validators: Array<(value: Value | null) => string | null>;
|
|
9
|
+
protected constructor(defaultValue?: Value | null, options?: FormFieldOptions);
|
|
10
|
+
get value(): Value | null;
|
|
11
|
+
set value(value: Value | null);
|
|
12
|
+
get error(): string;
|
|
13
|
+
set error(value: string | null);
|
|
14
|
+
set __valid_error(value: string | null);
|
|
15
|
+
reset(): void;
|
|
16
|
+
protected normalizeValue(value: Value | null): Value | null;
|
|
17
|
+
protected fieldIsEmpty(value: Value | null): boolean;
|
|
18
|
+
get isEmpty(): boolean;
|
|
19
|
+
protected fieldIsZero(value: Value | null): boolean;
|
|
20
|
+
get isZero(): boolean;
|
|
21
|
+
checkValid(): boolean;
|
|
22
|
+
abstract get valueClear(): ClearValue | null;
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FormField } from '../FormField';
|
|
2
|
+
import { DateTimeFieldOptions } from '../FieldOptions';
|
|
3
|
+
type DateValue = Date | string | number | null;
|
|
4
|
+
export declare class DateTimeField extends FormField<Date, string> {
|
|
5
|
+
mode: "date" | "datetime";
|
|
6
|
+
min: Date | null;
|
|
7
|
+
max: Date | null;
|
|
8
|
+
example: string;
|
|
9
|
+
constructor(defaultValue?: DateValue, options?: DateTimeFieldOptions);
|
|
10
|
+
protected normalizeValue(value: any): Date | null;
|
|
11
|
+
get valueClear(): string | null;
|
|
12
|
+
private typeValidator;
|
|
13
|
+
private minValidator;
|
|
14
|
+
/** 🔹 Максимальная дата */
|
|
15
|
+
private maxValidator;
|
|
16
|
+
private formatDate;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FormField } from '../FormField';
|
|
2
|
+
import { NumberFieldOptions } from '../FieldOptions';
|
|
3
|
+
export declare class NumberField extends FormField<number> {
|
|
4
|
+
min: number | null;
|
|
5
|
+
max: number | null;
|
|
6
|
+
example: string;
|
|
7
|
+
constructor(defaultValue?: number | null, options?: NumberFieldOptions);
|
|
8
|
+
protected normalizeValue(value: any): number | null;
|
|
9
|
+
get valueClear(): number | null;
|
|
10
|
+
private typeValidator;
|
|
11
|
+
private minValidator;
|
|
12
|
+
private maxValidator;
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FormField } from '../FormField';
|
|
2
|
+
import { StringFieldOptions } from '../FieldOptions';
|
|
3
|
+
export declare class StringField extends FormField<string> {
|
|
4
|
+
minLength: number | null;
|
|
5
|
+
maxLength: number | null;
|
|
6
|
+
regex: RegExp;
|
|
7
|
+
example: string;
|
|
8
|
+
mask: string | null;
|
|
9
|
+
returnWithMask: boolean;
|
|
10
|
+
constructor(defaultValue?: string, options?: StringFieldOptions);
|
|
11
|
+
protected normalizeValue(value: string | null): string | null;
|
|
12
|
+
get valueClear(): string | null;
|
|
13
|
+
get value(): string | null;
|
|
14
|
+
set value(value: string | null);
|
|
15
|
+
private minLengthValidator;
|
|
16
|
+
private maxLengthValidator;
|
|
17
|
+
private regexValidator;
|
|
18
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,111 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
protected normalizeValue(value: any): Date | null;
|
|
8
|
-
get valueClear(): string | null;
|
|
9
|
-
private typeValidator;
|
|
10
|
-
private minValidator;
|
|
11
|
-
/** 🔹 Максимальная дата */
|
|
12
|
-
private maxValidator;
|
|
13
|
-
private formatDate;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export declare interface DateTimeFieldOptions extends FormFieldOptions {
|
|
17
|
-
mode?: "date" | "datetime";
|
|
18
|
-
min?: Date | string | number;
|
|
19
|
-
max?: Date | string | number;
|
|
20
|
-
example?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
declare type DateValue = Date | string | number | null;
|
|
24
|
-
|
|
25
|
-
export declare abstract class Form<TFields extends Record<string, any> = any> {
|
|
26
|
-
private readonly _errors;
|
|
27
|
-
protected get declaredFields(): (keyof TFields)[];
|
|
28
|
-
checkValid(): boolean;
|
|
29
|
-
get valueObject(): Record<keyof TFields, any>;
|
|
30
|
-
get valueArray(): any[];
|
|
31
|
-
get errors(): Record<string, any>;
|
|
32
|
-
set errors(errors: Record<string, any>);
|
|
33
|
-
set fields(values: Partial<Record<keyof TFields, any>>);
|
|
34
|
-
setFieldValue<K extends keyof TFields>(key: K, value: any): void;
|
|
35
|
-
getFieldValue<K extends keyof TFields>(key: K): any;
|
|
36
|
-
reset(): this;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export declare abstract class FormField<Value = any, ClearValue = Value> {
|
|
40
|
-
protected _value: Value | null;
|
|
41
|
-
protected defaultValue: Value | null;
|
|
42
|
-
protected _error: string | null;
|
|
43
|
-
isRequired: boolean;
|
|
44
|
-
isValid: boolean | null;
|
|
45
|
-
validators: Array<(value: Value | null) => string | null>;
|
|
46
|
-
protected constructor(defaultValue?: Value | null, options?: FormFieldOptions);
|
|
47
|
-
get value(): Value | null;
|
|
48
|
-
set value(value: Value | null);
|
|
49
|
-
get error(): string;
|
|
50
|
-
set error(value: string | null);
|
|
51
|
-
set __valid_error(value: string | null);
|
|
52
|
-
reset(): void;
|
|
53
|
-
protected normalizeValue(value: Value | null): Value | null;
|
|
54
|
-
protected fieldIsEmpty(value: Value | null): boolean;
|
|
55
|
-
get isEmpty(): boolean;
|
|
56
|
-
protected fieldIsZero(value: Value | null): boolean;
|
|
57
|
-
get isZero(): boolean;
|
|
58
|
-
checkValid(): boolean;
|
|
59
|
-
abstract get valueClear(): ClearValue | null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export declare interface FormFieldOptions {
|
|
63
|
-
isRequired?: boolean;
|
|
64
|
-
validators?: Array<(value: any) => string | null>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export declare class NumberField extends FormField<number> {
|
|
68
|
-
min: number | null;
|
|
69
|
-
max: number | null;
|
|
70
|
-
example: string;
|
|
71
|
-
constructor(defaultValue?: number | null, options?: NumberFieldOptions);
|
|
72
|
-
protected normalizeValue(value: any): number | null;
|
|
73
|
-
get valueClear(): number | null;
|
|
74
|
-
private typeValidator;
|
|
75
|
-
private minValidator;
|
|
76
|
-
private maxValidator;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export declare interface NumberFieldOptions extends FormFieldOptions {
|
|
80
|
-
min?: number;
|
|
81
|
-
max?: number;
|
|
82
|
-
example?: string;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export declare class StringField extends FormField<string> {
|
|
86
|
-
minLength: number | null;
|
|
87
|
-
maxLength: number | null;
|
|
88
|
-
regex: RegExp;
|
|
89
|
-
example: string;
|
|
90
|
-
mask: string | null;
|
|
91
|
-
returnWithMask: boolean;
|
|
92
|
-
constructor(defaultValue?: string, options?: StringFieldOptions);
|
|
93
|
-
protected normalizeValue(value: string | null): string | null;
|
|
94
|
-
get valueClear(): string | null;
|
|
95
|
-
get value(): string | null;
|
|
96
|
-
set value(value: string | null);
|
|
97
|
-
private minLengthValidator;
|
|
98
|
-
private maxLengthValidator;
|
|
99
|
-
private regexValidator;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export declare interface StringFieldOptions extends FormFieldOptions {
|
|
103
|
-
minLength?: number;
|
|
104
|
-
maxLength?: number;
|
|
105
|
-
regex?: RegExp | string;
|
|
106
|
-
mask?: string;
|
|
107
|
-
example?: string;
|
|
108
|
-
returnWithMask?: boolean;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export { }
|
|
1
|
+
export * from './core/FieldOptions';
|
|
2
|
+
export * from './core/FormField';
|
|
3
|
+
export * from './core/string/StringField';
|
|
4
|
+
export * from './core/number/NumberField';
|
|
5
|
+
export * from './core/date/DateTimeField';
|
|
6
|
+
export * from './core/Form';
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adaptform",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Library of adaptive forms of validation",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
6
|
+
"main": "./dist/index.d.ts",
|
|
7
7
|
"module": "./dist/index.es.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|