@excofy/utils 1.0.8 → 1.0.9
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/index.d.cts +31 -84
- package/dist/index.d.ts +31 -84
- package/package.json +1 -1
- package/src/helpers/validator.ts +37 -1
package/dist/index.d.cts
CHANGED
|
@@ -17,6 +17,34 @@ type TTypes = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'file' | 'd
|
|
|
17
17
|
interface IInputErrors {
|
|
18
18
|
[key: string]: TMessage[] | IInputErrors[];
|
|
19
19
|
}
|
|
20
|
+
interface ValidatorField {
|
|
21
|
+
cnpj(message: string): ValidatorField;
|
|
22
|
+
cpf(message: string): ValidatorField;
|
|
23
|
+
each(callback: <U extends Record<string, TInputValue>>(item: U, index: number, subValidator: ReturnType<typeof createValidator<U>>) => void): ValidatorField;
|
|
24
|
+
email(message: string): ValidatorField;
|
|
25
|
+
fileMaxSize(maxSize: number, message: string): ValidatorField;
|
|
26
|
+
fileType(validTypes: string[], message: string): ValidatorField;
|
|
27
|
+
length(length: number, message: string): ValidatorField;
|
|
28
|
+
min(min: number, message: string): ValidatorField;
|
|
29
|
+
max(max: number, message: string): ValidatorField;
|
|
30
|
+
transform<U>(fn: (value: TInputValue) => U): ValidatorField;
|
|
31
|
+
slug(message: string): ValidatorField;
|
|
32
|
+
sanitize(): ValidatorField;
|
|
33
|
+
sanitizePreservingNewlines(): ValidatorField;
|
|
34
|
+
sanitizeHTML(tags?: AllowedTag[]): ValidatorField;
|
|
35
|
+
url(message: string): ValidatorField;
|
|
36
|
+
uuid(message: string): ValidatorField;
|
|
37
|
+
oneOf(types: string[], message: string): ValidatorField;
|
|
38
|
+
test(validateFn: (value: TValue, context: {
|
|
39
|
+
field: string;
|
|
40
|
+
}) => boolean, message: string): ValidatorField;
|
|
41
|
+
videoUrl: {
|
|
42
|
+
youtube(message: string): ValidatorField;
|
|
43
|
+
};
|
|
44
|
+
asNumber(message: string): ValidatorField;
|
|
45
|
+
asBoolean(message: string): ValidatorField;
|
|
46
|
+
asStringArray(message: string): ValidatorField;
|
|
47
|
+
}
|
|
20
48
|
/**
|
|
21
49
|
* Cria um validador de inputs com suporte a validações encadeadas, transformação e sanitização.
|
|
22
50
|
*
|
|
@@ -43,94 +71,13 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
|
|
|
43
71
|
unflattenErrors(flat: Record<string, TMessage[]>): Record<string, unknown>;
|
|
44
72
|
validate<K extends keyof TRaw>(field: K): {
|
|
45
73
|
isRequired(message: string): {
|
|
46
|
-
type(type: TTypes, message: string):
|
|
47
|
-
cnpj: (message: string) => /*elided*/ any;
|
|
48
|
-
cpf: (message: string) => /*elided*/ any;
|
|
49
|
-
each(callback: <U extends Record<string, TInputValue>>(item: U, index: number, subValidator: ReturnType<typeof createValidator<U>>) => void): /*elided*/ any;
|
|
50
|
-
email: (message: string) => /*elided*/ any;
|
|
51
|
-
fileMaxSize: (maxSize: number, message: string) => /*elided*/ any;
|
|
52
|
-
fileType: (validTypes: string[], message: string) => /*elided*/ any;
|
|
53
|
-
length(length: number, message: string): /*elided*/ any;
|
|
54
|
-
min(min: number, message: string): /*elided*/ any;
|
|
55
|
-
max(max: number, message: string): /*elided*/ any;
|
|
56
|
-
transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
|
|
57
|
-
slug(message: string): /*elided*/ any;
|
|
58
|
-
sanitize(): /*elided*/ any;
|
|
59
|
-
sanitizePreservingNewlines(): /*elided*/ any;
|
|
60
|
-
sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
|
|
61
|
-
url(message: string): /*elided*/ any;
|
|
62
|
-
uuid(message: string): /*elided*/ any;
|
|
63
|
-
oneOf: (types: string[], message: string) => /*elided*/ any;
|
|
64
|
-
test(validateFn: (value: TInputValue, context: {
|
|
65
|
-
field: string;
|
|
66
|
-
}) => boolean, message: string): /*elided*/ any;
|
|
67
|
-
videoUrl: {
|
|
68
|
-
youtube(message: string): /*elided*/ any;
|
|
69
|
-
};
|
|
70
|
-
asNumber(message: string): /*elided*/ any;
|
|
71
|
-
asBoolean(message: string): /*elided*/ any;
|
|
72
|
-
asStringArray(message: string): /*elided*/ any;
|
|
73
|
-
};
|
|
74
|
+
type(type: TTypes, message: string): ValidatorField;
|
|
74
75
|
};
|
|
75
76
|
isNotRequired(): {
|
|
76
|
-
type(type: TTypes, message: string):
|
|
77
|
-
cnpj: (message: string) => /*elided*/ any;
|
|
78
|
-
cpf: (message: string) => /*elided*/ any;
|
|
79
|
-
each(callback: <U extends Record<string, TInputValue>>(item: U, index: number, subValidator: ReturnType<typeof createValidator<U>>) => void): /*elided*/ any;
|
|
80
|
-
email: (message: string) => /*elided*/ any;
|
|
81
|
-
fileMaxSize: (maxSize: number, message: string) => /*elided*/ any;
|
|
82
|
-
fileType: (validTypes: string[], message: string) => /*elided*/ any;
|
|
83
|
-
length(length: number, message: string): /*elided*/ any;
|
|
84
|
-
min(min: number, message: string): /*elided*/ any;
|
|
85
|
-
max(max: number, message: string): /*elided*/ any;
|
|
86
|
-
transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
|
|
87
|
-
slug(message: string): /*elided*/ any;
|
|
88
|
-
sanitize(): /*elided*/ any;
|
|
89
|
-
sanitizePreservingNewlines(): /*elided*/ any;
|
|
90
|
-
sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
|
|
91
|
-
url(message: string): /*elided*/ any;
|
|
92
|
-
uuid(message: string): /*elided*/ any;
|
|
93
|
-
oneOf: (types: string[], message: string) => /*elided*/ any;
|
|
94
|
-
test(validateFn: (value: TInputValue, context: {
|
|
95
|
-
field: string;
|
|
96
|
-
}) => boolean, message: string): /*elided*/ any;
|
|
97
|
-
videoUrl: {
|
|
98
|
-
youtube(message: string): /*elided*/ any;
|
|
99
|
-
};
|
|
100
|
-
asNumber(message: string): /*elided*/ any;
|
|
101
|
-
asBoolean(message: string): /*elided*/ any;
|
|
102
|
-
asStringArray(message: string): /*elided*/ any;
|
|
103
|
-
};
|
|
77
|
+
type(type: TTypes, message: string): ValidatorField;
|
|
104
78
|
};
|
|
105
79
|
conditionallyRequired(isRequired: boolean, message: string): {
|
|
106
|
-
type(type: TTypes, message: string):
|
|
107
|
-
cnpj: (message: string) => /*elided*/ any;
|
|
108
|
-
cpf: (message: string) => /*elided*/ any;
|
|
109
|
-
each(callback: <U extends Record<string, TInputValue>>(item: U, index: number, subValidator: ReturnType<typeof createValidator<U>>) => void): /*elided*/ any;
|
|
110
|
-
email: (message: string) => /*elided*/ any;
|
|
111
|
-
fileMaxSize: (maxSize: number, message: string) => /*elided*/ any;
|
|
112
|
-
fileType: (validTypes: string[], message: string) => /*elided*/ any;
|
|
113
|
-
length(length: number, message: string): /*elided*/ any;
|
|
114
|
-
min(min: number, message: string): /*elided*/ any;
|
|
115
|
-
max(max: number, message: string): /*elided*/ any;
|
|
116
|
-
transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
|
|
117
|
-
slug(message: string): /*elided*/ any;
|
|
118
|
-
sanitize(): /*elided*/ any;
|
|
119
|
-
sanitizePreservingNewlines(): /*elided*/ any;
|
|
120
|
-
sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
|
|
121
|
-
url(message: string): /*elided*/ any;
|
|
122
|
-
uuid(message: string): /*elided*/ any;
|
|
123
|
-
oneOf: (types: string[], message: string) => /*elided*/ any;
|
|
124
|
-
test(validateFn: (value: TInputValue, context: {
|
|
125
|
-
field: string;
|
|
126
|
-
}) => boolean, message: string): /*elided*/ any;
|
|
127
|
-
videoUrl: {
|
|
128
|
-
youtube(message: string): /*elided*/ any;
|
|
129
|
-
};
|
|
130
|
-
asNumber(message: string): /*elided*/ any;
|
|
131
|
-
asBoolean(message: string): /*elided*/ any;
|
|
132
|
-
asStringArray(message: string): /*elided*/ any;
|
|
133
|
-
};
|
|
80
|
+
type(type: TTypes, message: string): ValidatorField;
|
|
134
81
|
};
|
|
135
82
|
};
|
|
136
83
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,34 @@ type TTypes = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'file' | 'd
|
|
|
17
17
|
interface IInputErrors {
|
|
18
18
|
[key: string]: TMessage[] | IInputErrors[];
|
|
19
19
|
}
|
|
20
|
+
interface ValidatorField {
|
|
21
|
+
cnpj(message: string): ValidatorField;
|
|
22
|
+
cpf(message: string): ValidatorField;
|
|
23
|
+
each(callback: <U extends Record<string, TInputValue>>(item: U, index: number, subValidator: ReturnType<typeof createValidator<U>>) => void): ValidatorField;
|
|
24
|
+
email(message: string): ValidatorField;
|
|
25
|
+
fileMaxSize(maxSize: number, message: string): ValidatorField;
|
|
26
|
+
fileType(validTypes: string[], message: string): ValidatorField;
|
|
27
|
+
length(length: number, message: string): ValidatorField;
|
|
28
|
+
min(min: number, message: string): ValidatorField;
|
|
29
|
+
max(max: number, message: string): ValidatorField;
|
|
30
|
+
transform<U>(fn: (value: TInputValue) => U): ValidatorField;
|
|
31
|
+
slug(message: string): ValidatorField;
|
|
32
|
+
sanitize(): ValidatorField;
|
|
33
|
+
sanitizePreservingNewlines(): ValidatorField;
|
|
34
|
+
sanitizeHTML(tags?: AllowedTag[]): ValidatorField;
|
|
35
|
+
url(message: string): ValidatorField;
|
|
36
|
+
uuid(message: string): ValidatorField;
|
|
37
|
+
oneOf(types: string[], message: string): ValidatorField;
|
|
38
|
+
test(validateFn: (value: TValue, context: {
|
|
39
|
+
field: string;
|
|
40
|
+
}) => boolean, message: string): ValidatorField;
|
|
41
|
+
videoUrl: {
|
|
42
|
+
youtube(message: string): ValidatorField;
|
|
43
|
+
};
|
|
44
|
+
asNumber(message: string): ValidatorField;
|
|
45
|
+
asBoolean(message: string): ValidatorField;
|
|
46
|
+
asStringArray(message: string): ValidatorField;
|
|
47
|
+
}
|
|
20
48
|
/**
|
|
21
49
|
* Cria um validador de inputs com suporte a validações encadeadas, transformação e sanitização.
|
|
22
50
|
*
|
|
@@ -43,94 +71,13 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
|
|
|
43
71
|
unflattenErrors(flat: Record<string, TMessage[]>): Record<string, unknown>;
|
|
44
72
|
validate<K extends keyof TRaw>(field: K): {
|
|
45
73
|
isRequired(message: string): {
|
|
46
|
-
type(type: TTypes, message: string):
|
|
47
|
-
cnpj: (message: string) => /*elided*/ any;
|
|
48
|
-
cpf: (message: string) => /*elided*/ any;
|
|
49
|
-
each(callback: <U extends Record<string, TInputValue>>(item: U, index: number, subValidator: ReturnType<typeof createValidator<U>>) => void): /*elided*/ any;
|
|
50
|
-
email: (message: string) => /*elided*/ any;
|
|
51
|
-
fileMaxSize: (maxSize: number, message: string) => /*elided*/ any;
|
|
52
|
-
fileType: (validTypes: string[], message: string) => /*elided*/ any;
|
|
53
|
-
length(length: number, message: string): /*elided*/ any;
|
|
54
|
-
min(min: number, message: string): /*elided*/ any;
|
|
55
|
-
max(max: number, message: string): /*elided*/ any;
|
|
56
|
-
transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
|
|
57
|
-
slug(message: string): /*elided*/ any;
|
|
58
|
-
sanitize(): /*elided*/ any;
|
|
59
|
-
sanitizePreservingNewlines(): /*elided*/ any;
|
|
60
|
-
sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
|
|
61
|
-
url(message: string): /*elided*/ any;
|
|
62
|
-
uuid(message: string): /*elided*/ any;
|
|
63
|
-
oneOf: (types: string[], message: string) => /*elided*/ any;
|
|
64
|
-
test(validateFn: (value: TInputValue, context: {
|
|
65
|
-
field: string;
|
|
66
|
-
}) => boolean, message: string): /*elided*/ any;
|
|
67
|
-
videoUrl: {
|
|
68
|
-
youtube(message: string): /*elided*/ any;
|
|
69
|
-
};
|
|
70
|
-
asNumber(message: string): /*elided*/ any;
|
|
71
|
-
asBoolean(message: string): /*elided*/ any;
|
|
72
|
-
asStringArray(message: string): /*elided*/ any;
|
|
73
|
-
};
|
|
74
|
+
type(type: TTypes, message: string): ValidatorField;
|
|
74
75
|
};
|
|
75
76
|
isNotRequired(): {
|
|
76
|
-
type(type: TTypes, message: string):
|
|
77
|
-
cnpj: (message: string) => /*elided*/ any;
|
|
78
|
-
cpf: (message: string) => /*elided*/ any;
|
|
79
|
-
each(callback: <U extends Record<string, TInputValue>>(item: U, index: number, subValidator: ReturnType<typeof createValidator<U>>) => void): /*elided*/ any;
|
|
80
|
-
email: (message: string) => /*elided*/ any;
|
|
81
|
-
fileMaxSize: (maxSize: number, message: string) => /*elided*/ any;
|
|
82
|
-
fileType: (validTypes: string[], message: string) => /*elided*/ any;
|
|
83
|
-
length(length: number, message: string): /*elided*/ any;
|
|
84
|
-
min(min: number, message: string): /*elided*/ any;
|
|
85
|
-
max(max: number, message: string): /*elided*/ any;
|
|
86
|
-
transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
|
|
87
|
-
slug(message: string): /*elided*/ any;
|
|
88
|
-
sanitize(): /*elided*/ any;
|
|
89
|
-
sanitizePreservingNewlines(): /*elided*/ any;
|
|
90
|
-
sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
|
|
91
|
-
url(message: string): /*elided*/ any;
|
|
92
|
-
uuid(message: string): /*elided*/ any;
|
|
93
|
-
oneOf: (types: string[], message: string) => /*elided*/ any;
|
|
94
|
-
test(validateFn: (value: TInputValue, context: {
|
|
95
|
-
field: string;
|
|
96
|
-
}) => boolean, message: string): /*elided*/ any;
|
|
97
|
-
videoUrl: {
|
|
98
|
-
youtube(message: string): /*elided*/ any;
|
|
99
|
-
};
|
|
100
|
-
asNumber(message: string): /*elided*/ any;
|
|
101
|
-
asBoolean(message: string): /*elided*/ any;
|
|
102
|
-
asStringArray(message: string): /*elided*/ any;
|
|
103
|
-
};
|
|
77
|
+
type(type: TTypes, message: string): ValidatorField;
|
|
104
78
|
};
|
|
105
79
|
conditionallyRequired(isRequired: boolean, message: string): {
|
|
106
|
-
type(type: TTypes, message: string):
|
|
107
|
-
cnpj: (message: string) => /*elided*/ any;
|
|
108
|
-
cpf: (message: string) => /*elided*/ any;
|
|
109
|
-
each(callback: <U extends Record<string, TInputValue>>(item: U, index: number, subValidator: ReturnType<typeof createValidator<U>>) => void): /*elided*/ any;
|
|
110
|
-
email: (message: string) => /*elided*/ any;
|
|
111
|
-
fileMaxSize: (maxSize: number, message: string) => /*elided*/ any;
|
|
112
|
-
fileType: (validTypes: string[], message: string) => /*elided*/ any;
|
|
113
|
-
length(length: number, message: string): /*elided*/ any;
|
|
114
|
-
min(min: number, message: string): /*elided*/ any;
|
|
115
|
-
max(max: number, message: string): /*elided*/ any;
|
|
116
|
-
transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
|
|
117
|
-
slug(message: string): /*elided*/ any;
|
|
118
|
-
sanitize(): /*elided*/ any;
|
|
119
|
-
sanitizePreservingNewlines(): /*elided*/ any;
|
|
120
|
-
sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
|
|
121
|
-
url(message: string): /*elided*/ any;
|
|
122
|
-
uuid(message: string): /*elided*/ any;
|
|
123
|
-
oneOf: (types: string[], message: string) => /*elided*/ any;
|
|
124
|
-
test(validateFn: (value: TInputValue, context: {
|
|
125
|
-
field: string;
|
|
126
|
-
}) => boolean, message: string): /*elided*/ any;
|
|
127
|
-
videoUrl: {
|
|
128
|
-
youtube(message: string): /*elided*/ any;
|
|
129
|
-
};
|
|
130
|
-
asNumber(message: string): /*elided*/ any;
|
|
131
|
-
asBoolean(message: string): /*elided*/ any;
|
|
132
|
-
asStringArray(message: string): /*elided*/ any;
|
|
133
|
-
};
|
|
80
|
+
type(type: TTypes, message: string): ValidatorField;
|
|
134
81
|
};
|
|
135
82
|
};
|
|
136
83
|
};
|
package/package.json
CHANGED
package/src/helpers/validator.ts
CHANGED
|
@@ -18,6 +18,42 @@ interface IInputErrors {
|
|
|
18
18
|
[key: string]: TMessage[] | IInputErrors[];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
interface ValidatorField {
|
|
22
|
+
cnpj(message: string): ValidatorField;
|
|
23
|
+
cpf(message: string): ValidatorField;
|
|
24
|
+
each(
|
|
25
|
+
callback: <U extends Record<string, TInputValue>>(
|
|
26
|
+
item: U,
|
|
27
|
+
index: number,
|
|
28
|
+
subValidator: ReturnType<typeof createValidator<U>>
|
|
29
|
+
) => void
|
|
30
|
+
): ValidatorField;
|
|
31
|
+
email(message: string): ValidatorField;
|
|
32
|
+
fileMaxSize(maxSize: number, message: string): ValidatorField;
|
|
33
|
+
fileType(validTypes: string[], message: string): ValidatorField;
|
|
34
|
+
length(length: number, message: string): ValidatorField;
|
|
35
|
+
min(min: number, message: string): ValidatorField;
|
|
36
|
+
max(max: number, message: string): ValidatorField;
|
|
37
|
+
transform<U>(fn: (value: TInputValue) => U): ValidatorField;
|
|
38
|
+
slug(message: string): ValidatorField;
|
|
39
|
+
sanitize(): ValidatorField;
|
|
40
|
+
sanitizePreservingNewlines(): ValidatorField;
|
|
41
|
+
sanitizeHTML(tags?: AllowedTag[]): ValidatorField;
|
|
42
|
+
url(message: string): ValidatorField;
|
|
43
|
+
uuid(message: string): ValidatorField;
|
|
44
|
+
oneOf(types: string[], message: string): ValidatorField;
|
|
45
|
+
test(
|
|
46
|
+
validateFn: (value: TValue, context: { field: string }) => boolean,
|
|
47
|
+
message: string
|
|
48
|
+
): ValidatorField;
|
|
49
|
+
videoUrl: {
|
|
50
|
+
youtube(message: string): ValidatorField;
|
|
51
|
+
};
|
|
52
|
+
asNumber(message: string): ValidatorField;
|
|
53
|
+
asBoolean(message: string): ValidatorField;
|
|
54
|
+
asStringArray(message: string): ValidatorField;
|
|
55
|
+
}
|
|
56
|
+
|
|
21
57
|
/**
|
|
22
58
|
* Cria um validador de inputs com suporte a validações encadeadas, transformação e sanitização.
|
|
23
59
|
*
|
|
@@ -128,7 +164,7 @@ export function createValidator<
|
|
|
128
164
|
);
|
|
129
165
|
};
|
|
130
166
|
|
|
131
|
-
const validator = {
|
|
167
|
+
const validator: ValidatorField = {
|
|
132
168
|
cnpj: (message: string) => {
|
|
133
169
|
if (shouldSkipValidation()) {
|
|
134
170
|
return validator;
|