structure-verifier 0.0.4 → 0.0.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/README.md +49 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/src/verifiers/any/v_any.d.ts +1 -1
- package/dist/src/verifiers/date/v_date.d.ts +31 -0
- package/dist/src/verifiers/date/v_date.js +115 -0
- package/dist/src/verifiers/date/v_date.js.map +1 -1
- package/dist/src/verifiers/date/v_date.test.d.ts +1 -0
- package/dist/src/verifiers/date/v_date.test.js.map +1 -0
- package/dist/src/verifiers/object/v_object.d.ts +16 -3
- package/dist/src/verifiers/object/v_object.js +3 -0
- package/dist/src/verifiers/object/v_object.js.map +1 -1
- package/package.json +1 -1
- package/dist/src/verifiers/any/v_any.test.js +0 -13
- package/dist/src/verifiers/array/v_array.test.js +0 -74
- package/dist/src/verifiers/boolean/v_boolean.test.js +0 -61
- package/dist/src/verifiers/number/v_number.test.js +0 -91
- package/dist/src/verifiers/object/v_object.test.js +0 -73
- package/dist/src/verifiers/string/v_string.test.js +0 -103
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# structure-verifier 0.0.
|
|
1
|
+
# structure-verifier 0.0.6
|
|
2
2
|
|
|
3
3
|
structure-verifier is a typescrpt library to validate data of "any" type and to ensure that it corresponds to a data type.
|
|
4
4
|
|
|
@@ -238,4 +238,52 @@ try {
|
|
|
238
238
|
} catch (error) {
|
|
239
239
|
console.error(error);
|
|
240
240
|
}
|
|
241
|
+
```
|
|
242
|
+
***
|
|
243
|
+
### Date
|
|
244
|
+
Validations for date data (depends Moment).
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
const vdate = new V.VDate();
|
|
248
|
+
const vdateNotNull = new V.VDateNotNull();
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
VDate Exclusive Conditions
|
|
252
|
+
|
|
253
|
+
- **format**: Specifies the date format to be validated against.
|
|
254
|
+
- **timeZone**: Specifies the expected time zone of the input date.
|
|
255
|
+
- **maxDate**: Specifies the maximum allowed date.
|
|
256
|
+
- **minDate**: Specifies the minimum allowed date.
|
|
257
|
+
|
|
258
|
+
#### Example
|
|
259
|
+
#### Basic Date Validation
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
const vdate = new V.VDate();
|
|
263
|
+
console.log(vdate.check("2023-08-09")?.format("YYYY-MM-DD")); // Output: "2023-08-09"
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
#### Date with Specific Format
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
const vdate = new V.VDate({ format: "DD/MM/YYYY" });
|
|
270
|
+
console.log(vdate.check("09/08/2023")?.format("DD/MM/YYYY")); // Output: "09/08/2023"
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
#### Date with Time Zone
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
const vdate = new V.VDate({ timeZone: "America/New_York" });
|
|
277
|
+
const result = vdate.check("2023-08-09T10:00:00");
|
|
278
|
+
console.log(result.tz("America/New_York").format()); // Output: "2023-08-09T10:00:00-04:00"
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
#### Date within Range
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
const vdate = new V.VDate({
|
|
285
|
+
minDate: moment("2023-01-01"),
|
|
286
|
+
maxDate: moment("2023-12-31")
|
|
287
|
+
});
|
|
288
|
+
console.log(vdate.check("2023-08-09").format("YYYY-MM-DD")); // Output: "2023-08-09"
|
|
241
289
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { VAny } from "./src/verifiers/any/v_any";
|
|
2
2
|
import { VArray, VArrayNotNull } from "./src/verifiers/array/v_array";
|
|
3
3
|
import { VBoolean, VBooleanNotNull } from "./src/verifiers/boolean/v_boolean";
|
|
4
|
+
import { VDate, VDateNotNull } from "./src/verifiers/date/v_date";
|
|
4
5
|
import { VNumber, VNumberNotNull } from "./src/verifiers/number/v_number";
|
|
5
6
|
import { VObject, VObjectNotNull } from "./src/verifiers/object/v_object";
|
|
6
7
|
import { VString, VStringNotNull } from "./src/verifiers/string/v_string";
|
|
@@ -18,4 +19,6 @@ export declare const Verifiers: {
|
|
|
18
19
|
VArray: typeof VArray;
|
|
19
20
|
VArrayNotNull: typeof VArrayNotNull;
|
|
20
21
|
VAny: typeof VAny;
|
|
22
|
+
VDate: typeof VDate;
|
|
23
|
+
VDateNotNull: typeof VDateNotNull;
|
|
21
24
|
};
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Verifiers = 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");
|
|
7
|
+
const v_date_1 = require("./src/verifiers/date/v_date");
|
|
7
8
|
const v_number_1 = require("./src/verifiers/number/v_number");
|
|
8
9
|
const v_object_1 = require("./src/verifiers/object/v_object");
|
|
9
10
|
const v_string_1 = require("./src/verifiers/string/v_string");
|
|
@@ -20,6 +21,8 @@ exports.Verifiers = {
|
|
|
20
21
|
VObject: v_object_1.VObject,
|
|
21
22
|
VArray: v_array_1.VArray,
|
|
22
23
|
VArrayNotNull: v_array_1.VArrayNotNull,
|
|
23
|
-
VAny: v_any_1.VAny
|
|
24
|
+
VAny: v_any_1.VAny,
|
|
25
|
+
VDate: v_date_1.VDate,
|
|
26
|
+
VDateNotNull: v_date_1.VDateNotNull
|
|
24
27
|
};
|
|
25
28
|
//# 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,8DAA0E;AAC1E,8DAA0E;AAC1E,8DAA0E;AAC1E,uDAAoD;AAIvC,QAAA,SAAS,GAAG;IACrB,QAAQ,EAAR,mBAAQ;IACR,cAAc,EAAd,yBAAc;IACd,OAAO,EAAP,kBAAO;IACP,cAAc,EAAd,yBAAc;IACd,OAAO,EAAP,kBAAO;IACP,QAAQ,EAAR,oBAAQ;IACR,eAAe,EAAf,2BAAe;IACf,cAAc,EAAd,yBAAc;IACd,OAAO,EAAP,kBAAO;IACP,MAAM,EAAN,gBAAM;IACN,aAAa,EAAb,uBAAa;IACb,IAAI,EAAJ,YAAI;
|
|
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;AAIvC,QAAA,SAAS,GAAG;IACrB,QAAQ,EAAR,mBAAQ;IACR,cAAc,EAAd,yBAAc;IACd,OAAO,EAAP,kBAAO;IACP,cAAc,EAAd,yBAAc;IACd,OAAO,EAAP,kBAAO;IACP,QAAQ,EAAR,oBAAQ;IACR,eAAe,EAAf,2BAAe;IACf,cAAc,EAAd,yBAAc;IACd,OAAO,EAAP,kBAAO;IACP,MAAM,EAAN,gBAAM;IACN,aAAa,EAAb,uBAAa;IACb,IAAI,EAAJ,YAAI;IACJ,KAAK,EAAL,cAAK;IACL,YAAY,EAAZ,qBAAY;CACf,CAAA"}
|
|
@@ -4,7 +4,7 @@ interface VAnyConditions extends VBadTypeMessage, VDefaultValue<number>, VVCIsRe
|
|
|
4
4
|
}
|
|
5
5
|
export declare class VAny extends Verifier<any | null> {
|
|
6
6
|
protected cond?: VAnyConditions | undefined;
|
|
7
|
-
check(data: any):
|
|
7
|
+
check(data: any): any | null;
|
|
8
8
|
constructor(cond?: VAnyConditions | undefined);
|
|
9
9
|
}
|
|
10
10
|
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import moment, { Moment } from "moment-timezone";
|
|
2
|
+
import { IInfo, MessageType, VBadTypeMessage, VDefaultValue, VVCIsRequired } from "../../interfaces/types";
|
|
3
|
+
import { Verifier } from "../verifier";
|
|
4
|
+
interface VDateConditions extends VBadTypeMessage, VDefaultValue<Moment>, VVCIsRequired, IInfo<number | string | Date | moment.Moment> {
|
|
5
|
+
format?: MessageType<string, {
|
|
6
|
+
format: string;
|
|
7
|
+
}>;
|
|
8
|
+
timeZone?: MessageType<string, {
|
|
9
|
+
timeZone: string;
|
|
10
|
+
}>;
|
|
11
|
+
maxDate?: MessageType<moment.Moment, {
|
|
12
|
+
maxDate: moment.Moment;
|
|
13
|
+
}>;
|
|
14
|
+
minDate?: MessageType<moment.Moment, {
|
|
15
|
+
minDate: moment.Moment;
|
|
16
|
+
}>;
|
|
17
|
+
default?: MessageType<moment.Moment, {
|
|
18
|
+
default: moment.Moment;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
export declare class VDateNotNull extends Verifier<moment.Moment> {
|
|
22
|
+
protected cond?: VDateConditions | undefined;
|
|
23
|
+
check(data: any): moment.Moment;
|
|
24
|
+
constructor(cond?: VDateConditions | undefined);
|
|
25
|
+
}
|
|
26
|
+
export declare class VDate extends Verifier<moment.Moment | null> {
|
|
27
|
+
protected cond?: VDateConditions | undefined;
|
|
28
|
+
check(data: any): moment.Moment | null;
|
|
29
|
+
constructor(cond?: VDateConditions | undefined);
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -1,2 +1,117 @@
|
|
|
1
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.VDate = exports.VDateNotNull = void 0;
|
|
7
|
+
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
8
|
+
const message_1 = require("../../languages/message");
|
|
9
|
+
const v_error_1 = require("../../error/v_error");
|
|
10
|
+
const verifier_1 = require("../verifier");
|
|
11
|
+
moment_timezone_1.default.suppressDeprecationWarnings = true;
|
|
12
|
+
const dMessages = {
|
|
13
|
+
format: {
|
|
14
|
+
es: (values) => `debe tener el formato ${values.format}`,
|
|
15
|
+
en: (values) => `must have the format ${values.format}`
|
|
16
|
+
},
|
|
17
|
+
timeZone: {
|
|
18
|
+
es: (values) => `debe tener la zona horaria ${values.timeZone}`,
|
|
19
|
+
en: (values) => `must have the time zone ${values.timeZone}`
|
|
20
|
+
},
|
|
21
|
+
maxDate: {
|
|
22
|
+
es: (values) => `debe ser menor o igual a ${values.maxDate.format()}`,
|
|
23
|
+
en: (values) => `must be less or equal to ${values.maxDate.format()}`
|
|
24
|
+
},
|
|
25
|
+
minDate: {
|
|
26
|
+
es: (values) => `debe ser mayor o igual a ${values.minDate.format()}`,
|
|
27
|
+
en: (values) => `must be greater or equal to ${values.minDate.format()}`
|
|
28
|
+
},
|
|
29
|
+
badTypeMessage: {
|
|
30
|
+
es: () => `debe ser una fecha`,
|
|
31
|
+
en: () => `must be a date`
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
function haveTimezone(input) {
|
|
35
|
+
const regexDesplazamiento = /(?:UTC|GMT|[+-]\d{2}:?\d{2})$/;
|
|
36
|
+
const regexIdentificadorZona = /(?:Europe\/|America\/|Asia\/|Africa\/|Australia\/|Antarctica\/|Atlantic\/|Indian\/|Pacific\/)[A-Za-z_]+/;
|
|
37
|
+
return regexDesplazamiento.test(input) || regexIdentificadorZona.test(input);
|
|
38
|
+
}
|
|
39
|
+
function formatWithTimeZone(format) {
|
|
40
|
+
return /Z{1,2}|z{1,2}/.test(format);
|
|
41
|
+
}
|
|
42
|
+
function vDate(data, badTypeMessage, conds) {
|
|
43
|
+
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 || moment_timezone_1.default.isMoment(data))) {
|
|
45
|
+
throw new v_error_1.VerificationError([{
|
|
46
|
+
key: "",
|
|
47
|
+
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
|
+
}]);
|
|
49
|
+
}
|
|
50
|
+
let date = (0, moment_timezone_1.default)();
|
|
51
|
+
if (conds === null || conds === void 0 ? void 0 : conds.format) {
|
|
52
|
+
let format = (0, message_1.getValue)(conds.format);
|
|
53
|
+
date = (0, moment_timezone_1.default)(data, format, true);
|
|
54
|
+
if (!date.isValid()) {
|
|
55
|
+
throw new v_error_1.VerificationError([{
|
|
56
|
+
key: "",
|
|
57
|
+
message: (0, message_1.getMessage)(conds.format, { format: format }, dMessages.format)
|
|
58
|
+
}]);
|
|
59
|
+
}
|
|
60
|
+
if (!formatWithTimeZone(format)) {
|
|
61
|
+
date = moment_timezone_1.default.tz(date.format('YYYY-MM-DD HH:mm:ss'), timeZone);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
date = (0, moment_timezone_1.default)(data);
|
|
66
|
+
if (typeof data === 'string' && !haveTimezone(data)) {
|
|
67
|
+
date = moment_timezone_1.default.tz(date.format('YYYY-MM-DD HH:mm:ss'), timeZone);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!date.isValid()) {
|
|
71
|
+
throw new v_error_1.VerificationError([{
|
|
72
|
+
key: "",
|
|
73
|
+
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)
|
|
74
|
+
}]);
|
|
75
|
+
}
|
|
76
|
+
if ((conds === null || conds === void 0 ? void 0 : conds.maxDate) && date.isAfter((0, message_1.getValue)(conds.maxDate))) {
|
|
77
|
+
throw new v_error_1.VerificationError([{
|
|
78
|
+
key: "",
|
|
79
|
+
message: (0, message_1.getMessage)(conds.maxDate, { maxDate: (0, message_1.getValue)(conds.maxDate) }, dMessages.maxDate)
|
|
80
|
+
}]);
|
|
81
|
+
}
|
|
82
|
+
if ((conds === null || conds === void 0 ? void 0 : conds.minDate) && date.isBefore((0, message_1.getValue)(conds.minDate))) {
|
|
83
|
+
throw new v_error_1.VerificationError([{
|
|
84
|
+
key: "",
|
|
85
|
+
message: (0, message_1.getMessage)(conds.minDate, { minDate: (0, message_1.getValue)(conds.minDate) }, dMessages.minDate)
|
|
86
|
+
}]);
|
|
87
|
+
}
|
|
88
|
+
return date;
|
|
89
|
+
}
|
|
90
|
+
class VDateNotNull extends verifier_1.Verifier {
|
|
91
|
+
check(data) {
|
|
92
|
+
return vDate(this.isRequired(data, true), this.badTypeMessage, this.cond);
|
|
93
|
+
}
|
|
94
|
+
constructor(cond) {
|
|
95
|
+
super(cond);
|
|
96
|
+
this.cond = cond;
|
|
97
|
+
this.badTypeMessage = dMessages.badTypeMessage;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.VDateNotNull = VDateNotNull;
|
|
101
|
+
class VDate extends verifier_1.Verifier {
|
|
102
|
+
check(data) {
|
|
103
|
+
let val = this.isRequired(data);
|
|
104
|
+
if (val === null || val === undefined) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return vDate(val, this.badTypeMessage, this.cond);
|
|
108
|
+
}
|
|
109
|
+
constructor(cond) {
|
|
110
|
+
super(cond);
|
|
111
|
+
this.cond = cond;
|
|
112
|
+
this.cond = cond;
|
|
113
|
+
this.badTypeMessage = dMessages.badTypeMessage;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.VDate = VDate;
|
|
2
117
|
//# sourceMappingURL=v_date.js.map
|
|
@@ -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":";;;;;;AAAA,sEAAiD;AAEjD,qDAAiF;AACjF,iDAAwD;AACxD,0CAAuC;AACvC,yBAAM,CAAC,2BAA2B,GAAG,IAAI,CAAC;AAkB1C,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,MAAkC,EAAE,EAAE,CAAC,4BAA4B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;QACjG,EAAE,EAAE,CAAC,MAAkC,EAAE,EAAE,CAAC,4BAA4B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;KACpG;IACD,OAAO,EAAE;QACL,EAAE,EAAE,CAAC,MAAkC,EAAE,EAAE,CAAC,4BAA4B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;QACjG,EAAE,EAAE,CAAC,MAAkC,EAAE,EAAE,CAAC,+BAA+B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;KACvG;IACD,cAAc,EAAE;QACZ,EAAE,EAAE,GAAG,EAAE,CAAC,oBAAoB;QAC9B,EAAE,EAAE,GAAG,EAAE,CAAC,gBAAgB;KAC7B;CACJ,CAAA;AAED,SAAS,YAAY,CAAC,K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AAC,OAAO,CAAC,2BAAiB,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACrD,MAAM,YAAY,GAAG,IAAI,iBAAC,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;QAClE,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACpF,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,2BAAiB,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import { MessageType, VBadTypeMessage, VDefaultValue, VVCIsRequired } from "../../interfaces/types";
|
|
2
2
|
import { Verifier } from "../verifier";
|
|
3
|
-
interface VObjectConditions<T
|
|
3
|
+
interface VObjectConditions<T extends Record<string, Verifier<any>>> extends VBadTypeMessage, VDefaultValue<T>, VVCIsRequired {
|
|
4
4
|
invalidPropertyMessage?: MessageType<void, void>;
|
|
5
5
|
strictMode?: boolean;
|
|
6
6
|
ignoreCase?: boolean;
|
|
7
7
|
takeAllValues?: boolean;
|
|
8
8
|
properties: T;
|
|
9
|
+
conds?: (val: {
|
|
10
|
+
[K in keyof T]: ReturnType<T[K]['check']>;
|
|
11
|
+
} | null) => void;
|
|
12
|
+
}
|
|
13
|
+
interface VObjectConditionsNotNull<T extends Record<string, Verifier<any>>> extends VBadTypeMessage, VDefaultValue<T>, VVCIsRequired {
|
|
14
|
+
invalidPropertyMessage?: MessageType<void, void>;
|
|
15
|
+
strictMode?: boolean;
|
|
16
|
+
ignoreCase?: boolean;
|
|
17
|
+
takeAllValues?: boolean;
|
|
18
|
+
properties: T;
|
|
19
|
+
conds?: (val: {
|
|
20
|
+
[K in keyof T]: ReturnType<T[K]['check']>;
|
|
21
|
+
}) => void;
|
|
9
22
|
}
|
|
10
23
|
export declare class VObjectNotNull<T extends Record<string, Verifier<any>>> extends Verifier<{
|
|
11
24
|
[K in keyof T]: ReturnType<T[K]['check']>;
|
|
12
25
|
}> {
|
|
13
|
-
protected cond:
|
|
26
|
+
protected cond: VObjectConditionsNotNull<T>;
|
|
14
27
|
check(data: any): {
|
|
15
28
|
[K in keyof T]: ReturnType<T[K]['check']>;
|
|
16
29
|
};
|
|
17
|
-
constructor(cond:
|
|
30
|
+
constructor(cond: VObjectConditionsNotNull<T>);
|
|
18
31
|
}
|
|
19
32
|
export declare class VObject<T extends Record<string, Verifier<any>>> extends Verifier<{
|
|
20
33
|
[K in keyof T]: ReturnType<T[K]['check']>;
|
|
@@ -93,6 +93,9 @@ function vObject(data, badTypeMessage, conds) {
|
|
|
93
93
|
if (errors.length > 0) {
|
|
94
94
|
throw new v_error_1.VerificationError(errors);
|
|
95
95
|
}
|
|
96
|
+
if (conds.conds) {
|
|
97
|
+
conds.conds(value);
|
|
98
|
+
}
|
|
96
99
|
return value;
|
|
97
100
|
}
|
|
98
101
|
class VObjectNotNull extends verifier_1.Verifier {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v_object.js","sourceRoot":"","sources":["../../../../src/src/verifiers/object/v_object.ts"],"names":[],"mappings":";;;AAAA,iDAAwD;AAExD,qDAAuE;AACvE,wCAAoC;AACpC,8CAAyD;AACzD,0CAAuC;
|
|
1
|
+
{"version":3,"file":"v_object.js","sourceRoot":"","sources":["../../../../src/src/verifiers/object/v_object.ts"],"names":[],"mappings":";;;AAAA,iDAAwD;AAExD,qDAAuE;AACvE,wCAAoC;AACpC,8CAAyD;AACzD,0CAAuC;AAoBvC,SAAS,OAAO,CAA0C,IAAS,EAAE,cAAsC,EAAE,KAAyD;IAClK,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAA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ClB,EAAE,EAAE,GAAG,EAAE,CAAC,oBAAoB;YAC9B,EAAE,EAAE,GAAG,EAAE,CAAC,kBAAkB;SAC/B,CAAA;IACL,CAAC;CACJ;AAfD,0BAeC"}
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("../../../index");
|
|
4
|
-
describe('VAny', () => {
|
|
5
|
-
it('should validate data as any', () => {
|
|
6
|
-
const validator = new index_1.Verifiers.VAny();
|
|
7
|
-
expect(validator.check([1, 2, 3])).toEqual([1, 2, 3]);
|
|
8
|
-
expect(validator.check(null)).toBeNull();
|
|
9
|
-
expect(validator.check(1)).toEqual(1);
|
|
10
|
-
expect(validator.check("TEST")).toEqual("TEST");
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
//# sourceMappingURL=v_any.test.js.map
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("../../../index");
|
|
4
|
-
const v_error_1 = require("../../error/v_error");
|
|
5
|
-
describe('VArray', () => {
|
|
6
|
-
it('should validate arrays with valid data', () => {
|
|
7
|
-
const validator = new index_1.Verifiers.VArray({
|
|
8
|
-
verifier: new index_1.Verifiers.VNumberNotNull()
|
|
9
|
-
});
|
|
10
|
-
expect(validator.check([1, 2, 3])).toEqual([1, 2, 3]);
|
|
11
|
-
});
|
|
12
|
-
it('should throw a validation error for arrays with invalid data', () => {
|
|
13
|
-
const validator = new index_1.Verifiers.VArray({
|
|
14
|
-
verifier: new index_1.Verifiers.VNumberNotNull()
|
|
15
|
-
});
|
|
16
|
-
expect(() => validator.check([1, "2a", 3])).toThrow(v_error_1.VerificationError);
|
|
17
|
-
});
|
|
18
|
-
it('should return null for null or undefined values', () => {
|
|
19
|
-
const validator = new index_1.Verifiers.VArray({
|
|
20
|
-
verifier: new index_1.Verifiers.VNumberNotNull()
|
|
21
|
-
});
|
|
22
|
-
expect(validator.check(null)).toBeNull();
|
|
23
|
-
});
|
|
24
|
-
it('should throw a validation error for arrays that do not meet minLength condition', () => {
|
|
25
|
-
const validator = new index_1.Verifiers.VArray({
|
|
26
|
-
verifier: new index_1.Verifiers.VNumberNotNull(),
|
|
27
|
-
minLength: 3
|
|
28
|
-
});
|
|
29
|
-
expect(() => validator.check([1, 2])).toThrow(v_error_1.VerificationError);
|
|
30
|
-
});
|
|
31
|
-
it('should throw a validation error for arrays that exceed maxLength condition', () => {
|
|
32
|
-
const validator = new index_1.Verifiers.VArray({
|
|
33
|
-
maxLength: 2,
|
|
34
|
-
verifier: new index_1.Verifiers.VNumberNotNull()
|
|
35
|
-
});
|
|
36
|
-
expect(() => validator.check([1, 2, 3])).toThrow(v_error_1.VerificationError);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe('VArrayNotNull', () => {
|
|
40
|
-
it('should validate arrays with valid data', () => {
|
|
41
|
-
const validator = new index_1.Verifiers.VArrayNotNull({
|
|
42
|
-
verifier: new index_1.Verifiers.VNumberNotNull()
|
|
43
|
-
});
|
|
44
|
-
expect(validator.check([1, 2, 3])).toEqual([1, 2, 3]);
|
|
45
|
-
});
|
|
46
|
-
it('should throw a validation error for arrays with invalid data', () => {
|
|
47
|
-
const validator = new index_1.Verifiers.VArrayNotNull({
|
|
48
|
-
verifier: new index_1.Verifiers.VNumberNotNull()
|
|
49
|
-
});
|
|
50
|
-
expect(() => validator.check([1, "2a", 3])).toThrow(v_error_1.VerificationError);
|
|
51
|
-
});
|
|
52
|
-
it('should throw a validation error for null or undefined values', () => {
|
|
53
|
-
const validator = new index_1.Verifiers.VArrayNotNull({
|
|
54
|
-
verifier: new index_1.Verifiers.VNumberNotNull()
|
|
55
|
-
});
|
|
56
|
-
expect(() => validator.check(null)).toThrow(v_error_1.VerificationError);
|
|
57
|
-
expect(() => validator.check(undefined)).toThrow(v_error_1.VerificationError);
|
|
58
|
-
});
|
|
59
|
-
it('should throw a validation error for arrays that do not meet minLength condition', () => {
|
|
60
|
-
const validator = new index_1.Verifiers.VArrayNotNull({
|
|
61
|
-
verifier: new index_1.Verifiers.VNumberNotNull(),
|
|
62
|
-
minLength: 3
|
|
63
|
-
});
|
|
64
|
-
expect(() => validator.check([1, 2])).toThrow(v_error_1.VerificationError);
|
|
65
|
-
});
|
|
66
|
-
it('should throw a validation error for arrays that exceed maxLength condition', () => {
|
|
67
|
-
const validator = new index_1.Verifiers.VArrayNotNull({
|
|
68
|
-
verifier: new index_1.Verifiers.VNumberNotNull(),
|
|
69
|
-
maxLength: 2
|
|
70
|
-
});
|
|
71
|
-
expect(() => validator.check([1, 2, 3])).toThrow(v_error_1.VerificationError);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
//# sourceMappingURL=v_array.test.js.map
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("../../../index");
|
|
4
|
-
const v_error_1 = require("../../error/v_error");
|
|
5
|
-
describe('VBoolean', () => {
|
|
6
|
-
it('should validate true for various true values', () => {
|
|
7
|
-
const validator = new index_1.Verifiers.VBoolean();
|
|
8
|
-
expect(validator.check('1')).toBe(true);
|
|
9
|
-
expect(validator.check(1)).toBe(true);
|
|
10
|
-
expect(validator.check(true)).toBe(true);
|
|
11
|
-
expect(validator.check('TRUE')).toBe(true);
|
|
12
|
-
expect(validator.check('true')).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
it('should validate false for various false values', () => {
|
|
15
|
-
const validator = new index_1.Verifiers.VBoolean();
|
|
16
|
-
expect(validator.check('0')).toBe(false);
|
|
17
|
-
expect(validator.check(0)).toBe(false);
|
|
18
|
-
expect(validator.check(false)).toBe(false);
|
|
19
|
-
expect(validator.check('FALSE')).toBe(false);
|
|
20
|
-
expect(validator.check('false')).toBe(false);
|
|
21
|
-
});
|
|
22
|
-
it('should throw a validation error for invalid boolean values', () => {
|
|
23
|
-
const validator = new index_1.Verifiers.VBoolean();
|
|
24
|
-
expect(() => validator.check('string')).toThrow(v_error_1.VerificationError);
|
|
25
|
-
expect(() => validator.check(123)).toThrow(v_error_1.VerificationError);
|
|
26
|
-
});
|
|
27
|
-
it('should return null for null or undefined values', () => {
|
|
28
|
-
const validator = new index_1.Verifiers.VBoolean();
|
|
29
|
-
expect(validator.check(null)).toBeNull();
|
|
30
|
-
expect(validator.check(undefined)).toBeNull();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
describe('VBooleanNotNull', () => {
|
|
34
|
-
it('should validate true for various true values', () => {
|
|
35
|
-
const validator = new index_1.Verifiers.VBooleanNotNull();
|
|
36
|
-
expect(validator.check('1')).toBe(true);
|
|
37
|
-
expect(validator.check(1)).toBe(true);
|
|
38
|
-
expect(validator.check(true)).toBe(true);
|
|
39
|
-
expect(validator.check('TRUE')).toBe(true);
|
|
40
|
-
expect(validator.check('true')).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
it('should validate false for various false values', () => {
|
|
43
|
-
const validator = new index_1.Verifiers.VBooleanNotNull();
|
|
44
|
-
expect(validator.check('0')).toBe(false);
|
|
45
|
-
expect(validator.check(0)).toBe(false);
|
|
46
|
-
expect(validator.check(false)).toBe(false);
|
|
47
|
-
expect(validator.check('FALSE')).toBe(false);
|
|
48
|
-
expect(validator.check('false')).toBe(false);
|
|
49
|
-
});
|
|
50
|
-
it('should throw a validation error for invalid boolean values', () => {
|
|
51
|
-
const validator = new index_1.Verifiers.VBooleanNotNull();
|
|
52
|
-
expect(() => validator.check('string')).toThrow(v_error_1.VerificationError);
|
|
53
|
-
expect(() => validator.check(123)).toThrow(v_error_1.VerificationError);
|
|
54
|
-
});
|
|
55
|
-
it('should throw a validation error for null or undefined values', () => {
|
|
56
|
-
const validator = new index_1.Verifiers.VBooleanNotNull();
|
|
57
|
-
expect(() => validator.check(null)).toThrow(v_error_1.VerificationError);
|
|
58
|
-
expect(() => validator.check(undefined)).toThrow(v_error_1.VerificationError);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
//# sourceMappingURL=v_boolean.test.js.map
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("../../../index");
|
|
4
|
-
const v_error_1 = require("../../error/v_error");
|
|
5
|
-
describe('VNumber', () => {
|
|
6
|
-
it('should validate a number correctly', () => {
|
|
7
|
-
const validator = new index_1.Verifiers.VNumber();
|
|
8
|
-
expect(validator.check(123)).toBe(123);
|
|
9
|
-
expect(validator.check(null)).toBeNull();
|
|
10
|
-
});
|
|
11
|
-
it('should throw a validation error for min', () => {
|
|
12
|
-
const validator = new index_1.Verifiers.VNumber({ min: 10 });
|
|
13
|
-
expect(() => validator.check(5)).toThrow(v_error_1.VerificationError);
|
|
14
|
-
expect(validator.check(10)).toBe(10);
|
|
15
|
-
});
|
|
16
|
-
it('should throw a validation error for max', () => {
|
|
17
|
-
const validator = new index_1.Verifiers.VNumber({ max: 10 });
|
|
18
|
-
expect(() => validator.check(15)).toThrow(v_error_1.VerificationError);
|
|
19
|
-
expect(validator.check(5)).toBe(5);
|
|
20
|
-
});
|
|
21
|
-
it('should throw a validation error for in', () => {
|
|
22
|
-
const validator = new index_1.Verifiers.VNumber({ in: [1, 2, 3] });
|
|
23
|
-
expect(() => validator.check(4)).toThrow(v_error_1.VerificationError);
|
|
24
|
-
expect(validator.check(2)).toBe(2);
|
|
25
|
-
});
|
|
26
|
-
it('should throw a validation error for notIn', () => {
|
|
27
|
-
const validator = new index_1.Verifiers.VNumber({ notIn: [1, 2, 3] });
|
|
28
|
-
expect(() => validator.check(2)).toThrow(v_error_1.VerificationError);
|
|
29
|
-
expect(validator.check(4)).toBe(4);
|
|
30
|
-
});
|
|
31
|
-
it('should throw a validation error for maxDecimalPlaces', () => {
|
|
32
|
-
const validator = new index_1.Verifiers.VNumber({ maxDecimalPlaces: 2 });
|
|
33
|
-
expect(() => validator.check(1.234)).toThrow(v_error_1.VerificationError);
|
|
34
|
-
expect(validator.check(1.23)).toBe(1.23);
|
|
35
|
-
});
|
|
36
|
-
it('should throw a validation error for minDecimalPlaces', () => {
|
|
37
|
-
const validator = new index_1.Verifiers.VNumber({ minDecimalPlaces: 2 });
|
|
38
|
-
expect(() => validator.check(1.2)).toThrow(v_error_1.VerificationError);
|
|
39
|
-
expect(validator.check(1.23)).toBe(1.23);
|
|
40
|
-
});
|
|
41
|
-
it('should throw a validation error for invalid type', () => {
|
|
42
|
-
const validator = new index_1.Verifiers.VNumber();
|
|
43
|
-
expect(() => validator.check('string')).toThrow(v_error_1.VerificationError);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
describe('VNumberNotNull', () => {
|
|
47
|
-
it('should validate a non-null number correctly', () => {
|
|
48
|
-
const validator = new index_1.Verifiers.VNumberNotNull();
|
|
49
|
-
expect(validator.check(123)).toBe(123);
|
|
50
|
-
});
|
|
51
|
-
it('should throw a validation error for null or undefined', () => {
|
|
52
|
-
const validator = new index_1.Verifiers.VNumberNotNull();
|
|
53
|
-
expect(() => validator.check(null)).toThrow(v_error_1.VerificationError);
|
|
54
|
-
expect(() => validator.check(undefined)).toThrow(v_error_1.VerificationError);
|
|
55
|
-
});
|
|
56
|
-
it('should throw a validation error for min', () => {
|
|
57
|
-
const validator = new index_1.Verifiers.VNumberNotNull({ min: 10 });
|
|
58
|
-
expect(() => validator.check(5)).toThrow(v_error_1.VerificationError);
|
|
59
|
-
expect(validator.check(10)).toBe(10);
|
|
60
|
-
});
|
|
61
|
-
it('should throw a validation error for max', () => {
|
|
62
|
-
const validator = new index_1.Verifiers.VNumberNotNull({ max: 10 });
|
|
63
|
-
expect(() => validator.check(15)).toThrow(v_error_1.VerificationError);
|
|
64
|
-
expect(validator.check(5)).toBe(5);
|
|
65
|
-
});
|
|
66
|
-
it('should throw a validation error for in', () => {
|
|
67
|
-
const validator = new index_1.Verifiers.VNumberNotNull({ in: [1, 2, 3] });
|
|
68
|
-
expect(() => validator.check(4)).toThrow(v_error_1.VerificationError);
|
|
69
|
-
expect(validator.check(2)).toBe(2);
|
|
70
|
-
});
|
|
71
|
-
it('should throw a validation error for notIn', () => {
|
|
72
|
-
const validator = new index_1.Verifiers.VNumberNotNull({ notIn: [1, 2, 3] });
|
|
73
|
-
expect(() => validator.check(2)).toThrow(v_error_1.VerificationError);
|
|
74
|
-
expect(validator.check(4)).toBe(4);
|
|
75
|
-
});
|
|
76
|
-
it('should throw a validation error for maxDecimalPlaces', () => {
|
|
77
|
-
const validator = new index_1.Verifiers.VNumberNotNull({ maxDecimalPlaces: 2 });
|
|
78
|
-
expect(() => validator.check(1.234)).toThrow(v_error_1.VerificationError);
|
|
79
|
-
expect(validator.check(1.23)).toBe(1.23);
|
|
80
|
-
});
|
|
81
|
-
it('should throw a validation error for minDecimalPlaces', () => {
|
|
82
|
-
const validator = new index_1.Verifiers.VNumberNotNull({ minDecimalPlaces: 2 });
|
|
83
|
-
expect(() => validator.check(1.2)).toThrow(v_error_1.VerificationError);
|
|
84
|
-
expect(validator.check(1.23)).toBe(1.23);
|
|
85
|
-
});
|
|
86
|
-
it('should throw a validation error for invalid type', () => {
|
|
87
|
-
const validator = new index_1.Verifiers.VNumberNotNull();
|
|
88
|
-
expect(() => validator.check('string')).toThrow(v_error_1.VerificationError);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
//# sourceMappingURL=v_number.test.js.map
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("../../../index");
|
|
4
|
-
const v_error_1 = require("../../error/v_error");
|
|
5
|
-
describe('VObject', () => {
|
|
6
|
-
const properties = {
|
|
7
|
-
name: new index_1.Verifiers.VString({ minLength: 3 }),
|
|
8
|
-
age: new index_1.Verifiers.VNumber({ min: 18, max: 99 })
|
|
9
|
-
};
|
|
10
|
-
it('should validate an object correctly', () => {
|
|
11
|
-
const validator = new index_1.Verifiers.VObject({ properties });
|
|
12
|
-
expect(validator.check({ name: 'John', age: 25 })).toEqual({ name: 'John', age: 25 });
|
|
13
|
-
expect(validator.check(null)).toBeNull();
|
|
14
|
-
});
|
|
15
|
-
it('should throw a validation error for invalid properties', () => {
|
|
16
|
-
const validator = new index_1.Verifiers.VObject({ properties, strictMode: true });
|
|
17
|
-
expect(() => validator.check({ name: 'John', age: 25, extra: 'invalid' })).toThrow(v_error_1.VerificationError);
|
|
18
|
-
});
|
|
19
|
-
it('should throw a validation error for invalid property values', () => {
|
|
20
|
-
const validator = new index_1.Verifiers.VObject({ properties });
|
|
21
|
-
expect(() => validator.check({ name: 'Jo', age: 25 })).toThrow(v_error_1.VerificationError);
|
|
22
|
-
expect(() => validator.check({ name: 'John', age: 17 })).toThrow(v_error_1.VerificationError);
|
|
23
|
-
});
|
|
24
|
-
it('should validate with ignoreCase for property names', () => {
|
|
25
|
-
const validator = new index_1.Verifiers.VObject({ properties, ignoreCase: true });
|
|
26
|
-
expect(validator.check({ NAME: 'John', AGE: 25 })).toEqual({ name: 'John', age: 25 });
|
|
27
|
-
});
|
|
28
|
-
it('should throw a validation error for invalidPropertyMessage', () => {
|
|
29
|
-
const validator = new index_1.Verifiers.VObject({
|
|
30
|
-
properties,
|
|
31
|
-
strictMode: true,
|
|
32
|
-
invalidPropertyMessage: { val: undefined, message: () => "invalid property" }
|
|
33
|
-
});
|
|
34
|
-
expect(() => validator.check({ name: 'John', age: 25, extra: 'invalid' })).toThrow(v_error_1.VerificationError);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
describe('VObjectNotNull', () => {
|
|
38
|
-
const properties = {
|
|
39
|
-
name: new index_1.Verifiers.VStringNotNull({ minLength: 3 }),
|
|
40
|
-
age: new index_1.Verifiers.VNumberNotNull({ min: 18, max: 99 })
|
|
41
|
-
};
|
|
42
|
-
it('should validate a non-null object correctly', () => {
|
|
43
|
-
const validator = new index_1.Verifiers.VObjectNotNull({ properties });
|
|
44
|
-
expect(validator.check({ name: 'Jane', age: 30 })).toEqual({ name: 'Jane', age: 30 });
|
|
45
|
-
});
|
|
46
|
-
it('should throw a validation error for null or undefined', () => {
|
|
47
|
-
const validator = new index_1.Verifiers.VObjectNotNull({ properties });
|
|
48
|
-
expect(() => validator.check(null)).toThrow(v_error_1.VerificationError);
|
|
49
|
-
expect(() => validator.check(undefined)).toThrow(v_error_1.VerificationError);
|
|
50
|
-
});
|
|
51
|
-
it('should throw a validation error for invalid properties', () => {
|
|
52
|
-
const validator = new index_1.Verifiers.VObjectNotNull({ properties, strictMode: true });
|
|
53
|
-
expect(() => validator.check({ name: 'Jane', age: 30, extra: 'invalid' })).toThrow(v_error_1.VerificationError);
|
|
54
|
-
});
|
|
55
|
-
it('should throw a validation error for invalid property values', () => {
|
|
56
|
-
const validator = new index_1.Verifiers.VObjectNotNull({ properties });
|
|
57
|
-
expect(() => validator.check({ name: 'Ja', age: 30 })).toThrow(v_error_1.VerificationError);
|
|
58
|
-
expect(() => validator.check({ name: 'Jane', age: 17 })).toThrow(v_error_1.VerificationError);
|
|
59
|
-
});
|
|
60
|
-
it('should validate with ignoreCase for property names', () => {
|
|
61
|
-
const validator = new index_1.Verifiers.VObjectNotNull({ properties, ignoreCase: true });
|
|
62
|
-
expect(validator.check({ NAME: 'Jane', AGE: 30 })).toEqual({ name: 'Jane', age: 30 });
|
|
63
|
-
});
|
|
64
|
-
it('should throw a validation error for invalidPropertyMessage', () => {
|
|
65
|
-
const validator = new index_1.Verifiers.VObjectNotNull({
|
|
66
|
-
properties,
|
|
67
|
-
strictMode: true,
|
|
68
|
-
invalidPropertyMessage: { val: undefined, message: () => "invalid property" }
|
|
69
|
-
});
|
|
70
|
-
expect(() => validator.check({ name: 'Jane', age: 30, extra: 'invalid' })).toThrow(v_error_1.VerificationError);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
//# sourceMappingURL=v_object.test.js.map
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("../../../index");
|
|
4
|
-
const v_error_1 = require("../../error/v_error");
|
|
5
|
-
describe('VString', () => {
|
|
6
|
-
it('should validate a string correctly', () => {
|
|
7
|
-
const validator = new index_1.Verifiers.VString();
|
|
8
|
-
expect(validator.check('valid string')).toBe('valid string');
|
|
9
|
-
expect(validator.check(null)).toBeNull();
|
|
10
|
-
});
|
|
11
|
-
it('should throw a validation error for minLength', () => {
|
|
12
|
-
const validator = new index_1.Verifiers.VString({ minLength: 5 });
|
|
13
|
-
expect(() => validator.check('abc')).toThrow(v_error_1.VerificationError);
|
|
14
|
-
expect(validator.check('abcde')).toBe('abcde');
|
|
15
|
-
});
|
|
16
|
-
it('should throw a validation error for maxLength', () => {
|
|
17
|
-
const validator = new index_1.Verifiers.VString({ maxLength: 5 });
|
|
18
|
-
expect(() => validator.check('abcdef')).toThrow(v_error_1.VerificationError);
|
|
19
|
-
expect(validator.check('abc')).toBe('abc');
|
|
20
|
-
});
|
|
21
|
-
it('should throw a validation error for regex', () => {
|
|
22
|
-
const validator = new index_1.Verifiers.VString({ regex: /^[a-z]+$/ });
|
|
23
|
-
expect(() => validator.check('abc123')).toThrow(v_error_1.VerificationError);
|
|
24
|
-
expect(validator.check('abcdef')).toBe('abcdef');
|
|
25
|
-
});
|
|
26
|
-
it('should throw a validation error for notRegex', () => {
|
|
27
|
-
const validator = new index_1.Verifiers.VString({ notRegex: /^[0-9]+$/ });
|
|
28
|
-
expect(() => validator.check('123')).toThrow(v_error_1.VerificationError);
|
|
29
|
-
expect(validator.check('abc')).toBe('abc');
|
|
30
|
-
});
|
|
31
|
-
it('should throw a validation error for in', () => {
|
|
32
|
-
const validator = new index_1.Verifiers.VString({ in: ['apple', 'banana', 'cherry'] });
|
|
33
|
-
expect(() => validator.check('orange')).toThrow(v_error_1.VerificationError);
|
|
34
|
-
expect(validator.check('apple')).toBe('apple');
|
|
35
|
-
});
|
|
36
|
-
it('should throw a validation error for notIn', () => {
|
|
37
|
-
const validator = new index_1.Verifiers.VString({ notIn: ['apple', 'banana', 'cherry'] });
|
|
38
|
-
expect(() => validator.check('apple')).toThrow(v_error_1.VerificationError);
|
|
39
|
-
expect(validator.check('orange')).toBe('orange');
|
|
40
|
-
});
|
|
41
|
-
it('should validate string in strictMode', () => {
|
|
42
|
-
const validator = new index_1.Verifiers.VString({ strictMode: true });
|
|
43
|
-
expect(() => validator.check(123)).toThrow(v_error_1.VerificationError);
|
|
44
|
-
expect(validator.check('valid string')).toBe('valid string');
|
|
45
|
-
});
|
|
46
|
-
it('should validate string with ignoreCase in in condition', () => {
|
|
47
|
-
const validator = new index_1.Verifiers.VString({ in: ['Apple', 'Banana', 'Cherry'], ignoreCase: true });
|
|
48
|
-
expect(validator.check('apple')).toBe('apple');
|
|
49
|
-
expect(() => validator.check('orange')).toThrow(v_error_1.VerificationError);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe('VStringNotNull', () => {
|
|
53
|
-
it('should validate a non-null string correctly', () => {
|
|
54
|
-
const validator = new index_1.Verifiers.VStringNotNull();
|
|
55
|
-
expect(validator.check('valid string')).toBe('valid string');
|
|
56
|
-
});
|
|
57
|
-
it('should throw a validation error for null or undefined', () => {
|
|
58
|
-
const validator = new index_1.Verifiers.VStringNotNull();
|
|
59
|
-
expect(() => validator.check(null)).toThrow(v_error_1.VerificationError);
|
|
60
|
-
expect(() => validator.check(undefined)).toThrow(v_error_1.VerificationError);
|
|
61
|
-
});
|
|
62
|
-
it('should throw a validation error for minLength', () => {
|
|
63
|
-
const validator = new index_1.Verifiers.VStringNotNull({ minLength: 5 });
|
|
64
|
-
expect(() => validator.check('abc')).toThrow(v_error_1.VerificationError);
|
|
65
|
-
expect(validator.check('abcde')).toBe('abcde');
|
|
66
|
-
});
|
|
67
|
-
it('should throw a validation error for maxLength', () => {
|
|
68
|
-
const validator = new index_1.Verifiers.VStringNotNull({ maxLength: 5 });
|
|
69
|
-
expect(() => validator.check('abcdef')).toThrow(v_error_1.VerificationError);
|
|
70
|
-
expect(validator.check('abc')).toBe('abc');
|
|
71
|
-
});
|
|
72
|
-
it('should throw a validation error for regex', () => {
|
|
73
|
-
const validator = new index_1.Verifiers.VStringNotNull({ regex: /^[a-z]+$/ });
|
|
74
|
-
expect(() => validator.check('abc123')).toThrow(v_error_1.VerificationError);
|
|
75
|
-
expect(validator.check('abcdef')).toBe('abcdef');
|
|
76
|
-
});
|
|
77
|
-
it('should throw a validation error for notRegex', () => {
|
|
78
|
-
const validator = new index_1.Verifiers.VStringNotNull({ notRegex: /^[0-9]+$/ });
|
|
79
|
-
expect(() => validator.check('123')).toThrow(v_error_1.VerificationError);
|
|
80
|
-
expect(validator.check('abc')).toBe('abc');
|
|
81
|
-
});
|
|
82
|
-
it('should throw a validation error for in', () => {
|
|
83
|
-
const validator = new index_1.Verifiers.VStringNotNull({ in: ['apple', 'banana', 'cherry'] });
|
|
84
|
-
expect(() => validator.check('orange')).toThrow(v_error_1.VerificationError);
|
|
85
|
-
expect(validator.check('apple')).toBe('apple');
|
|
86
|
-
});
|
|
87
|
-
it('should throw a validation error for notIn', () => {
|
|
88
|
-
const validator = new index_1.Verifiers.VStringNotNull({ notIn: ['apple', 'banana', 'cherry'] });
|
|
89
|
-
expect(() => validator.check('apple')).toThrow(v_error_1.VerificationError);
|
|
90
|
-
expect(validator.check('orange')).toBe('orange');
|
|
91
|
-
});
|
|
92
|
-
it('should validate string in strictMode', () => {
|
|
93
|
-
const validator = new index_1.Verifiers.VStringNotNull({ strictMode: true });
|
|
94
|
-
expect(() => validator.check(123)).toThrow(v_error_1.VerificationError);
|
|
95
|
-
expect(validator.check('valid string')).toBe('valid string');
|
|
96
|
-
});
|
|
97
|
-
it('should validate string with ignoreCase in in condition', () => {
|
|
98
|
-
const validator = new index_1.Verifiers.VStringNotNull({ in: ['Apple', 'Banana', 'Cherry'], ignoreCase: true });
|
|
99
|
-
expect(validator.check('apple')).toBe('apple');
|
|
100
|
-
expect(() => validator.check('orange')).toThrow(v_error_1.VerificationError);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
//# sourceMappingURL=v_string.test.js.map
|