@juantroconisf/lib 2.3.0 → 2.3.2

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
@@ -18,12 +18,13 @@ 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;
24
25
  };
25
26
  type ValidatorErrorMessage = {
26
- [K in keyof ValidatorTypes]: string;
27
+ [K in keyof ValidatorTypes]?: string;
27
28
  };
28
29
 
29
30
  interface ValidationProps {
package/dist/index.d.ts CHANGED
@@ -18,12 +18,13 @@ 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;
24
25
  };
25
26
  type ValidatorErrorMessage = {
26
- [K in keyof ValidatorTypes]: string;
27
+ [K in keyof ValidatorTypes]?: string;
27
28
  };
28
29
 
29
30
  interface ValidationProps {
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juantroconisf/lib",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",