@juantroconisf/lib 2.2.4 → 2.2.6
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.js +13 -2
- package/dist/index.mjs +13 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -66,9 +66,20 @@ var regex = {
|
|
|
66
66
|
email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
|
67
67
|
password: /^(?!.*\s)(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~`!@#$%^&*()--+={}[\]|:;"'<>,.?/_₹]).{8,24}$/
|
|
68
68
|
};
|
|
69
|
+
var map = {
|
|
70
|
+
string: (val) => Boolean(val),
|
|
71
|
+
number: (val) => String(val) !== "",
|
|
72
|
+
null: (val) => val !== null,
|
|
73
|
+
object: (val) => Object.keys(val).length > 0
|
|
74
|
+
};
|
|
75
|
+
var requiredValidation = (value) => {
|
|
76
|
+
const isArray = Array.isArray(value);
|
|
77
|
+
if (isArray) return value.length > 0;
|
|
78
|
+
return map[typeof value](value);
|
|
79
|
+
};
|
|
69
80
|
var errors = {
|
|
70
81
|
required: {
|
|
71
|
-
validate: (val) =>
|
|
82
|
+
validate: (val, isRequired) => !isRequired || requiredValidation(val),
|
|
72
83
|
msg: "REQUIRED"
|
|
73
84
|
},
|
|
74
85
|
min: {
|
|
@@ -147,7 +158,7 @@ function useComponentLanguage() {
|
|
|
147
158
|
function useValidation() {
|
|
148
159
|
const { lang } = useComponentLanguage();
|
|
149
160
|
const getValidation = (value, isTouched, types, errorMessages) => {
|
|
150
|
-
const items = Object.entries(types), isRequired = items.some(([key]) => key === "required");
|
|
161
|
+
const items = Object.entries(types), isRequired = items.some(([key, val]) => key === "required" && val);
|
|
151
162
|
if (isRequired && !isTouched)
|
|
152
163
|
return {
|
|
153
164
|
isValid: true,
|
package/dist/index.mjs
CHANGED
|
@@ -48,9 +48,20 @@ var regex = {
|
|
|
48
48
|
email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
|
49
49
|
password: /^(?!.*\s)(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~`!@#$%^&*()--+={}[\]|:;"'<>,.?/_₹]).{8,24}$/
|
|
50
50
|
};
|
|
51
|
+
var map = {
|
|
52
|
+
string: (val) => Boolean(val),
|
|
53
|
+
number: (val) => String(val) !== "",
|
|
54
|
+
null: (val) => val !== null,
|
|
55
|
+
object: (val) => Object.keys(val).length > 0
|
|
56
|
+
};
|
|
57
|
+
var requiredValidation = (value) => {
|
|
58
|
+
const isArray = Array.isArray(value);
|
|
59
|
+
if (isArray) return value.length > 0;
|
|
60
|
+
return map[typeof value](value);
|
|
61
|
+
};
|
|
51
62
|
var errors = {
|
|
52
63
|
required: {
|
|
53
|
-
validate: (val) =>
|
|
64
|
+
validate: (val, isRequired) => !isRequired || requiredValidation(val),
|
|
54
65
|
msg: "REQUIRED"
|
|
55
66
|
},
|
|
56
67
|
min: {
|
|
@@ -129,7 +140,7 @@ function useComponentLanguage() {
|
|
|
129
140
|
function useValidation() {
|
|
130
141
|
const { lang } = useComponentLanguage();
|
|
131
142
|
const getValidation = (value, isTouched, types, errorMessages) => {
|
|
132
|
-
const items = Object.entries(types), isRequired = items.some(([key]) => key === "required");
|
|
143
|
+
const items = Object.entries(types), isRequired = items.some(([key, val]) => key === "required" && val);
|
|
133
144
|
if (isRequired && !isTouched)
|
|
134
145
|
return {
|
|
135
146
|
isValid: true,
|