@juantroconisf/lib 2.3.0 → 2.3.1
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.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -2
- package/dist/index.mjs +6 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -18,6 +18,7 @@ interface ValidatorTypes {
|
|
|
18
18
|
numberIsEqual: Validator<number, number>;
|
|
19
19
|
email: Validator<string, boolean>;
|
|
20
20
|
password: Validator<string, boolean>;
|
|
21
|
+
custom: Validator<any, boolean>;
|
|
21
22
|
}
|
|
22
23
|
type ValidatorParams = {
|
|
23
24
|
[K in keyof ValidatorTypes]?: ValidatorTypes[K] extends Validator<any, infer U> ? U : never;
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ interface ValidatorTypes {
|
|
|
18
18
|
numberIsEqual: Validator<number, number>;
|
|
19
19
|
email: Validator<string, boolean>;
|
|
20
20
|
password: Validator<string, boolean>;
|
|
21
|
+
custom: Validator<any, boolean>;
|
|
21
22
|
}
|
|
22
23
|
type ValidatorParams = {
|
|
23
24
|
[K in keyof ValidatorTypes]?: ValidatorTypes[K] extends Validator<any, infer U> ? U : never;
|
package/dist/index.js
CHANGED
|
@@ -112,6 +112,10 @@ var errors = {
|
|
|
112
112
|
password: {
|
|
113
113
|
validate: (val) => new RegExp(regex.password).test(val),
|
|
114
114
|
msg: "INVALID_PASSWORD"
|
|
115
|
+
},
|
|
116
|
+
custom: {
|
|
117
|
+
validate: (_, bool) => bool,
|
|
118
|
+
msg: "INVALID"
|
|
115
119
|
}
|
|
116
120
|
};
|
|
117
121
|
|
|
@@ -159,6 +163,8 @@ function useValidation() {
|
|
|
159
163
|
isValid: true,
|
|
160
164
|
validationProps: nxError()
|
|
161
165
|
};
|
|
166
|
+
if (value === "" && !isRequired)
|
|
167
|
+
return { isValid: true, validationProps: nxError() };
|
|
162
168
|
const validations = items.map(([name, opts]) => {
|
|
163
169
|
const { validate, msg: msg2 } = errors[name];
|
|
164
170
|
return {
|
|
@@ -169,8 +175,6 @@ function useValidation() {
|
|
|
169
175
|
isValid: true,
|
|
170
176
|
msg: ""
|
|
171
177
|
};
|
|
172
|
-
if (!isValid && value === "" && !isRequired)
|
|
173
|
-
return { isValid: true, validationProps: nxError() };
|
|
174
178
|
return {
|
|
175
179
|
isValid,
|
|
176
180
|
validationProps: nxError(!isValid, msg)
|
package/dist/index.mjs
CHANGED
|
@@ -94,6 +94,10 @@ var errors = {
|
|
|
94
94
|
password: {
|
|
95
95
|
validate: (val) => new RegExp(regex.password).test(val),
|
|
96
96
|
msg: "INVALID_PASSWORD"
|
|
97
|
+
},
|
|
98
|
+
custom: {
|
|
99
|
+
validate: (_, bool) => bool,
|
|
100
|
+
msg: "INVALID"
|
|
97
101
|
}
|
|
98
102
|
};
|
|
99
103
|
|
|
@@ -141,6 +145,8 @@ function useValidation() {
|
|
|
141
145
|
isValid: true,
|
|
142
146
|
validationProps: nxError()
|
|
143
147
|
};
|
|
148
|
+
if (value === "" && !isRequired)
|
|
149
|
+
return { isValid: true, validationProps: nxError() };
|
|
144
150
|
const validations = items.map(([name, opts]) => {
|
|
145
151
|
const { validate, msg: msg2 } = errors[name];
|
|
146
152
|
return {
|
|
@@ -151,8 +157,6 @@ function useValidation() {
|
|
|
151
157
|
isValid: true,
|
|
152
158
|
msg: ""
|
|
153
159
|
};
|
|
154
|
-
if (!isValid && value === "" && !isRequired)
|
|
155
|
-
return { isValid: true, validationProps: nxError() };
|
|
156
160
|
return {
|
|
157
161
|
isValid,
|
|
158
162
|
validationProps: nxError(!isValid, msg)
|