@juantroconisf/lib 2.2.10 → 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 +7 -1
- package/dist/index.mjs +7 -1
- 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
|
|
|
@@ -153,12 +157,14 @@ function useComponentLanguage() {
|
|
|
153
157
|
function useValidation() {
|
|
154
158
|
const { lang } = useComponentLanguage();
|
|
155
159
|
const getValidation = (value, isTouched, types, errorMessages) => {
|
|
156
|
-
const items = Object.entries(types),
|
|
160
|
+
const items = Object.entries(types), requiredIndex = items.findIndex(([key]) => key === "required"), isRequired = requiredIndex === -1 ? false : items[requiredIndex][1];
|
|
157
161
|
if (isRequired && !isTouched)
|
|
158
162
|
return {
|
|
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 {
|
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
|
|
|
@@ -135,12 +139,14 @@ function useComponentLanguage() {
|
|
|
135
139
|
function useValidation() {
|
|
136
140
|
const { lang } = useComponentLanguage();
|
|
137
141
|
const getValidation = (value, isTouched, types, errorMessages) => {
|
|
138
|
-
const items = Object.entries(types),
|
|
142
|
+
const items = Object.entries(types), requiredIndex = items.findIndex(([key]) => key === "required"), isRequired = requiredIndex === -1 ? false : items[requiredIndex][1];
|
|
139
143
|
if (isRequired && !isTouched)
|
|
140
144
|
return {
|
|
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 {
|