structure-verifier 0.0.14 → 0.0.16

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.
Files changed (39) hide show
  1. package/README.md +299 -325
  2. package/dist/index.d.ts +50 -18
  3. package/dist/index.js +20 -15
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/error/v_error.d.ts +9 -4
  6. package/dist/src/error/v_error.js +14 -7
  7. package/dist/src/error/v_error.js.map +1 -1
  8. package/dist/src/interfaces/types.d.ts +3 -3
  9. package/dist/src/languages/message.d.ts +1 -1
  10. package/dist/src/languages/message.js +7 -4
  11. package/dist/src/languages/message.js.map +1 -1
  12. package/dist/src/verifiers/any/v_any.d.ts +1 -2
  13. package/dist/src/verifiers/any/v_any.js +8 -3
  14. package/dist/src/verifiers/any/v_any.js.map +1 -1
  15. package/dist/src/verifiers/array/v_array.d.ts +7 -6
  16. package/dist/src/verifiers/array/v_array.js +44 -33
  17. package/dist/src/verifiers/array/v_array.js.map +1 -1
  18. package/dist/src/verifiers/boolean/v_boolean.d.ts +1 -2
  19. package/dist/src/verifiers/boolean/v_boolean.js +30 -21
  20. package/dist/src/verifiers/boolean/v_boolean.js.map +1 -1
  21. package/dist/src/verifiers/date/v_date.d.ts +1 -2
  22. package/dist/src/verifiers/date/v_date.js +68 -47
  23. package/dist/src/verifiers/date/v_date.js.map +1 -1
  24. package/dist/src/verifiers/number/v_number.d.ts +1 -2
  25. package/dist/src/verifiers/number/v_number.js +30 -52
  26. package/dist/src/verifiers/number/v_number.js.map +1 -1
  27. package/dist/src/verifiers/object/v_object.d.ts +14 -15
  28. package/dist/src/verifiers/object/v_object.js +98 -68
  29. package/dist/src/verifiers/object/v_object.js.map +1 -1
  30. package/dist/src/verifiers/string/v_string.d.ts +1 -2
  31. package/dist/src/verifiers/string/v_string.js +73 -85
  32. package/dist/src/verifiers/string/v_string.js.map +1 -1
  33. package/dist/src/verifiers/type.d.ts +1 -0
  34. package/dist/src/verifiers/uuid/v_uuid.d.ts +1 -2
  35. package/dist/src/verifiers/uuid/v_uuid.js +83 -46
  36. package/dist/src/verifiers/uuid/v_uuid.js.map +1 -1
  37. package/dist/src/verifiers/verifier.js +1 -1
  38. package/dist/src/verifiers/verifier.js.map +1 -1
  39. package/package.json +1 -1
package/README.md CHANGED
@@ -1,422 +1,396 @@
1
- # structure-verifier 0.0.9
1
+ # structure-verifier 0.0.16
2
2
 
3
- structure-verifier is a typescript library to validate data of "any" type and to ensure that it corresponds to a data type.
3
+ Libreria TypeScript para validar estructuras de datos con tipado inferido.
4
4
 
5
- ## Installation
5
+ Permite validar valores simples y estructuras anidadas (objetos y arrays), con errores detallados por ruta (por ejemplo: name, items[0], address.city).
6
+
7
+ ## Instalacion
6
8
 
7
9
  ```bash
8
- npm install structure-verifier
10
+ npm install structure-verifier
9
11
  ```
10
12
 
11
- ## Example use
13
+ ## Inicio rapido
12
14
 
13
- ```typescript
15
+ ```ts
14
16
  import { Verifiers as V, VerificationError } from "structure-verifier";
15
- //////////Verificator object creation
16
- const v = new V.Number();
17
- /////////Running validations
18
17
 
19
- try {
20
- let value = v.check(10);
21
- /////////Will get the value without error
22
- } catch (error:any) {
23
- console.log(error as VerificationError);
24
- }
18
+ const userValidator = V.ObjectNotNull({
19
+ id: V.UUIDNotNull({ version: 4 }),
20
+ name: V.StringNotNull({ minLength: 2 }),
21
+ age: V.Number({ min: 0 }),
22
+ active: V.BooleanNotNull(),
23
+ });
25
24
 
26
25
  try {
27
- let value = v.check('TEST');
28
- } catch (error:any) {
29
- ///////////Will get the error, because the value is not a number
30
- console.log(error as VerificationError);
26
+ const user = userValidator.check({
27
+ id: "550e8400-e29b-41d4-a716-446655440000",
28
+ name: "Ana",
29
+ age: 31,
30
+ active: "true",
31
+ });
32
+
33
+ // user queda tipado con los tipos inferidos de cada propiedad
34
+ console.log(user);
35
+ } catch (error) {
36
+ if (error instanceof VerificationError) {
37
+ console.log(error.errors); // mensajes planos
38
+ console.log(error.errorsObj); // mensajes con key y metadatos
39
+ }
31
40
  }
32
41
  ```
33
42
 
34
- ### Alternative Import with Verifiers Object
35
-
36
- You can also import the `Verifiers` object which contains all available validators:
37
-
38
- ```typescript
39
- import { Verifiers, VerificationError } from "structure-verifier";
40
-
41
- // Available verifiers:
42
- const numberVal = new Verifiers.Number(); // VNumber
43
- const numberNotNullVal = new Verifiers.NumberNotNull(); // VNumberNotNull
44
- const stringVal = new Verifiers.String(); // VString
45
- const stringNotNullVal = new Verifiers.StringNotNull(); // VStringNotNull
46
- const booleanVal = new Verifiers.Boolean(); // VBoolean
47
- const booleanNotNullVal = new Verifiers.BooleanNotNull(); // VBooleanNotNull
48
- const objectVal = new Verifiers.Object({ properties: {} }); // VObject
49
- const objectNotNullVal = new Verifiers.ObjectNotNull({ properties: {} }); // VObjectNotNull
50
- const arrayVal = new Verifiers.Array({ verifier: new Verifiers.Number() }); // VArray
51
- const arrayNotNullVal = new Verifiers.ArrayNotNull({ verifier: new Verifiers.Number() }); // VArrayNotNull
52
- const anyVal = new Verifiers.Any(); // VAny
53
- const dateVal = new Verifiers.Date(); // VDate
54
- const dateNotNullVal = new Verifiers.DateNotNull(); // VDateNotNull
55
- const uuidVal = new Verifiers.UUID(); // VUUID
56
- const uuidNotNullVal = new Verifiers.UUIDNotNull(); // VUUIDNotNull
43
+ ## API publica
44
+
45
+ Import principal:
46
+
47
+ ```ts
48
+ import {
49
+ Verifiers,
50
+ VerificationError,
51
+ Verifier,
52
+ InferType,
53
+ InferFactoryType,
54
+ VAny,
55
+ VAnyConditions,
56
+ VArray,
57
+ VArrayNotNull,
58
+ VArrayConditions,
59
+ VBoolean,
60
+ VBooleanNotNull,
61
+ VBooleanConditions,
62
+ VDate,
63
+ VDateNotNull,
64
+ VDateConditions,
65
+ VNumber,
66
+ VNumberNotNull,
67
+ VNumberConditions,
68
+ VObject,
69
+ VObjectNotNull,
70
+ VObjectConditions,
71
+ VObjectConditionsNotNull,
72
+ VString,
73
+ VStringNotNull,
74
+ VStringConditions,
75
+ VUUID,
76
+ VUUIDNotNull,
77
+ VUUIDConditions,
78
+ datetime,
79
+ } from "structure-verifier";
57
80
  ```
58
- ## Types
59
- In case it is necessary to infer the type of the response, it is achieved by using InferType
60
-
61
- ```typescript
62
- import { InferType, Verifiers as V } from "structure-verifier";
63
-
64
- const val = new V.Number();
65
- type valType = InferType<typeof val>;
66
-
67
- function action(data:valType){
68
- ...
69
- }
70
- ```
71
- ## Validations
72
81
 
73
- ### Numbers
74
- Validations to numerical data
75
- ```typescript
76
- const numberVal = new V.Number();////return number|null
77
- const notNullNumberVal = new V.NumberNotNull() ////return number
78
- ```
79
- Number exclusive conditions
80
-
81
- - **min:** - Used to denote the smallest valid number.
82
- - **max:** - Used to denote the biggest valid number.
83
- - **in:** - Used to denote an array of valid numbers that the value must be one of.
84
- - **notIn:** - Used to denote an array of numbers that the value must not be one of.
85
- - **maxDecimalPlaces:** - Used to denote the maximum number of decimal places allowed.
86
- - **minDecimalPlaces:** - Used to denote the minimum number of decimal places required.
87
-
88
- #### Example
89
- ```typescript
90
- const numberVal = new V.Number({
91
- min:10,
92
- max:20,
93
- in: [15,16,17],
94
- notIn: [18,19,20],
95
- maxDecimalPlaces: 0,
96
- minDecimalPlaces: 0
97
- });
98
- /////Validate a number or null that meets all conditions otherwise error (VerificationError)
99
- ```
100
- ***
101
- ### Strings
102
- Validations for string data.
82
+ ## Formas de uso
103
83
 
104
- ```typescript
105
- const stringVal = new V.String(); // Returns string | null
106
- const notNullStringVal = new V.StringNotNull(); // Returns string
107
- ```
108
- String Exclusive Conditions
109
- - **minLength:** - Specifies the minimum length the string must have.
110
- - **maxLength:** - Specifies the maximum length the string can have.
111
- - **regex:** - Specifies a regular expression pattern the string must match.
112
- - **notRegex:** - Specifies a regular expression pattern the string must not match.
113
- - **in:** - Specifies an array of valid string values; the string must be one of these values.
114
- - **notIn:** - Specifies an array of string values that the string must not be one of.
115
- - **strictMode:** - When true, ensures the value is strictly a string (not coerced from another type).
116
- - **ignoreCase:** - When true, makes the in condition case-insensitive.
117
-
118
- #### Example
119
- ```typescript
120
- const stringVal = new V.String({
121
- minLength: 5,
122
- maxLength: 10,
123
- regex: /^[a-zA-Z]+$/,
124
- notRegex: /[^a-zA-Z]/,
125
- in: ['apple', 'banana', 'cherry'],
126
- notIn: ['date', 'fig', 'grape'],
127
- strictMode: true,
128
- ignoreCase: true
129
- });
130
- ///// Validate a string or null that meets all conditions otherwise error (VerificationError)
131
- ```
132
- ***
133
- ### Booleans
134
- Validations for boolean data.
84
+ La libreria soporta dos estilos:
135
85
 
136
- ```typescript
137
- const booleanVal = new V.Boolean(); // Returns boolean | null
138
- const notNullBooleanVal = new V.BooleanNotNull(); // Returns boolean
139
- ```
86
+ 1. API recomendada con Verifiers (callable, con o sin new)
87
+ 2. Clases directas (new VString(...), new VObject(...), etc.)
140
88
 
141
- Boolean Exclusive Conditions
89
+ Ejemplo con Verifiers:
142
90
 
143
- *No exclusive conditions for boolean validation*
91
+ ```ts
92
+ import { Verifiers as V } from "structure-verifier";
144
93
 
145
- #### Example
146
- ```typescript
147
- const booleanVal = new V.Boolean();
148
- const notNullBooleanVal = new V.BooleanNotNull();
94
+ const a = V.StringNotNull({ minLength: 3 });
95
+ const b = new V.StringNotNull({ minLength: 3 });
149
96
 
150
- try {
151
- console.log(booleanVal.check('true')); // Output: true
152
- console.log(booleanVal.check('FALSE')); // Output: false
153
- console.log(booleanVal.check(null)); // Output: null
154
- console.log(notNullBooleanVal.check('1')); // Output: true
155
- console.log(notNullBooleanVal.check(0)); // Output: false
156
- } catch (error) {
157
- console.error(error);
158
- }
97
+ console.log(a.check("hola"));
98
+ console.log(b.check("hola"));
159
99
  ```
160
- ***
161
- ### Objects
162
- Validations for object data.
163
100
 
164
- ```typescript
165
- const objectVal = new V.Object({ properties: { name: new V.String({ minLength: 3 })/* properties with validations */ } }); // Returns object {name:""} | null
166
- const notNullObjectVal = new V.ObjectNotNull({ properties: { name: new V.String({ minLength: 3 })/* properties with validations */ } }); // Returns object {name:""}
167
- ```
101
+ ## Inferencia de tipos
168
102
 
169
- Object Exclusive Conditions
103
+ ### InferType
170
104
 
171
- - **invalidPropertyMessage:** - Custom message for invalid properties.
172
- - **strictMode:** - When `true`, ensures the object has exactly the same properties as defined.
173
- - **ignoreCase:** - When `true`, makes the property names case-insensitive.
174
- - **takeAllValues:** - When `true`, allows taking all values from the input object, not just those defined in the properties.
105
+ ```ts
106
+ import { InferType, Verifiers as V } from "structure-verifier";
175
107
 
176
- #### Example
177
- ```typescript
178
- const objectVal = new V.Object({
179
- properties: {
180
- name: new V.String({ minLength: 3 }),
181
- age: new V.Number({ min: 18, max: 99 }),
182
- },
183
- strictMode: true,
184
- ignoreCase: true,
185
- invalidPropertyMessage: {
186
- message: () => "no es una propiedad valida",
187
- val: undefined
188
- }
108
+ const v = V.ObjectNotNull({
109
+ id: V.UUIDNotNull(),
110
+ tags: V.ArrayNotNull(V.StringNotNull()),
189
111
  });
190
112
 
191
- const notNullObjectVal = new V.ObjectNotNull({
192
- properties: {
193
- name: new V.StringNotNull({ minLength: 3 }),
194
- age: new V.NumberNotNull({ min: 18, max: 99 }),
195
- },
196
- strictMode: true,
197
- ignoreCase: true,
198
- invalidPropertyMessage: {
199
- message: () => "no es una propiedad valida",
200
- val: undefined
201
- }
202
- });
203
-
204
- try {
205
- console.log(objectVal.check({ name: 'John', age: 25 })); // Output: { name: 'John', age: 25 }
206
- console.log(objectVal.check(null)); // Output: null
207
- console.log(notNullObjectVal.check({ name: 'Jane', age: 30 })); // Output: { name: 'Jane', age: 30 }
208
- } catch (error) {
209
- console.error(error);
210
- }
113
+ type User = InferType<typeof v>;
211
114
  ```
212
- ***
213
- ### Arrays
214
- Validations for array data.
215
115
 
216
- ```typescript
217
- const arrayVal = new V.Array({verifier: new V.Number()}); // Returns Array | null
218
- const notNullArrayVal = new V.ArrayNotNull({verifier: new V.Number()}); // Returns Array
219
- ```
116
+ ### InferFactoryType
220
117
 
221
- Array Exclusive Conditions
118
+ Funciona con funciones que retornan un Verifier (por ejemplo, miembros callable de Verifiers).
222
119
 
223
- - **minLength**: Minimum length of the array.
224
- - **maxLength**: Maximum length of the array.
120
+ ```ts
121
+ import { InferFactoryType, Verifiers as V } from "structure-verifier";
122
+
123
+ type NullableNumber = InferFactoryType<typeof V.Number>; // number | null
124
+ type RequiredNumber = InferFactoryType<typeof V.NumberNotNull>; // number
125
+ ```
225
126
 
226
- #### Example
227
- ```typescript
228
- const arrayVal = new V.Array({ verifier: new V.Number(), minLength: 1, maxLength: 5 });
229
- const notNullArrayVal = new V.ArrayNotNull({ verifier: new V.Number(), minLength: 2 });
127
+ ## Manejo de errores
230
128
 
129
+ Cuando una validacion falla se lanza VerificationError.
130
+
131
+ ```ts
231
132
  try {
232
- console.log(arrayVal.check([1, 2, 3])); // Output: [1, 2, 3]
233
- console.log(arrayVal.check([])); // Throws VerificationError (array too short)
234
- console.log(arrayVal.check(null)); // Output: null
235
- console.log(notNullArrayVal.check([1, 2])); // Output: [1, 2]
236
- console.log(notNullArrayVal.check([1])); // Throws VerificationError (array too short)
133
+ V.NumberNotNull({ min: 10 }).check(5);
237
134
  } catch (error) {
238
- console.error(error);
135
+ if (error instanceof VerificationError) {
136
+ console.log(error.errors); // ["debe ser mayor o igual a 10"]
137
+ console.log(error.errorsObj); // [{ key: "", message: "..." }]
138
+ }
239
139
  }
240
140
  ```
241
- ***
242
- ### Any
243
- Validations for any data.
244
141
 
245
- ```typescript
246
- const anyVal = new V.Any(); // Returns any type
247
- ```
142
+ ## Opciones comunes
248
143
 
249
- VAny Exclusive Conditions
144
+ Muchos validadores comparten estas opciones:
250
145
 
251
- *No exclusive conditions for any validation*
146
+ - isRequired: fuerza que el valor exista.
147
+ - emptyAsNull: si llega string vacio, se convierte a null antes de validar.
148
+ - defaultValue: valor por defecto si llega undefined (y en algunos flujos tambien null).
149
+ - badTypeMessage: mensaje personalizado de tipo invalido.
252
150
 
253
- #### Example
254
- ```typescript
255
- const anyVal = new V.Any();
151
+ Puedes pasar mensajes simples o mensajes dinamicos con estructura:
256
152
 
257
- try {
258
- console.log(anyVal.check('true')); // Output: 'true'
259
- console.log(anyVal.check('FALSE')); // Output: 'FALSE'
260
- console.log(anyVal.check(null)); // Output: null
261
- console.log(anyVal.check('1')); // Output: '1'
262
- console.log(anyVal.check(0)); // Output: 0
263
- } catch (error) {
264
- console.error(error);
265
- }
153
+ ```ts
154
+ { val: valorReal, message: (values) => "mensaje" }
266
155
  ```
267
- ***
268
- ### Date
269
- Validations for date data (depends Moment).
270
156
 
271
- ```typescript
272
- const vdate = new V.Date();
273
- const vdateNotNull = new V.DateNotNull();
157
+ ## Validadores
158
+
159
+ ### Number / NumberNotNull
160
+
161
+ ```ts
162
+ const n1 = V.Number();
163
+ const n2 = V.NumberNotNull();
274
164
  ```
275
165
 
276
- VDate Exclusive Conditions
166
+ Condiciones:
277
167
 
278
- - **format**: Specifies the date format to be validated against.
279
- - **timeZone**: Specifies the expected time zone of the input date.
280
- - **maxDate**: Specifies the maximum allowed date.
281
- - **minDate**: Specifies the minimum allowed date.
168
+ - min
169
+ - max
170
+ - in
171
+ - notIn
172
+ - maxDecimalPlaces
173
+ - minDecimalPlaces
174
+ - isRequired
175
+ - emptyAsNull
176
+ - defaultValue
177
+ - badTypeMessage
282
178
 
283
- #### Example
284
- #### Basic Date Validation
179
+ Notas:
285
180
 
286
- ```typescript
287
- const vdate = new V.Date();
288
- console.log(vdate.check("2023-08-09")?.format("YYYY-MM-DD")); // Output: "2023-08-09"
289
- ```
181
+ - Convierte con Number(data), por lo que acepta strings numericos como "42".
182
+ - "" y NaN fallan.
290
183
 
291
- #### Date with Specific Format
184
+ ### String / StringNotNull
292
185
 
293
- ```typescript
294
- const vdate = new V.Date({ format: "DD/MM/YYYY" });
295
- console.log(vdate.check("09/08/2023")?.format("DD/MM/YYYY")); // Output: "09/08/2023"
186
+ ```ts
187
+ const s1 = V.String();
188
+ const s2 = V.StringNotNull();
296
189
  ```
297
190
 
298
- #### Date with Time Zone
191
+ Condiciones:
299
192
 
300
- ```typescript
301
- const vdate = new V.Date({ timeZone: "America/New_York" });
302
- const result = vdate.check("2023-08-09T10:00:00");
303
- console.log(result.tz("America/New_York").format()); // Output: "2023-08-09T10:00:00-04:00"
304
- ```
193
+ - minLength
194
+ - maxLength
195
+ - regex
196
+ - notRegex
197
+ - in
198
+ - notIn
199
+ - strictMode
200
+ - ignoreCase
201
+ - isRequired
202
+ - emptyAsNull
203
+ - defaultValue
204
+ - badTypeMessage
305
205
 
306
- #### Date within Range
206
+ Notas:
307
207
 
308
- ```typescript
309
- const vdate = new VDate({
310
- minDate: moment("2023-01-01"),
311
- maxDate: moment("2023-12-31")
312
- });
313
- console.log(vdate.check("2023-08-09").format("YYYY-MM-DD")); // Output: "2023-08-09"
208
+ - En modo no estricto convierte con String(data).
209
+ - En strictMode exige typeof data === "string".
210
+ - ignoreCase afecta in y notIn.
211
+
212
+ ### Boolean / BooleanNotNull
213
+
214
+ ```ts
215
+ const b1 = V.Boolean();
216
+ const b2 = V.BooleanNotNull();
314
217
  ```
315
218
 
316
- ***
317
- ### UUID
318
- Validations for UUID (Universally Unique Identifier) data.
219
+ Condiciones:
220
+
221
+ - strictMode
222
+ - isRequired
223
+ - emptyAsNull
224
+ - defaultValue
225
+ - badTypeMessage
319
226
 
320
- ```typescript
321
- const uuidVal = new V.UUID(); // Returns string | null
322
- const notNullUuidVal = new V.UUIDNotNull(); // Returns string
227
+ Notas:
228
+
229
+ - En modo no estricto acepta: true, false, 1, 0, "1", "0", "true", "false" (case-insensitive).
230
+ - En strictMode solo acepta boolean real.
231
+
232
+ ### UUID / UUIDNotNull
233
+
234
+ ```ts
235
+ const u1 = V.UUID();
236
+ const u2 = V.UUIDNotNull();
323
237
  ```
324
238
 
325
- UUID Exclusive Conditions
239
+ Condiciones:
240
+
241
+ - version (1 | 2 | 3 | 4 | 5)
242
+ - allowNoHyphens
243
+ - strictMode
244
+ - isRequired
245
+ - emptyAsNull
246
+ - defaultValue
247
+ - badTypeMessage
326
248
 
327
- - **version**: Specifies the UUID version to validate against (1, 2, 3, 4, or 5). If not specified, accepts any version.
328
- - **allowNoHyphens**: When `true`, allows UUIDs without hyphens. Default is `false`.
329
- - **strictMode**: When `true`, ensures the input value is strictly a string (not coerced from another type).
249
+ Notas:
330
250
 
331
- #### Example
251
+ - Devuelve UUID normalizado en minusculas y con guiones.
252
+ - Si allowNoHyphens es false, exige formato 8-4-4-4-12.
332
253
 
333
- #### Basic UUID Validation
254
+ ### Date / DateNotNull
334
255
 
335
- ```typescript
336
- const uuidVal = new V.UUID();
337
- console.log(uuidVal.check("550e8400-e29b-41d4-a716-446655440000")); // Output: "550e8400-e29b-41d4-a716-446655440000"
338
- console.log(uuidVal.check(null)); // Output: null
256
+ ```ts
257
+ import { Verifiers as V, datetime } from "structure-verifier";
258
+
259
+ const d1 = V.Date();
260
+ const d2 = V.DateNotNull({
261
+ format: "YYYY-MM-DD",
262
+ timeZone: "UTC",
263
+ minDate: datetime("2024-01-01"),
264
+ maxDate: datetime("2026-12-31"),
265
+ });
339
266
  ```
340
267
 
341
- #### UUID with Specific Version
268
+ Condiciones:
269
+
270
+ - format
271
+ - timeZone
272
+ - minDate
273
+ - maxDate
274
+ - default
275
+ - isRequired
276
+ - emptyAsNull
277
+ - defaultValue
278
+ - badTypeMessage
279
+
280
+ Notas:
342
281
 
343
- ```typescript
344
- const uuidV4Val = new V.UUID({ version: 4 });
345
- console.log(uuidV4Val.check("550e8400-e29b-41d4-a716-446655440000")); // Output: "550e8400-e29b-41d4-a716-446655440000"
282
+ - Retorna instancias dayjs (re-exportado como datetime).
283
+ - Inputs soportados: number, string, Date y datetime.Dayjs.
284
+ - timeZone por defecto: UTC.
285
+
286
+ ### Any
287
+
288
+ ```ts
289
+ const anyVal = V.Any();
346
290
  ```
347
291
 
348
- #### UUID without Hyphens
292
+ Condiciones:
293
+
294
+ - isRequired
295
+ - emptyAsNull
296
+ - defaultValue
297
+ - badTypeMessage
298
+
299
+ ### Array / ArrayNotNull
349
300
 
350
- ```typescript
351
- const uuidNoHyphensVal = new V.UUID({ allowNoHyphens: true });
352
- console.log(uuidNoHyphensVal.check("550e8400e29b41d4a716446655440000")); // Output: "550e8400-e29b-41d4-a716-446655440000"
301
+ Firma:
302
+
303
+ ```ts
304
+ const arr1 = V.Array(verifier, conditions?);
305
+ const arr2 = V.ArrayNotNull(verifier, conditions?);
353
306
  ```
354
307
 
355
- #### Strict Mode UUID
308
+ Ejemplo:
356
309
 
357
- ```typescript
358
- const strictUuidVal = new V.UUIDNotNull({ strictMode: true });
359
- try {
360
- console.log(strictUuidVal.check("550e8400-e29b-41d4-a716-446655440000")); // Output: "550e8400-e29b-41d4-a716-446655440000"
361
- console.log(strictUuidVal.check(123)); // Throws VerificationError
362
- } catch (error) {
363
- console.error(error);
364
- }
310
+ ```ts
311
+ const numbers = V.ArrayNotNull(V.NumberNotNull(), {
312
+ minLength: 1,
313
+ maxLength: 5,
314
+ });
365
315
  ```
366
316
 
367
- ***
368
- ## VerificationError
317
+ Condiciones:
369
318
 
370
- The `VerificationError` class extends the native JavaScript `Error` object to provide enhanced error handling for validation scenarios. This class is designed to collect and format multiple error messages, making it easier to understand and manage errors in your application.
319
+ - minLength
320
+ - maxLength
321
+ - isRequired
322
+ - emptyAsNull
323
+ - defaultValue
324
+ - badTypeMessage
371
325
 
372
- ### Import
326
+ Notas:
373
327
 
374
- To use the `VerificationError` class, import it as follows:
328
+ - Valida item por item con el verificador interno.
329
+ - En errores anidados utiliza claves como [0], [1].name, etc.
375
330
 
376
- ```typescript
377
- import { VerificationError } from "./path/to/your/VerificationError";
378
- ```
331
+ ### Object / ObjectNotNull
379
332
 
380
- ### Constructor
333
+ Firma:
381
334
 
382
- #### `constructor(messages: messageResp[])`
335
+ ```ts
336
+ const o1 = V.Object(properties, conditions?);
337
+ const o2 = V.ObjectNotNull(properties, conditions?);
338
+ ```
383
339
 
384
- The constructor takes an array of `messageResp` objects as an argument. Each `messageResp` object represents an individual validation error and has the following structure:
340
+ Ejemplo:
385
341
 
386
- ```typescript
387
- interface messageResp {
388
- key: string;
389
- message: string;
390
- parent?: string;
391
- }
342
+ ```ts
343
+ const user = V.ObjectNotNull(
344
+ {
345
+ name: V.StringNotNull({ minLength: 3 }),
346
+ age: V.NumberNotNull({ min: 18 }),
347
+ },
348
+ {
349
+ strictMode: true,
350
+ ignoreCase: true,
351
+ takeAllValues: false,
352
+ },
353
+ );
392
354
  ```
393
355
 
394
- The constructor will generate a formatted error message by concatenating each `messageResp` into a single string, separating them by a semicolon (`;`). Additionally, it stores the original errors in two formats:
356
+ Condiciones:
395
357
 
396
- - **`_errors`**: An array of strings, where each string is a formatted error message.
397
- - **`_errorsObj`**: An array of `messageResp` objects.
358
+ - invalidPropertyMessage
359
+ - strictMode
360
+ - ignoreCase
361
+ - takeAllValues
362
+ - conds
363
+ - isRequired
364
+ - emptyAsNull
365
+ - defaultValue
366
+ - badTypeMessage
398
367
 
399
- ### Properties
368
+ Notas:
400
369
 
401
- #### `errors: string[]`
370
+ - strictMode rechaza propiedades extra.
371
+ - ignoreCase permite mapear propiedades sin importar mayusculas/minusculas.
372
+ - takeAllValues conserva propiedades no definidas en el esquema.
373
+ - conds ejecuta una validacion adicional al final con el objeto ya tipado.
402
374
 
403
- This getter returns the array of formatted error messages. Each message is generated based on the `parent`, `key`, and `message` properties of the `messageResp` objects.
375
+ ## datetime (dayjs)
404
376
 
405
- #### `errorsObj: messageResp[]`
377
+ La libreria re-exporta dayjs como datetime con plugins:
406
378
 
407
- This getter returns the original array of `messageResp` objects, allowing access to the detailed structure of each validation error.
379
+ - utc
380
+ - timezone
381
+ - customParseFormat
408
382
 
409
- ### Usage Example
383
+ Ejemplo:
410
384
 
411
- ```typescript
412
- import { VerificationError } from "../src/error/v_error";
385
+ ```ts
386
+ import { datetime } from "structure-verifier";
413
387
 
414
- try {
415
- throw new VerificationError([{ key: "email", message: "is invalid", parent: "contact" }]);
416
- } catch (err) {
417
- if (err instanceof VerificationError) {
418
- console.log(err.errors); // [ 'contact.email is invalid' ]
419
- console.log(err.errorsObj); // Original messageResp objects
420
- }
421
- }
422
- ```
388
+ const now = datetime();
389
+ console.log(now.tz("UTC").format());
390
+ ```
391
+
392
+ ## Ejecutar tests del proyecto
393
+
394
+ ```bash
395
+ npm test
396
+ ```