@juantroconisf/lib 2.2.9 → 2.3.0

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 CHANGED
@@ -9,8 +9,8 @@ interface Validator<T, U = any> {
9
9
  }
10
10
  interface ValidatorTypes {
11
11
  required: Validator<string | number, boolean>;
12
- min: Validator<number, number>;
13
- max: Validator<number, number>;
12
+ min: Validator<number | string, number | string>;
13
+ max: Validator<number | string, number | string>;
14
14
  minLength: Validator<string, number>;
15
15
  maxLength: Validator<string, number>;
16
16
  pattern: Validator<string, RegExp>;
package/dist/index.d.ts CHANGED
@@ -9,8 +9,8 @@ interface Validator<T, U = any> {
9
9
  }
10
10
  interface ValidatorTypes {
11
11
  required: Validator<string | number, boolean>;
12
- min: Validator<number, number>;
13
- max: Validator<number, number>;
12
+ min: Validator<number | string, number | string>;
13
+ max: Validator<number | string, number | string>;
14
14
  minLength: Validator<string, number>;
15
15
  maxLength: Validator<string, number>;
16
16
  pattern: Validator<string, RegExp>;
package/dist/index.js CHANGED
@@ -153,7 +153,7 @@ function useComponentLanguage() {
153
153
  function useValidation() {
154
154
  const { lang } = useComponentLanguage();
155
155
  const getValidation = (value, isTouched, types, errorMessages) => {
156
- const items = Object.entries(types), isRequired = items.some(([key, val]) => key === "required" && val);
156
+ const items = Object.entries(types), requiredIndex = items.findIndex(([key]) => key === "required"), isRequired = requiredIndex === -1 ? false : items[requiredIndex][1];
157
157
  if (isRequired && !isTouched)
158
158
  return {
159
159
  isValid: true,
@@ -169,6 +169,8 @@ function useValidation() {
169
169
  isValid: true,
170
170
  msg: ""
171
171
  };
172
+ if (!isValid && value === "" && !isRequired)
173
+ return { isValid: true, validationProps: nxError() };
172
174
  return {
173
175
  isValid,
174
176
  validationProps: nxError(!isValid, msg)
package/dist/index.mjs CHANGED
@@ -135,7 +135,7 @@ function useComponentLanguage() {
135
135
  function useValidation() {
136
136
  const { lang } = useComponentLanguage();
137
137
  const getValidation = (value, isTouched, types, errorMessages) => {
138
- const items = Object.entries(types), isRequired = items.some(([key, val]) => key === "required" && val);
138
+ const items = Object.entries(types), requiredIndex = items.findIndex(([key]) => key === "required"), isRequired = requiredIndex === -1 ? false : items[requiredIndex][1];
139
139
  if (isRequired && !isTouched)
140
140
  return {
141
141
  isValid: true,
@@ -151,6 +151,8 @@ function useValidation() {
151
151
  isValid: true,
152
152
  msg: ""
153
153
  };
154
+ if (!isValid && value === "" && !isRequired)
155
+ return { isValid: true, validationProps: nxError() };
154
156
  return {
155
157
  isValid,
156
158
  validationProps: nxError(!isValid, msg)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juantroconisf/lib",
3
- "version": "2.2.9",
3
+ "version": "2.3.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",