structure-verifier 0.0.9 → 0.0.12
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/README.md +116 -40
- package/dist/index.d.ts +26 -13
- package/dist/index.js +44 -14
- package/dist/index.js.map +1 -1
- package/dist/src/interfaces/types.d.ts +1 -0
- package/dist/src/utils/datetime.d.ts +2 -0
- package/dist/src/utils/datetime.js +15 -0
- package/dist/src/utils/datetime.js.map +1 -0
- package/dist/src/verifiers/date/v_date.d.ts +12 -12
- package/dist/src/verifiers/date/v_date.js +7 -11
- package/dist/src/verifiers/date/v_date.js.map +1 -1
- package/dist/src/verifiers/uuid/v_uuid.d.ts +18 -0
- package/dist/src/verifiers/uuid/v_uuid.js +87 -0
- package/dist/src/verifiers/uuid/v_uuid.js.map +1 -0
- package/dist/src/verifiers/verifier.js +7 -2
- package/dist/src/verifiers/verifier.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# structure-verifier 0.0.
|
|
1
|
+
# structure-verifier 0.0.9
|
|
2
2
|
|
|
3
|
-
structure-verifier is a
|
|
3
|
+
structure-verifier is a typescript library to validate data of "any" type and to ensure that it corresponds to a data type.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -11,9 +11,9 @@ structure-verifier is a typescrpt library to validate data of "any" type and to
|
|
|
11
11
|
## Example use
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import { Verifiers as V,VerificationError } from "structure-verifier";
|
|
14
|
+
import { Verifiers as V, VerificationError } from "structure-verifier";
|
|
15
15
|
//////////Verificator object creation
|
|
16
|
-
const v = new V.
|
|
16
|
+
const v = new V.Number();
|
|
17
17
|
/////////Running validations
|
|
18
18
|
|
|
19
19
|
try {
|
|
@@ -30,13 +30,38 @@ try {
|
|
|
30
30
|
console.log(error as VerificationError);
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
|
+
|
|
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
|
|
57
|
+
```
|
|
33
58
|
## Types
|
|
34
59
|
In case it is necessary to infer the type of the response, it is achieved by using InferType
|
|
35
60
|
|
|
36
61
|
```typescript
|
|
37
|
-
import { InferType } from "structure-verifier";
|
|
62
|
+
import { InferType, Verifiers as V } from "structure-verifier";
|
|
38
63
|
|
|
39
|
-
const val = new V.
|
|
64
|
+
const val = new V.Number();
|
|
40
65
|
type valType = InferType<typeof val>;
|
|
41
66
|
|
|
42
67
|
function action(data:valType){
|
|
@@ -48,8 +73,8 @@ In case it is necessary to infer the type of the response, it is achieved by usi
|
|
|
48
73
|
### Numbers
|
|
49
74
|
Validations to numerical data
|
|
50
75
|
```typescript
|
|
51
|
-
const numberVal = new V.
|
|
52
|
-
const notNullNumberVal = new V.
|
|
76
|
+
const numberVal = new V.Number();////return number|null
|
|
77
|
+
const notNullNumberVal = new V.NumberNotNull() ////return number
|
|
53
78
|
```
|
|
54
79
|
Number exclusive conditions
|
|
55
80
|
|
|
@@ -62,7 +87,7 @@ Number exclusive conditions
|
|
|
62
87
|
|
|
63
88
|
#### Example
|
|
64
89
|
```typescript
|
|
65
|
-
const numberVal = new V.
|
|
90
|
+
const numberVal = new V.Number({
|
|
66
91
|
min:10,
|
|
67
92
|
max:20,
|
|
68
93
|
in: [15,16,17],
|
|
@@ -77,8 +102,8 @@ Number exclusive conditions
|
|
|
77
102
|
Validations for string data.
|
|
78
103
|
|
|
79
104
|
```typescript
|
|
80
|
-
const stringVal = new V.
|
|
81
|
-
const notNullStringVal = new V.
|
|
105
|
+
const stringVal = new V.String(); // Returns string | null
|
|
106
|
+
const notNullStringVal = new V.StringNotNull(); // Returns string
|
|
82
107
|
```
|
|
83
108
|
String Exclusive Conditions
|
|
84
109
|
- **minLength:** - Specifies the minimum length the string must have.
|
|
@@ -92,7 +117,7 @@ String Exclusive Conditions
|
|
|
92
117
|
|
|
93
118
|
#### Example
|
|
94
119
|
```typescript
|
|
95
|
-
const stringVal = new V.
|
|
120
|
+
const stringVal = new V.String({
|
|
96
121
|
minLength: 5,
|
|
97
122
|
maxLength: 10,
|
|
98
123
|
regex: /^[a-zA-Z]+$/,
|
|
@@ -109,8 +134,8 @@ String Exclusive Conditions
|
|
|
109
134
|
Validations for boolean data.
|
|
110
135
|
|
|
111
136
|
```typescript
|
|
112
|
-
const booleanVal = new V.
|
|
113
|
-
const notNullBooleanVal = new V.
|
|
137
|
+
const booleanVal = new V.Boolean(); // Returns boolean | null
|
|
138
|
+
const notNullBooleanVal = new V.BooleanNotNull(); // Returns boolean
|
|
114
139
|
```
|
|
115
140
|
|
|
116
141
|
Boolean Exclusive Conditions
|
|
@@ -119,8 +144,8 @@ Boolean Exclusive Conditions
|
|
|
119
144
|
|
|
120
145
|
#### Example
|
|
121
146
|
```typescript
|
|
122
|
-
const booleanVal = new V.
|
|
123
|
-
const notNullBooleanVal = new V.
|
|
147
|
+
const booleanVal = new V.Boolean();
|
|
148
|
+
const notNullBooleanVal = new V.BooleanNotNull();
|
|
124
149
|
|
|
125
150
|
try {
|
|
126
151
|
console.log(booleanVal.check('true')); // Output: true
|
|
@@ -137,8 +162,8 @@ try {
|
|
|
137
162
|
Validations for object data.
|
|
138
163
|
|
|
139
164
|
```typescript
|
|
140
|
-
const objectVal = new V.
|
|
141
|
-
const notNullObjectVal = new V.
|
|
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:""}
|
|
142
167
|
```
|
|
143
168
|
|
|
144
169
|
Object Exclusive Conditions
|
|
@@ -150,10 +175,10 @@ Object Exclusive Conditions
|
|
|
150
175
|
|
|
151
176
|
#### Example
|
|
152
177
|
```typescript
|
|
153
|
-
const objectVal = new V.
|
|
178
|
+
const objectVal = new V.Object({
|
|
154
179
|
properties: {
|
|
155
|
-
name: new V.
|
|
156
|
-
age: new V.
|
|
180
|
+
name: new V.String({ minLength: 3 }),
|
|
181
|
+
age: new V.Number({ min: 18, max: 99 }),
|
|
157
182
|
},
|
|
158
183
|
strictMode: true,
|
|
159
184
|
ignoreCase: true,
|
|
@@ -163,10 +188,10 @@ const objectVal = new V.VObject({
|
|
|
163
188
|
}
|
|
164
189
|
});
|
|
165
190
|
|
|
166
|
-
const notNullObjectVal = new V.
|
|
191
|
+
const notNullObjectVal = new V.ObjectNotNull({
|
|
167
192
|
properties: {
|
|
168
|
-
name: new V.
|
|
169
|
-
age: new V.
|
|
193
|
+
name: new V.StringNotNull({ minLength: 3 }),
|
|
194
|
+
age: new V.NumberNotNull({ min: 18, max: 99 }),
|
|
170
195
|
},
|
|
171
196
|
strictMode: true,
|
|
172
197
|
ignoreCase: true,
|
|
@@ -189,8 +214,8 @@ try {
|
|
|
189
214
|
Validations for array data.
|
|
190
215
|
|
|
191
216
|
```typescript
|
|
192
|
-
const arrayVal = new V.
|
|
193
|
-
const notNullArrayVal = new V.
|
|
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
|
|
194
219
|
```
|
|
195
220
|
|
|
196
221
|
Array Exclusive Conditions
|
|
@@ -200,8 +225,8 @@ Array Exclusive Conditions
|
|
|
200
225
|
|
|
201
226
|
#### Example
|
|
202
227
|
```typescript
|
|
203
|
-
const arrayVal = new V.
|
|
204
|
-
const notNullArrayVal = new V.
|
|
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 });
|
|
205
230
|
|
|
206
231
|
try {
|
|
207
232
|
console.log(arrayVal.check([1, 2, 3])); // Output: [1, 2, 3]
|
|
@@ -218,7 +243,7 @@ try {
|
|
|
218
243
|
Validations for any data.
|
|
219
244
|
|
|
220
245
|
```typescript
|
|
221
|
-
const anyVal = new V.
|
|
246
|
+
const anyVal = new V.Any(); // Returns any type
|
|
222
247
|
```
|
|
223
248
|
|
|
224
249
|
VAny Exclusive Conditions
|
|
@@ -227,14 +252,14 @@ VAny Exclusive Conditions
|
|
|
227
252
|
|
|
228
253
|
#### Example
|
|
229
254
|
```typescript
|
|
230
|
-
const anyVal = new V.
|
|
255
|
+
const anyVal = new V.Any();
|
|
231
256
|
|
|
232
257
|
try {
|
|
233
|
-
console.log(anyVal.check('true')); // Output: true
|
|
234
|
-
console.log(anyVal.check('FALSE')); // Output:
|
|
258
|
+
console.log(anyVal.check('true')); // Output: 'true'
|
|
259
|
+
console.log(anyVal.check('FALSE')); // Output: 'FALSE'
|
|
235
260
|
console.log(anyVal.check(null)); // Output: null
|
|
236
|
-
console.log(anyVal.check('1'));
|
|
237
|
-
console.log(anyVal.check(0));
|
|
261
|
+
console.log(anyVal.check('1')); // Output: '1'
|
|
262
|
+
console.log(anyVal.check(0)); // Output: 0
|
|
238
263
|
} catch (error) {
|
|
239
264
|
console.error(error);
|
|
240
265
|
}
|
|
@@ -244,8 +269,8 @@ try {
|
|
|
244
269
|
Validations for date data (depends Moment).
|
|
245
270
|
|
|
246
271
|
```typescript
|
|
247
|
-
const vdate = new V.
|
|
248
|
-
const vdateNotNull = new V.
|
|
272
|
+
const vdate = new V.Date();
|
|
273
|
+
const vdateNotNull = new V.DateNotNull();
|
|
249
274
|
```
|
|
250
275
|
|
|
251
276
|
VDate Exclusive Conditions
|
|
@@ -259,21 +284,21 @@ VDate Exclusive Conditions
|
|
|
259
284
|
#### Basic Date Validation
|
|
260
285
|
|
|
261
286
|
```typescript
|
|
262
|
-
const vdate = new V.
|
|
287
|
+
const vdate = new V.Date();
|
|
263
288
|
console.log(vdate.check("2023-08-09")?.format("YYYY-MM-DD")); // Output: "2023-08-09"
|
|
264
289
|
```
|
|
265
290
|
|
|
266
291
|
#### Date with Specific Format
|
|
267
292
|
|
|
268
293
|
```typescript
|
|
269
|
-
const vdate = new V.
|
|
294
|
+
const vdate = new V.Date({ format: "DD/MM/YYYY" });
|
|
270
295
|
console.log(vdate.check("09/08/2023")?.format("DD/MM/YYYY")); // Output: "09/08/2023"
|
|
271
296
|
```
|
|
272
297
|
|
|
273
298
|
#### Date with Time Zone
|
|
274
299
|
|
|
275
300
|
```typescript
|
|
276
|
-
const vdate = new V.
|
|
301
|
+
const vdate = new V.Date({ timeZone: "America/New_York" });
|
|
277
302
|
const result = vdate.check("2023-08-09T10:00:00");
|
|
278
303
|
console.log(result.tz("America/New_York").format()); // Output: "2023-08-09T10:00:00-04:00"
|
|
279
304
|
```
|
|
@@ -281,13 +306,64 @@ console.log(result.tz("America/New_York").format()); // Output: "2023-08-09T10:0
|
|
|
281
306
|
#### Date within Range
|
|
282
307
|
|
|
283
308
|
```typescript
|
|
284
|
-
const vdate = new
|
|
309
|
+
const vdate = new VDate({
|
|
285
310
|
minDate: moment("2023-01-01"),
|
|
286
311
|
maxDate: moment("2023-12-31")
|
|
287
312
|
});
|
|
288
313
|
console.log(vdate.check("2023-08-09").format("YYYY-MM-DD")); // Output: "2023-08-09"
|
|
289
314
|
```
|
|
290
315
|
|
|
316
|
+
***
|
|
317
|
+
### UUID
|
|
318
|
+
Validations for UUID (Universally Unique Identifier) data.
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
const uuidVal = new V.UUID(); // Returns string | null
|
|
322
|
+
const notNullUuidVal = new V.UUIDNotNull(); // Returns string
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
UUID Exclusive Conditions
|
|
326
|
+
|
|
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).
|
|
330
|
+
|
|
331
|
+
#### Example
|
|
332
|
+
|
|
333
|
+
#### Basic UUID Validation
|
|
334
|
+
|
|
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
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
#### UUID with Specific Version
|
|
342
|
+
|
|
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"
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
#### UUID without Hyphens
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
const uuidNoHyphensVal = new V.UUID({ allowNoHyphens: true });
|
|
352
|
+
console.log(uuidNoHyphensVal.check("550e8400e29b41d4a716446655440000")); // Output: "550e8400-e29b-41d4-a716-446655440000"
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
#### Strict Mode UUID
|
|
356
|
+
|
|
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
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
291
367
|
***
|
|
292
368
|
## VerificationError
|
|
293
369
|
|
package/dist/index.d.ts
CHANGED
|
@@ -5,22 +5,35 @@ import { VDate, VDateNotNull } from "./src/verifiers/date/v_date";
|
|
|
5
5
|
import { VNumber, VNumberNotNull } from "./src/verifiers/number/v_number";
|
|
6
6
|
import { VObject, VObjectNotNull } from "./src/verifiers/object/v_object";
|
|
7
7
|
import { VString, VStringNotNull } from "./src/verifiers/string/v_string";
|
|
8
|
+
import { VUUID, VUUIDNotNull } from "./src/verifiers/uuid/v_uuid";
|
|
8
9
|
import { Verifier } from './src/verifiers/verifier';
|
|
9
10
|
export { VerificationError } from "./src/error/v_error";
|
|
10
11
|
export { InferType } from "./src/verifiers/type";
|
|
12
|
+
export { Verifier } from './src/verifiers/verifier';
|
|
13
|
+
export { VNumberNotNull, VNumber } from "./src/verifiers/number/v_number";
|
|
14
|
+
export { VStringNotNull, VString } from "./src/verifiers/string/v_string";
|
|
15
|
+
export { VBooleanNotNull, VBoolean } from "./src/verifiers/boolean/v_boolean";
|
|
16
|
+
export { VObjectNotNull, VObject } from "./src/verifiers/object/v_object";
|
|
17
|
+
export { VArrayNotNull, VArray } from "./src/verifiers/array/v_array";
|
|
18
|
+
export { VAny } from "./src/verifiers/any/v_any";
|
|
19
|
+
export { VDateNotNull, VDate } from "./src/verifiers/date/v_date";
|
|
20
|
+
export { VUUIDNotNull, VUUID } from "./src/verifiers/uuid/v_uuid";
|
|
21
|
+
export { datetime } from "./src/utils/datetime";
|
|
11
22
|
export declare const Verifiers: {
|
|
12
23
|
Verifier: typeof Verifier;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
NumberNotNull: typeof VNumberNotNull;
|
|
25
|
+
Number: typeof VNumber;
|
|
26
|
+
StringNotNull: typeof VStringNotNull;
|
|
27
|
+
String: typeof VString;
|
|
28
|
+
Boolean: typeof VBoolean;
|
|
29
|
+
BooleanNotNull: typeof VBooleanNotNull;
|
|
30
|
+
ObjectNotNull: typeof VObjectNotNull;
|
|
31
|
+
Object: typeof VObject;
|
|
32
|
+
Array: typeof VArray;
|
|
33
|
+
ArrayNotNull: typeof VArrayNotNull;
|
|
34
|
+
Any: typeof VAny;
|
|
35
|
+
Date: typeof VDate;
|
|
36
|
+
DateNotNull: typeof VDateNotNull;
|
|
37
|
+
UUIDNotNull: typeof VUUIDNotNull;
|
|
38
|
+
UUID: typeof VUUID;
|
|
26
39
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Verifiers = exports.VerificationError = void 0;
|
|
3
|
+
exports.Verifiers = exports.datetime = exports.VUUID = exports.VUUIDNotNull = exports.VDate = exports.VDateNotNull = exports.VAny = exports.VArray = exports.VArrayNotNull = exports.VObject = exports.VObjectNotNull = exports.VBoolean = exports.VBooleanNotNull = exports.VString = exports.VStringNotNull = exports.VNumber = exports.VNumberNotNull = exports.Verifier = exports.VerificationError = void 0;
|
|
4
4
|
const v_any_1 = require("./src/verifiers/any/v_any");
|
|
5
5
|
const v_array_1 = require("./src/verifiers/array/v_array");
|
|
6
6
|
const v_boolean_1 = require("./src/verifiers/boolean/v_boolean");
|
|
@@ -8,23 +8,53 @@ const v_date_1 = require("./src/verifiers/date/v_date");
|
|
|
8
8
|
const v_number_1 = require("./src/verifiers/number/v_number");
|
|
9
9
|
const v_object_1 = require("./src/verifiers/object/v_object");
|
|
10
10
|
const v_string_1 = require("./src/verifiers/string/v_string");
|
|
11
|
+
const v_uuid_1 = require("./src/verifiers/uuid/v_uuid");
|
|
11
12
|
const verifier_1 = require("./src/verifiers/verifier");
|
|
12
13
|
var v_error_1 = require("./src/error/v_error");
|
|
13
14
|
Object.defineProperty(exports, "VerificationError", { enumerable: true, get: function () { return v_error_1.VerificationError; } });
|
|
15
|
+
var verifier_2 = require("./src/verifiers/verifier");
|
|
16
|
+
Object.defineProperty(exports, "Verifier", { enumerable: true, get: function () { return verifier_2.Verifier; } });
|
|
17
|
+
var v_number_2 = require("./src/verifiers/number/v_number");
|
|
18
|
+
Object.defineProperty(exports, "VNumberNotNull", { enumerable: true, get: function () { return v_number_2.VNumberNotNull; } });
|
|
19
|
+
Object.defineProperty(exports, "VNumber", { enumerable: true, get: function () { return v_number_2.VNumber; } });
|
|
20
|
+
var v_string_2 = require("./src/verifiers/string/v_string");
|
|
21
|
+
Object.defineProperty(exports, "VStringNotNull", { enumerable: true, get: function () { return v_string_2.VStringNotNull; } });
|
|
22
|
+
Object.defineProperty(exports, "VString", { enumerable: true, get: function () { return v_string_2.VString; } });
|
|
23
|
+
var v_boolean_2 = require("./src/verifiers/boolean/v_boolean");
|
|
24
|
+
Object.defineProperty(exports, "VBooleanNotNull", { enumerable: true, get: function () { return v_boolean_2.VBooleanNotNull; } });
|
|
25
|
+
Object.defineProperty(exports, "VBoolean", { enumerable: true, get: function () { return v_boolean_2.VBoolean; } });
|
|
26
|
+
var v_object_2 = require("./src/verifiers/object/v_object");
|
|
27
|
+
Object.defineProperty(exports, "VObjectNotNull", { enumerable: true, get: function () { return v_object_2.VObjectNotNull; } });
|
|
28
|
+
Object.defineProperty(exports, "VObject", { enumerable: true, get: function () { return v_object_2.VObject; } });
|
|
29
|
+
var v_array_2 = require("./src/verifiers/array/v_array");
|
|
30
|
+
Object.defineProperty(exports, "VArrayNotNull", { enumerable: true, get: function () { return v_array_2.VArrayNotNull; } });
|
|
31
|
+
Object.defineProperty(exports, "VArray", { enumerable: true, get: function () { return v_array_2.VArray; } });
|
|
32
|
+
var v_any_2 = require("./src/verifiers/any/v_any");
|
|
33
|
+
Object.defineProperty(exports, "VAny", { enumerable: true, get: function () { return v_any_2.VAny; } });
|
|
34
|
+
var v_date_2 = require("./src/verifiers/date/v_date");
|
|
35
|
+
Object.defineProperty(exports, "VDateNotNull", { enumerable: true, get: function () { return v_date_2.VDateNotNull; } });
|
|
36
|
+
Object.defineProperty(exports, "VDate", { enumerable: true, get: function () { return v_date_2.VDate; } });
|
|
37
|
+
var v_uuid_2 = require("./src/verifiers/uuid/v_uuid");
|
|
38
|
+
Object.defineProperty(exports, "VUUIDNotNull", { enumerable: true, get: function () { return v_uuid_2.VUUIDNotNull; } });
|
|
39
|
+
Object.defineProperty(exports, "VUUID", { enumerable: true, get: function () { return v_uuid_2.VUUID; } });
|
|
40
|
+
var datetime_1 = require("./src/utils/datetime");
|
|
41
|
+
Object.defineProperty(exports, "datetime", { enumerable: true, get: function () { return datetime_1.datetime; } });
|
|
14
42
|
exports.Verifiers = {
|
|
15
43
|
Verifier: verifier_1.Verifier,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
44
|
+
NumberNotNull: v_number_1.VNumberNotNull,
|
|
45
|
+
Number: v_number_1.VNumber,
|
|
46
|
+
StringNotNull: v_string_1.VStringNotNull,
|
|
47
|
+
String: v_string_1.VString,
|
|
48
|
+
Boolean: v_boolean_1.VBoolean,
|
|
49
|
+
BooleanNotNull: v_boolean_1.VBooleanNotNull,
|
|
50
|
+
ObjectNotNull: v_object_1.VObjectNotNull,
|
|
51
|
+
Object: v_object_1.VObject,
|
|
52
|
+
Array: v_array_1.VArray,
|
|
53
|
+
ArrayNotNull: v_array_1.VArrayNotNull,
|
|
54
|
+
Any: v_any_1.VAny,
|
|
55
|
+
Date: v_date_1.VDate,
|
|
56
|
+
DateNotNull: v_date_1.VDateNotNull,
|
|
57
|
+
UUIDNotNull: v_uuid_1.VUUIDNotNull,
|
|
58
|
+
UUID: v_uuid_1.VUUID
|
|
29
59
|
};
|
|
30
60
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AACjD,2DAAsE;AACtE,iEAA8E;AAC9E,wDAAkE;AAClE,8DAA0E;AAC1E,8DAA0E;AAC1E,8DAA0E;AAC1E,uDAAoD;AAEpD,+CAAwD;AAA/C,4GAAA,iBAAiB,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AACjD,2DAAsE;AACtE,iEAA8E;AAC9E,wDAAkE;AAClE,8DAA0E;AAC1E,8DAA0E;AAC1E,8DAA0E;AAC1E,wDAAkE;AAClE,uDAAoD;AAEpD,+CAAwD;AAA/C,4GAAA,iBAAiB,OAAA;AAI1B,qDAAoD;AAA3C,oGAAA,QAAQ,OAAA;AACjB,4DAA0E;AAAjE,0GAAA,cAAc,OAAA;AAAE,mGAAA,OAAO,OAAA;AAChC,4DAA0E;AAAjE,0GAAA,cAAc,OAAA;AAAE,mGAAA,OAAO,OAAA;AAChC,+DAA8E;AAArE,4GAAA,eAAe,OAAA;AAAE,qGAAA,QAAQ,OAAA;AAClC,4DAA0E;AAAjE,0GAAA,cAAc,OAAA;AAAE,mGAAA,OAAO,OAAA;AAChC,yDAAsE;AAA7D,wGAAA,aAAa,OAAA;AAAE,iGAAA,MAAM,OAAA;AAC9B,mDAAiD;AAAxC,6FAAA,IAAI,OAAA;AACb,sDAAkE;AAAzD,sGAAA,YAAY,OAAA;AAAE,+FAAA,KAAK,OAAA;AAC5B,sDAAkE;AAAzD,sGAAA,YAAY,OAAA;AAAE,+FAAA,KAAK,OAAA;AAC5B,iDAAgD;AAAvC,oGAAA,QAAQ,OAAA;AAGJ,QAAA,SAAS,GAAG;IACrB,QAAQ,EAAR,mBAAQ;IACR,aAAa,EAAE,yBAAc;IAC7B,MAAM,EAAE,kBAAO;IACf,aAAa,EAAE,yBAAc;IAC7B,MAAM,EAAE,kBAAO;IACf,OAAO,EAAE,oBAAQ;IACjB,cAAc,EAAE,2BAAe;IAC/B,aAAa,EAAE,yBAAc;IAC7B,MAAM,EAAE,kBAAO;IACf,KAAK,EAAE,gBAAM;IACb,YAAY,EAAE,uBAAa;IAC3B,GAAG,EAAE,YAAI;IACT,IAAI,EAAE,cAAK;IACX,WAAW,EAAE,qBAAY;IACzB,WAAW,EAAE,qBAAY;IACzB,IAAI,EAAE,cAAK;CACd,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.datetime = void 0;
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
exports.datetime = dayjs_1.default;
|
|
9
|
+
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
|
|
10
|
+
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
11
|
+
const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFormat"));
|
|
12
|
+
dayjs_1.default.extend(utc_1.default);
|
|
13
|
+
dayjs_1.default.extend(timezone_1.default);
|
|
14
|
+
dayjs_1.default.extend(customParseFormat_1.default);
|
|
15
|
+
//# sourceMappingURL=datetime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datetime.js","sourceRoot":"","sources":["../../../src/src/utils/datetime.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AASR,mBATX,eAAK,CASc;AAR1B,qEAA6C;AAC7C,2DAAmC;AACnC,uFAA+D;AAE/D,eAAK,CAAC,MAAM,CAAC,aAAG,CAAC,CAAC;AAClB,eAAK,CAAC,MAAM,CAAC,kBAAQ,CAAC,CAAC;AACvB,eAAK,CAAC,MAAM,CAAC,2BAAiB,CAAC,CAAC"}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import moment, { Moment } from "moment-timezone";
|
|
2
1
|
import { IInfo, MessageType, VBadTypeMessage, VDefaultValue, VVCIsRequired } from "../../interfaces/types";
|
|
3
2
|
import { Verifier } from "../verifier";
|
|
4
|
-
|
|
3
|
+
import { datetime } from "../../utils/datetime";
|
|
4
|
+
interface VDateConditions extends VBadTypeMessage, VDefaultValue<datetime.Dayjs>, VVCIsRequired, IInfo<number | string | Date | datetime.Dayjs> {
|
|
5
5
|
format?: MessageType<string, {
|
|
6
6
|
format: string;
|
|
7
7
|
}>;
|
|
8
8
|
timeZone?: MessageType<string, {
|
|
9
9
|
timeZone: string;
|
|
10
10
|
}>;
|
|
11
|
-
maxDate?: MessageType<
|
|
12
|
-
maxDate:
|
|
11
|
+
maxDate?: MessageType<datetime.Dayjs, {
|
|
12
|
+
maxDate: datetime.Dayjs;
|
|
13
13
|
}>;
|
|
14
|
-
minDate?: MessageType<
|
|
15
|
-
minDate:
|
|
14
|
+
minDate?: MessageType<datetime.Dayjs, {
|
|
15
|
+
minDate: datetime.Dayjs;
|
|
16
16
|
}>;
|
|
17
|
-
default?: MessageType<
|
|
18
|
-
default:
|
|
17
|
+
default?: MessageType<datetime.Dayjs, {
|
|
18
|
+
default: datetime.Dayjs;
|
|
19
19
|
}>;
|
|
20
20
|
}
|
|
21
|
-
export declare class VDateNotNull extends Verifier<
|
|
21
|
+
export declare class VDateNotNull extends Verifier<datetime.Dayjs> {
|
|
22
22
|
protected cond?: VDateConditions | undefined;
|
|
23
|
-
check(data: any):
|
|
23
|
+
check(data: any): datetime.Dayjs;
|
|
24
24
|
constructor(cond?: VDateConditions | undefined);
|
|
25
25
|
}
|
|
26
|
-
export declare class VDate extends Verifier<
|
|
26
|
+
export declare class VDate extends Verifier<datetime.Dayjs | null> {
|
|
27
27
|
protected cond?: VDateConditions | undefined;
|
|
28
|
-
check(data: any):
|
|
28
|
+
check(data: any): datetime.Dayjs | null;
|
|
29
29
|
constructor(cond?: VDateConditions | undefined);
|
|
30
30
|
}
|
|
31
31
|
export {};
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.VDate = exports.VDateNotNull = void 0;
|
|
7
|
-
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
8
4
|
const message_1 = require("../../languages/message");
|
|
9
5
|
const v_error_1 = require("../../error/v_error");
|
|
10
6
|
const verifier_1 = require("../verifier");
|
|
11
|
-
|
|
7
|
+
const datetime_1 = require("../../utils/datetime");
|
|
12
8
|
const dMessages = {
|
|
13
9
|
format: {
|
|
14
10
|
es: (values) => `debe tener el formato ${values.format}`,
|
|
@@ -41,16 +37,16 @@ function formatWithTimeZone(format) {
|
|
|
41
37
|
}
|
|
42
38
|
function vDate(data, badTypeMessage, conds) {
|
|
43
39
|
let timeZone = (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.timeZone) || "UTC";
|
|
44
|
-
if (data === '' || !(typeof data === 'number' || typeof data === 'string' || data instanceof Date ||
|
|
40
|
+
if (data === '' || !(typeof data === 'number' || typeof data === 'string' || data instanceof Date || datetime_1.datetime.isDayjs(data))) {
|
|
45
41
|
throw new v_error_1.VerificationError([{
|
|
46
42
|
key: "",
|
|
47
43
|
message: (0, message_1.getMessage)((conds === null || conds === void 0 ? void 0 : conds.badTypeMessage) != undefined ? conds === null || conds === void 0 ? void 0 : conds.badTypeMessage : undefined, undefined, badTypeMessage)
|
|
48
44
|
}]);
|
|
49
45
|
}
|
|
50
|
-
let date = (0,
|
|
46
|
+
let date = (0, datetime_1.datetime)();
|
|
51
47
|
if (conds === null || conds === void 0 ? void 0 : conds.format) {
|
|
52
48
|
let format = (0, message_1.getValue)(conds.format);
|
|
53
|
-
date = (0,
|
|
49
|
+
date = (0, datetime_1.datetime)(data, format, true);
|
|
54
50
|
if (!date.isValid()) {
|
|
55
51
|
throw new v_error_1.VerificationError([{
|
|
56
52
|
key: "",
|
|
@@ -58,13 +54,13 @@ function vDate(data, badTypeMessage, conds) {
|
|
|
58
54
|
}]);
|
|
59
55
|
}
|
|
60
56
|
if (!formatWithTimeZone(format)) {
|
|
61
|
-
date =
|
|
57
|
+
date = datetime_1.datetime.tz(date.format('YYYY-MM-DD HH:mm:ss'), timeZone);
|
|
62
58
|
}
|
|
63
59
|
}
|
|
64
60
|
else {
|
|
65
|
-
date = (0,
|
|
61
|
+
date = (0, datetime_1.datetime)(data);
|
|
66
62
|
if (typeof data === 'string' && !haveTimezone(data)) {
|
|
67
|
-
date =
|
|
63
|
+
date = datetime_1.datetime.tz(date.format('YYYY-MM-DD HH:mm:ss'), timeZone);
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
66
|
if (!date.isValid()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v_date.js","sourceRoot":"","sources":["../../../../src/src/verifiers/date/v_date.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"v_date.js","sourceRoot":"","sources":["../../../../src/src/verifiers/date/v_date.ts"],"names":[],"mappings":";;;AAEA,qDAAiF;AACjF,iDAAwD;AACxD,0CAAuC;AACvC,mDAAgD;AAmBhD,MAAM,SAAS,GAAyB;IACpC,MAAM,EAAE;QACJ,EAAE,EAAE,CAAC,MAA0B,EAAE,EAAE,CAAC,yBAAyB,MAAM,CAAC,MAAM,EAAE;QAC5E,EAAE,EAAE,CAAC,MAA0B,EAAE,EAAE,CAAC,wBAAwB,MAAM,CAAC,MAAM,EAAE;KAC9E;IACD,QAAQ,EAAE;QACN,EAAE,EAAE,CAAC,MAA4B,EAAE,EAAE,CAAC,8BAA8B,MAAM,CAAC,QAAQ,EAAE;QACrF,EAAE,EAAE,CAAC,MAA4B,EAAE,EAAE,CAAC,2BAA2B,MAAM,CAAC,QAAQ,EAAE;KACrF;IACD,OAAO,EAAE;QACL,EAAE,EAAE,CAAC,MAAmC,EAAE,EAAE,CAAC,4BAA4B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;QAClG,EAAE,EAAE,CAAC,MAAmC,EAAE,EAAE,CAAC,4BAA4B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;KACrG;IACD,OAAO,EAAE;QACL,EAAE,EAAE,CAAC,MAAmC,EAAE,EAAE,CAAC,4BAA4B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;QAClG,EAAE,EAAE,CAAC,MAAmC,EAAE,EAAE,CAAC,+BAA+B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;KACxG;IACD,cAAc,EAAE;QACZ,EAAE,EAAE,GAAG,EAA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AARD,oCAQC;AAED,MAAa,KAAM,SAAQ,mBAA+B;IACtD,KAAK,CAAC,IAAS;QACX,IAAI,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IACD,YAAsB,IAAsB;QACxC,KAAK,CAAC,IAAI,CAAC,CAAC;QADM,SAAI,GAAJ,IAAI,CAAkB;QAExC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC,cAAc,CAAC;IACnD,CAAC;CACJ;AAbD,sBAaC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Verifier } from "../verifier";
|
|
2
|
+
import { VBadTypeMessage, VDefaultValue, VVCIsRequired, MessageType } from "../../interfaces/types";
|
|
3
|
+
interface VUUIDConditions extends VBadTypeMessage, VDefaultValue<string>, VVCIsRequired {
|
|
4
|
+
version?: 1 | 2 | 3 | 4 | 5;
|
|
5
|
+
allowNoHyphens?: boolean;
|
|
6
|
+
strictMode?: MessageType<boolean, void>;
|
|
7
|
+
}
|
|
8
|
+
export declare class VUUIDNotNull extends Verifier<string> {
|
|
9
|
+
protected cond?: VUUIDConditions | undefined;
|
|
10
|
+
constructor(cond?: VUUIDConditions | undefined);
|
|
11
|
+
check(data: any): string;
|
|
12
|
+
}
|
|
13
|
+
export declare class VUUID extends Verifier<string | null> {
|
|
14
|
+
protected cond?: VUUIDConditions | undefined;
|
|
15
|
+
constructor(cond?: VUUIDConditions | undefined);
|
|
16
|
+
check(data: any): string | null;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VUUID = exports.VUUIDNotNull = void 0;
|
|
4
|
+
const verifier_1 = require("../verifier");
|
|
5
|
+
const v_error_1 = require("../../error/v_error");
|
|
6
|
+
const message_1 = require("../../languages/message");
|
|
7
|
+
function vUUID(data, badTypeMessage, conds) {
|
|
8
|
+
var _a;
|
|
9
|
+
if (typeof data !== 'string' && (conds === null || conds === void 0 ? void 0 : conds.strictMode)) {
|
|
10
|
+
throw new v_error_1.VerificationError([{
|
|
11
|
+
key: "",
|
|
12
|
+
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.badTypeMessage, undefined, badTypeMessage)
|
|
13
|
+
}]);
|
|
14
|
+
}
|
|
15
|
+
let uuid = String(data);
|
|
16
|
+
const hasHyphens = uuid.includes('-');
|
|
17
|
+
if (!(conds === null || conds === void 0 ? void 0 : conds.allowNoHyphens) && !hasHyphens) {
|
|
18
|
+
throw new v_error_1.VerificationError([{
|
|
19
|
+
key: "",
|
|
20
|
+
message: (0, message_1.getMessage)(undefined, undefined, {
|
|
21
|
+
es: () => `UUID debe incluir guiones`,
|
|
22
|
+
en: () => `UUID must include hyphens`
|
|
23
|
+
})
|
|
24
|
+
}]);
|
|
25
|
+
}
|
|
26
|
+
const normalized = uuid.replace(/-/g, "");
|
|
27
|
+
if (normalized.length !== 32) {
|
|
28
|
+
throw new v_error_1.VerificationError([{
|
|
29
|
+
key: "",
|
|
30
|
+
message: (0, message_1.getMessage)(undefined, undefined, {
|
|
31
|
+
es: () => `UUID inválido, longitud incorrecta`,
|
|
32
|
+
en: () => `Invalid UUID, wrong length`
|
|
33
|
+
})
|
|
34
|
+
}]);
|
|
35
|
+
}
|
|
36
|
+
const versionPattern = (_a = conds === null || conds === void 0 ? void 0 : conds.version) !== null && _a !== void 0 ? _a : "[1-5]";
|
|
37
|
+
const regex = new RegExp(`^[0-9a-f]{8}[0-9a-f]{4}${versionPattern}[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12}$`, "i");
|
|
38
|
+
if (!regex.test(normalized)) {
|
|
39
|
+
throw new v_error_1.VerificationError([{
|
|
40
|
+
key: "",
|
|
41
|
+
message: (0, message_1.getMessage)(undefined, undefined, {
|
|
42
|
+
es: (values) => `UUID inválido${(conds === null || conds === void 0 ? void 0 : conds.version) ? ` para versión ${conds.version}` : ""}`,
|
|
43
|
+
en: (values) => `Invalid UUID${(conds === null || conds === void 0 ? void 0 : conds.version) ? ` for version ${conds.version}` : ""}`
|
|
44
|
+
})
|
|
45
|
+
}]);
|
|
46
|
+
}
|
|
47
|
+
const formatted = [
|
|
48
|
+
normalized.slice(0, 8),
|
|
49
|
+
normalized.slice(8, 12),
|
|
50
|
+
normalized.slice(12, 16),
|
|
51
|
+
normalized.slice(16, 20),
|
|
52
|
+
normalized.slice(20, 32)
|
|
53
|
+
].join('-');
|
|
54
|
+
return formatted.toLowerCase();
|
|
55
|
+
}
|
|
56
|
+
class VUUIDNotNull extends verifier_1.Verifier {
|
|
57
|
+
constructor(cond) {
|
|
58
|
+
super(cond);
|
|
59
|
+
this.cond = cond;
|
|
60
|
+
this.badTypeMessage = {
|
|
61
|
+
es: () => `debe ser un UUID`,
|
|
62
|
+
en: () => `must be a UUID`
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
check(data) {
|
|
66
|
+
return vUUID(this.isRequired(data, true), this.badTypeMessage, this.cond);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.VUUIDNotNull = VUUIDNotNull;
|
|
70
|
+
class VUUID extends verifier_1.Verifier {
|
|
71
|
+
constructor(cond) {
|
|
72
|
+
super(cond);
|
|
73
|
+
this.cond = cond;
|
|
74
|
+
this.badTypeMessage = {
|
|
75
|
+
es: () => `debe ser un UUID`,
|
|
76
|
+
en: () => `must be a UUID`
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
check(data) {
|
|
80
|
+
const val = this.isRequired(data);
|
|
81
|
+
if (val === null || val === undefined)
|
|
82
|
+
return null;
|
|
83
|
+
return vUUID(val, this.badTypeMessage, this.cond);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.VUUID = VUUID;
|
|
87
|
+
//# sourceMappingURL=v_uuid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v_uuid.js","sourceRoot":"","sources":["../../../../src/src/verifiers/uuid/v_uuid.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,iDAAwD;AACxD,qDAAuE;AASvE,SAAS,KAAK,CAAC,IAAS,EAAE,cAAsC,EAAE,KAAuB;;IACrF,IAAI,OAAO,IAAI,KAAK,QAAQ,KAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,CAAA,EAAE,CAAC;QAChD,MAAM,IAAI,2BAAiB,CAAC,CAAC;gBACzB,GAAG,EAAE,EAAE;gBACP,OAAO,EAAE,IAAA,oBAAU,EAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,EAAE,SAAS,EAAE,cAAc,CAAC;aACxE,CAAC,CAAC,CAAC;IACR,CAAC;IAED,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAExB,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAEtC,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,CAAA,IAAI,CAAC,UAAU,EAAE,CAAC;QACxC,MAAM,IAAI,2BAAiB,CAAC,CAAC;gBACzB,GAAG,EAAE,EAAE;gBACP,OAAO,EAAE,IAAA,oBAAU,EAAC,SAAS,EAAE,SAAS,EAAE;oBACtC,EAAE,EAAE,GAAG,EAAE,CAAC,2BAA2B;oBACrC,EAAE,EAAE,GAAG,EAAE,CAAC,2BAA2B;iBACxC,CAAC;aACL,CAAC,CAAC,CAAC;IACR,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CA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AI,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;CACJ;AAdD,sBAcC"}
|
|
@@ -9,13 +9,18 @@ class Verifier {
|
|
|
9
9
|
this.cond = cond;
|
|
10
10
|
}
|
|
11
11
|
isRequired(data, isRequired) {
|
|
12
|
-
var _a;
|
|
12
|
+
var _a, _b;
|
|
13
13
|
let mReq = {
|
|
14
14
|
es: () => "es requerido y",
|
|
15
15
|
en: () => "is required and"
|
|
16
16
|
};
|
|
17
|
+
if (typeof data === 'string' && ((_a = this.cond) === null || _a === void 0 ? void 0 : _a.emptyAsNull) === true) {
|
|
18
|
+
if (data.length === 0) {
|
|
19
|
+
data = null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
17
22
|
let reqVal = false;
|
|
18
|
-
if (((
|
|
23
|
+
if (((_b = this.cond) === null || _b === void 0 ? void 0 : _b.isRequired) !== undefined) {
|
|
19
24
|
reqVal = this.cond.isRequired;
|
|
20
25
|
if (isRequired !== undefined) {
|
|
21
26
|
if (typeof reqVal === 'boolean') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../../src/src/verifiers/verifier.ts"],"names":[],"mappings":";;;AAAA,6DAA0D;AAC1D,8CAAqD;AAErD,kDAAiF;AAEjF,MAAsB,QAAQ;IAC1B,YAAsB,IAAoB;QAApB,SAAI,GAAJ,IAAI,CAAgB;IAAI,CAAC;IAGrC,UAAU,CAAC,IAAS,EAAE,UAAoB;;QAChD,IAAI,IAAI,GAA2B;YAC/B,EAAE,EAAE,GAAG,EAAE,CAAC,gBAAgB;YAC1B,EAAE,EAAE,GAAG,EAAE,CAAC,iBAAiB;SAC9B,CAAA;QACD,IAAI,MAAM,GAA+B,KAAK,CAAC;QAC/C,IAAI,CAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,UAAU,MAAK,SAAS,EAAE,CAAC;YACtC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,UA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ist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
"typescript": "^5.3.3"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"
|
|
33
|
+
"dayjs": "^1.11.19"
|
|
34
34
|
}
|
|
35
35
|
}
|