structure-verifier 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/verifiers/boolean/v_boolean.js +25 -16
- package/dist/src/verifiers/boolean/v_boolean.js.map +1 -1
- package/dist/src/verifiers/date/v_date.js +47 -27
- package/dist/src/verifiers/date/v_date.js.map +1 -1
- package/dist/src/verifiers/number/v_number.js +51 -33
- package/dist/src/verifiers/number/v_number.js.map +1 -1
- package/dist/src/verifiers/string/v_string.js +68 -42
- package/dist/src/verifiers/string/v_string.js.map +1 -1
- package/dist/src/verifiers/uuid/v_uuid.js +33 -23
- package/dist/src/verifiers/uuid/v_uuid.js.map +1 -1
- package/dist/src/verifiers/verifier.d.ts +1 -1
- package/dist/src/verifiers/verifier.js +12 -7
- package/dist/src/verifiers/verifier.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,45 +7,54 @@ const verifier_1 = require("../verifier");
|
|
|
7
7
|
function vBoolean(data, badTypeMessage, conds) {
|
|
8
8
|
// Strict mode: only accept boolean type
|
|
9
9
|
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.strictMode) === true) {
|
|
10
|
-
if (typeof data !==
|
|
11
|
-
throw new v_error_1.VerificationError([
|
|
10
|
+
if (typeof data !== "boolean") {
|
|
11
|
+
throw new v_error_1.VerificationError([
|
|
12
|
+
{
|
|
12
13
|
key: "",
|
|
13
|
-
message: (0, message_1.getMessage)((conds === null || conds === void 0 ? void 0 : conds.badTypeMessage) != undefined
|
|
14
|
-
|
|
14
|
+
message: (0, message_1.getMessage)((conds === null || conds === void 0 ? void 0 : conds.badTypeMessage) != undefined
|
|
15
|
+
? conds === null || conds === void 0 ? void 0 : conds.badTypeMessage
|
|
16
|
+
: undefined, undefined, badTypeMessage),
|
|
17
|
+
},
|
|
18
|
+
]);
|
|
15
19
|
}
|
|
16
20
|
return data;
|
|
17
21
|
}
|
|
18
22
|
// Non-strict mode: accept boolean, number (1/0), or string representations
|
|
19
|
-
const acceptedValues = [true, false, 1, 0,
|
|
20
|
-
const acceptedStrings = [
|
|
23
|
+
const acceptedValues = [true, false, 1, 0, "1", "0"];
|
|
24
|
+
const acceptedStrings = ["true", "false"];
|
|
21
25
|
if (acceptedValues.includes(data)) {
|
|
22
|
-
return data === true || data === 1 || data ===
|
|
26
|
+
return data === true || data === 1 || data === "1";
|
|
23
27
|
}
|
|
24
|
-
if (typeof data ===
|
|
25
|
-
|
|
28
|
+
if (typeof data === "string" &&
|
|
29
|
+
acceptedStrings.includes(data.toLowerCase())) {
|
|
30
|
+
return data.toLowerCase() === "true";
|
|
26
31
|
}
|
|
27
|
-
throw new v_error_1.VerificationError([
|
|
32
|
+
throw new v_error_1.VerificationError([
|
|
33
|
+
{
|
|
28
34
|
key: "",
|
|
29
|
-
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)
|
|
30
|
-
}
|
|
35
|
+
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),
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
31
38
|
}
|
|
32
39
|
class VBooleanNotNull extends verifier_1.Verifier {
|
|
33
40
|
check(data) {
|
|
34
|
-
|
|
41
|
+
var _a;
|
|
42
|
+
return vBoolean(this.isRequired(data, true, (_a = this.cond) === null || _a === void 0 ? void 0 : _a.defaultValue), this.badTypeMessage, this.cond);
|
|
35
43
|
}
|
|
36
44
|
constructor(cond) {
|
|
37
45
|
super(cond);
|
|
38
46
|
this.cond = cond;
|
|
39
47
|
this.badTypeMessage = {
|
|
40
48
|
es: () => `debe ser un booleano`,
|
|
41
|
-
en: () => `must be a boolean
|
|
49
|
+
en: () => `must be a boolean`,
|
|
42
50
|
};
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
53
|
exports.VBooleanNotNull = VBooleanNotNull;
|
|
46
54
|
class VBoolean extends verifier_1.Verifier {
|
|
47
55
|
check(data) {
|
|
48
|
-
|
|
56
|
+
var _a;
|
|
57
|
+
let val = this.isRequired(data, undefined, (_a = this.cond) === null || _a === void 0 ? void 0 : _a.defaultValue);
|
|
49
58
|
if (val === null || val === undefined) {
|
|
50
59
|
return null;
|
|
51
60
|
}
|
|
@@ -57,7 +66,7 @@ class VBoolean extends verifier_1.Verifier {
|
|
|
57
66
|
this.cond = cond;
|
|
58
67
|
this.badTypeMessage = {
|
|
59
68
|
es: () => `debe ser un booleano`,
|
|
60
|
-
en: () => `must be a boolean
|
|
69
|
+
en: () => `must be a boolean`,
|
|
61
70
|
};
|
|
62
71
|
}
|
|
63
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v_boolean.js","sourceRoot":"","sources":["../../../../src/src/verifiers/boolean/v_boolean.ts"],"names":[],"mappings":";;;AAAA,iDAAwD;
|
|
1
|
+
{"version":3,"file":"v_boolean.js","sourceRoot":"","sources":["../../../../src/src/verifiers/boolean/v_boolean.ts"],"names":[],"mappings":";;;AAAA,iDAAwD;AAOxD,qDAIiC;AACjC,0CAAuC;AAOvC,SAAS,QAAQ,CACf,IAAS,EACT,cAAsC,EACtC,KAA0B;IAE1B,wCAAwC;IACxC,IAAI,IAAA,kBAAQ,EAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC;QACzC,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,IAAI,2BAAiB,CAAC;gBAC1B;oBACE,GAAG,EAAE,EAAE;oBACP,OAAO,EAAE,IAAA,oBAAU,EACjB,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,KAAI,SAAS;wBAChC,CAAC,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc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AC,CAAC;QADQ,SAAI,GAAJ,IAAI,CAAqB;QAE7C,IAAI,CAAC,cAAc,GAAG;YACpB,EAAE,EAAE,GAAG,EAAE,CAAC,sBAAsB;YAChC,EAAE,EAAE,GAAG,EAAE,CAAC,mBAAmB;SAC9B,CAAC;IACJ,CAAC;CACF;AAfD,0CAeC;AAED,MAAa,QAAS,SAAQ,mBAAwB;IACpD,KAAK,CAAC,IAAS;;QACb,IAAI,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,MAAA,IAAI,CAAC,IAAI,0CAAE,YAAY,CAAC,CAAC;QACpE,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IACD,YAAsB,IAAyB;QAC7C,KAAK,CAAC,IAAI,CAAC,CAAC;QADQ,SAAI,GAAJ,IAAI,CAAqB;QAE7C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,cAAc,GAAG;YACpB,EAAE,EAAE,GAAG,EAAE,CAAC,sBAAsB;YAChC,EAAE,EAAE,GAAG,EAAE,CAAC,mBAAmB;SAC9B,CAAC;IACJ,CAAC;CACF;AAhBD,4BAgBC"}
|
|
@@ -8,24 +8,24 @@ const datetime_1 = require("../../utils/datetime");
|
|
|
8
8
|
const dMessages = {
|
|
9
9
|
format: {
|
|
10
10
|
es: (values) => `debe tener el formato ${values.format}`,
|
|
11
|
-
en: (values) => `must have the format ${values.format}
|
|
11
|
+
en: (values) => `must have the format ${values.format}`,
|
|
12
12
|
},
|
|
13
13
|
timeZone: {
|
|
14
14
|
es: (values) => `debe tener la zona horaria ${values.timeZone}`,
|
|
15
|
-
en: (values) => `must have the time zone ${values.timeZone}
|
|
15
|
+
en: (values) => `must have the time zone ${values.timeZone}`,
|
|
16
16
|
},
|
|
17
17
|
maxDate: {
|
|
18
18
|
es: (values) => `debe ser menor o igual a ${values.maxDate.format()}`,
|
|
19
|
-
en: (values) => `must be less or equal to ${values.maxDate.format()}
|
|
19
|
+
en: (values) => `must be less or equal to ${values.maxDate.format()}`,
|
|
20
20
|
},
|
|
21
21
|
minDate: {
|
|
22
22
|
es: (values) => `debe ser mayor o igual a ${values.minDate.format()}`,
|
|
23
|
-
en: (values) => `must be greater or equal to ${values.minDate.format()}
|
|
23
|
+
en: (values) => `must be greater or equal to ${values.minDate.format()}`,
|
|
24
24
|
},
|
|
25
25
|
badTypeMessage: {
|
|
26
26
|
es: () => `debe ser una fecha`,
|
|
27
|
-
en: () => `must be a date
|
|
28
|
-
}
|
|
27
|
+
en: () => `must be a date`,
|
|
28
|
+
},
|
|
29
29
|
};
|
|
30
30
|
function haveTimezone(input) {
|
|
31
31
|
const regexDesplazamiento = /(?:UTC|GMT|[+-]\d{2}:?\d{2})$/;
|
|
@@ -37,55 +37,74 @@ function formatWithTimeZone(format) {
|
|
|
37
37
|
}
|
|
38
38
|
function vDate(data, badTypeMessage, conds) {
|
|
39
39
|
let timeZone = (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.timeZone) || "UTC";
|
|
40
|
-
if (data ===
|
|
41
|
-
|
|
40
|
+
if (data === "" ||
|
|
41
|
+
!(typeof data === "number" ||
|
|
42
|
+
typeof data === "string" ||
|
|
43
|
+
data instanceof Date ||
|
|
44
|
+
datetime_1.datetime.isDayjs(data))) {
|
|
45
|
+
throw new v_error_1.VerificationError([
|
|
46
|
+
{
|
|
42
47
|
key: "",
|
|
43
|
-
message: (0, message_1.getMessage)((conds === null || conds === void 0 ? void 0 : conds.badTypeMessage) != undefined
|
|
44
|
-
|
|
48
|
+
message: (0, message_1.getMessage)((conds === null || conds === void 0 ? void 0 : conds.badTypeMessage) != undefined
|
|
49
|
+
? conds === null || conds === void 0 ? void 0 : conds.badTypeMessage
|
|
50
|
+
: undefined, undefined, badTypeMessage),
|
|
51
|
+
},
|
|
52
|
+
]);
|
|
45
53
|
}
|
|
46
54
|
let date = (0, datetime_1.datetime)();
|
|
47
55
|
if (conds === null || conds === void 0 ? void 0 : conds.format) {
|
|
48
56
|
let format = (0, message_1.getValue)(conds.format);
|
|
49
57
|
date = (0, datetime_1.datetime)(data, format, true);
|
|
50
58
|
if (!date.isValid()) {
|
|
51
|
-
throw new v_error_1.VerificationError([
|
|
59
|
+
throw new v_error_1.VerificationError([
|
|
60
|
+
{
|
|
52
61
|
key: "",
|
|
53
|
-
message: (0, message_1.getMessage)(conds.format, { format: format }, dMessages.format)
|
|
54
|
-
}
|
|
62
|
+
message: (0, message_1.getMessage)(conds.format, { format: format }, dMessages.format),
|
|
63
|
+
},
|
|
64
|
+
]);
|
|
55
65
|
}
|
|
56
66
|
if (!formatWithTimeZone(format)) {
|
|
57
|
-
date = datetime_1.datetime.tz(date.format(
|
|
67
|
+
date = datetime_1.datetime.tz(date.format("YYYY-MM-DD HH:mm:ss"), timeZone);
|
|
58
68
|
}
|
|
59
69
|
}
|
|
60
70
|
else {
|
|
61
71
|
date = (0, datetime_1.datetime)(data);
|
|
62
|
-
if (typeof data ===
|
|
63
|
-
date = datetime_1.datetime.tz(date.format(
|
|
72
|
+
if (typeof data === "string" && !haveTimezone(data)) {
|
|
73
|
+
date = datetime_1.datetime.tz(date.format("YYYY-MM-DD HH:mm:ss"), timeZone);
|
|
64
74
|
}
|
|
65
75
|
}
|
|
66
76
|
if (!date.isValid()) {
|
|
67
|
-
throw new v_error_1.VerificationError([
|
|
77
|
+
throw new v_error_1.VerificationError([
|
|
78
|
+
{
|
|
68
79
|
key: "",
|
|
69
|
-
message: (0, message_1.getMessage)((conds === null || conds === void 0 ? void 0 : conds.badTypeMessage) != undefined
|
|
70
|
-
|
|
80
|
+
message: (0, message_1.getMessage)((conds === null || conds === void 0 ? void 0 : conds.badTypeMessage) != undefined
|
|
81
|
+
? conds === null || conds === void 0 ? void 0 : conds.badTypeMessage
|
|
82
|
+
: undefined, undefined, badTypeMessage),
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
71
85
|
}
|
|
72
86
|
if ((conds === null || conds === void 0 ? void 0 : conds.maxDate) && date.isAfter((0, message_1.getValue)(conds.maxDate))) {
|
|
73
|
-
throw new v_error_1.VerificationError([
|
|
87
|
+
throw new v_error_1.VerificationError([
|
|
88
|
+
{
|
|
74
89
|
key: "",
|
|
75
|
-
message: (0, message_1.getMessage)(conds.maxDate, { maxDate: (0, message_1.getValue)(conds.maxDate) }, dMessages.maxDate)
|
|
76
|
-
}
|
|
90
|
+
message: (0, message_1.getMessage)(conds.maxDate, { maxDate: (0, message_1.getValue)(conds.maxDate) }, dMessages.maxDate),
|
|
91
|
+
},
|
|
92
|
+
]);
|
|
77
93
|
}
|
|
78
94
|
if ((conds === null || conds === void 0 ? void 0 : conds.minDate) && date.isBefore((0, message_1.getValue)(conds.minDate))) {
|
|
79
|
-
throw new v_error_1.VerificationError([
|
|
95
|
+
throw new v_error_1.VerificationError([
|
|
96
|
+
{
|
|
80
97
|
key: "",
|
|
81
|
-
message: (0, message_1.getMessage)(conds.minDate, { minDate: (0, message_1.getValue)(conds.minDate) }, dMessages.minDate)
|
|
82
|
-
}
|
|
98
|
+
message: (0, message_1.getMessage)(conds.minDate, { minDate: (0, message_1.getValue)(conds.minDate) }, dMessages.minDate),
|
|
99
|
+
},
|
|
100
|
+
]);
|
|
83
101
|
}
|
|
84
102
|
return date;
|
|
85
103
|
}
|
|
86
104
|
class VDateNotNull extends verifier_1.Verifier {
|
|
87
105
|
check(data) {
|
|
88
|
-
|
|
106
|
+
var _a;
|
|
107
|
+
return vDate(this.isRequired(data, true, (_a = this.cond) === null || _a === void 0 ? void 0 : _a.defaultValue), this.badTypeMessage, this.cond);
|
|
89
108
|
}
|
|
90
109
|
constructor(cond) {
|
|
91
110
|
super(cond);
|
|
@@ -96,7 +115,8 @@ class VDateNotNull extends verifier_1.Verifier {
|
|
|
96
115
|
exports.VDateNotNull = VDateNotNull;
|
|
97
116
|
class VDate extends verifier_1.Verifier {
|
|
98
117
|
check(data) {
|
|
99
|
-
|
|
118
|
+
var _a;
|
|
119
|
+
let val = this.isRequired(data, undefined, (_a = this.cond) === null || _a === void 0 ? void 0 : _a.defaultValue);
|
|
100
120
|
if (val === null || val === undefined) {
|
|
101
121
|
return null;
|
|
102
122
|
}
|
|
@@ -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":";;;AAOA,qDAIiC;AACjC,iDAAwD;AACxD,0CAAuC;AACvC,mDAAgD;AAuBhD,MAAM,SAAS,GAAyB;IACtC,MAAM,EAAE;QACN,EAAE,EAAE,CAAC,MAA0B,EAAE,EAAE,CACjC,yBAAyB,MAAM,CAAC,MAAM,EAAE;QAC1C,EAAE,EAAE,CAAC,MAA0B,EAAE,EAAE,CAAC,wBAAwB,MAAM,CAAC,MAAM,EAAE;KAC5E;IACD,QAAQ,EAAE;QACR,EAAE,EAAE,CAAC,MAA4B,EAAE,EAAE,CACnC,8BAA8B,MAAM,CAAC,QAAQ,EAAE;QACjD,EAAE,EAAE,CAAC,MAA4B,EAAE,EAAE,CACnC,2BAA2B,MAAM,CAAC,QAAQ,EAAE;KAC/C;IACD,OAAO,EAAE;QACP,EAAE,EAAE,CAAC,MAAmC,EAAE,EAAE,CAC1C,4BAA4B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;QACvD,EAAE,EAAE,CAAC,MAAmC,EAAE,EAAE,CAC1C,4BAA4B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;KACxD;IACD,OAAO,EAAE;QACP,EAAE,EAAE,CAAC,MAAmC,EAAE,EAAE,CAC1C,4BAA4B,MAAM,CA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AI,CAAC,IAAI,CACV,CAAC;IACJ,CAAC;IACD,YAAsB,IAAsB;QAC1C,KAAK,CAAC,IAAI,CAAC,CAAC;QADQ,SAAI,GAAJ,IAAI,CAAkB;QAE1C,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC,cAAc,CAAC;IACjD,CAAC;CACF;AAZD,oCAYC;AAED,MAAa,KAAM,SAAQ,mBAA+B;IACxD,KAAK,CAAC,IAAS;;QACb,IAAI,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,MAAA,IAAI,CAAC,IAAI,0CAAE,YAAY,CAAC,CAAC;QACpE,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;IACD,YAAsB,IAAsB;QAC1C,KAAK,CAAC,IAAI,CAAC,CAAC;QADQ,SAAI,GAAJ,IAAI,CAAkB;QAE1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC,cAAc,CAAC;IACjD,CAAC;CACF;AAbD,sBAaC"}
|
|
@@ -7,94 +7,111 @@ const verifier_1 = require("../verifier");
|
|
|
7
7
|
const dMessages = {
|
|
8
8
|
min: {
|
|
9
9
|
es: (values) => `debe ser mayor o igual a ${values.min}`,
|
|
10
|
-
en: (values) => `must be greater or equal to ${values.min}
|
|
10
|
+
en: (values) => `must be greater or equal to ${values.min}`,
|
|
11
11
|
},
|
|
12
12
|
max: {
|
|
13
13
|
es: (values) => `debe ser menor o igual a ${values.max}`,
|
|
14
|
-
en: (values) => `must be less or equal to ${values.max}
|
|
14
|
+
en: (values) => `must be less or equal to ${values.max}`,
|
|
15
15
|
},
|
|
16
16
|
in: {
|
|
17
17
|
es: (values) => `debe ser uno de los siguientes valores ${values.in.join(", ")}`,
|
|
18
|
-
en: (values) => `must be one of the following values ${values.in.join(", ")}
|
|
18
|
+
en: (values) => `must be one of the following values ${values.in.join(", ")}`,
|
|
19
19
|
},
|
|
20
20
|
notIn: {
|
|
21
21
|
es: (values) => `no debe ser uno de los siguientes valores ${values.notIn.join(", ")}`,
|
|
22
|
-
en: (values) => `must not be one of the following values ${values.notIn.join(", ")}
|
|
22
|
+
en: (values) => `must not be one of the following values ${values.notIn.join(", ")}`,
|
|
23
23
|
},
|
|
24
24
|
maxDecimalPlaces: {
|
|
25
25
|
es: (values) => `debe tener como máximo ${values.maxDecimalPlaces} decimales`,
|
|
26
|
-
en: (values) => `must have at most ${values.maxDecimalPlaces} decimal places
|
|
26
|
+
en: (values) => `must have at most ${values.maxDecimalPlaces} decimal places`,
|
|
27
27
|
},
|
|
28
28
|
minDecimalPlaces: {
|
|
29
29
|
es: (values) => `debe tener como mínimo ${values.minDecimalPlaces} decimales`,
|
|
30
|
-
en: (values) => `must have at least ${values.minDecimalPlaces} decimal places
|
|
30
|
+
en: (values) => `must have at least ${values.minDecimalPlaces} decimal places`,
|
|
31
31
|
},
|
|
32
32
|
badTypeMessage: {
|
|
33
33
|
es: () => `debe ser un número`,
|
|
34
|
-
en: () => `must be a number
|
|
35
|
-
}
|
|
34
|
+
en: () => `must be a number`,
|
|
35
|
+
},
|
|
36
36
|
};
|
|
37
37
|
function vNumber(data, badTypeMessage, conds) {
|
|
38
|
-
if (data ===
|
|
39
|
-
throw new v_error_1.VerificationError([
|
|
38
|
+
if (data === "" || isNaN(data)) {
|
|
39
|
+
throw new v_error_1.VerificationError([
|
|
40
|
+
{
|
|
40
41
|
key: "",
|
|
41
|
-
message: (0, message_1.getMessage)((conds === null || conds === void 0 ? void 0 : conds.badTypeMessage) != undefined
|
|
42
|
-
|
|
42
|
+
message: (0, message_1.getMessage)((conds === null || conds === void 0 ? void 0 : conds.badTypeMessage) != undefined
|
|
43
|
+
? conds === null || conds === void 0 ? void 0 : conds.badTypeMessage
|
|
44
|
+
: undefined, undefined, badTypeMessage),
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
43
47
|
}
|
|
44
48
|
if ((conds === null || conds === void 0 ? void 0 : conds.min) !== undefined) {
|
|
45
49
|
if (data < (conds === null || conds === void 0 ? void 0 : conds.min)) {
|
|
46
|
-
throw new v_error_1.VerificationError([
|
|
50
|
+
throw new v_error_1.VerificationError([
|
|
51
|
+
{
|
|
47
52
|
key: "",
|
|
48
|
-
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.min, { min: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.min) }, dMessages.min)
|
|
49
|
-
}
|
|
53
|
+
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.min, { min: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.min) }, dMessages.min),
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
if ((conds === null || conds === void 0 ? void 0 : conds.max) !== undefined) {
|
|
53
59
|
if (data > (conds === null || conds === void 0 ? void 0 : conds.max)) {
|
|
54
|
-
throw new v_error_1.VerificationError([
|
|
60
|
+
throw new v_error_1.VerificationError([
|
|
61
|
+
{
|
|
55
62
|
key: "",
|
|
56
|
-
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.max, { max: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.max) }, dMessages.max)
|
|
57
|
-
}
|
|
63
|
+
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.max, { max: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.max) }, dMessages.max),
|
|
64
|
+
},
|
|
65
|
+
]);
|
|
58
66
|
}
|
|
59
67
|
}
|
|
60
68
|
if ((conds === null || conds === void 0 ? void 0 : conds.in) !== undefined) {
|
|
61
69
|
if (!(0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.in).includes(data)) {
|
|
62
|
-
throw new v_error_1.VerificationError([
|
|
70
|
+
throw new v_error_1.VerificationError([
|
|
71
|
+
{
|
|
63
72
|
key: "",
|
|
64
|
-
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.in, { in: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.in) }, dMessages.in)
|
|
65
|
-
}
|
|
73
|
+
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.in, { in: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.in) }, dMessages.in),
|
|
74
|
+
},
|
|
75
|
+
]);
|
|
66
76
|
}
|
|
67
77
|
}
|
|
68
78
|
if ((conds === null || conds === void 0 ? void 0 : conds.notIn) !== undefined) {
|
|
69
79
|
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.notIn).includes(data)) {
|
|
70
|
-
throw new v_error_1.VerificationError([
|
|
80
|
+
throw new v_error_1.VerificationError([
|
|
81
|
+
{
|
|
71
82
|
key: "",
|
|
72
|
-
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.notIn, { notIn: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.notIn) }, dMessages.notIn)
|
|
73
|
-
}
|
|
83
|
+
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.notIn, { notIn: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.notIn) }, dMessages.notIn),
|
|
84
|
+
},
|
|
85
|
+
]);
|
|
74
86
|
}
|
|
75
87
|
}
|
|
76
|
-
const decimalPart = data.toString().split(".")[1] ||
|
|
88
|
+
const decimalPart = data.toString().split(".")[1] || "";
|
|
77
89
|
if ((conds === null || conds === void 0 ? void 0 : conds.maxDecimalPlaces) !== undefined) {
|
|
78
90
|
if (decimalPart.length > (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.maxDecimalPlaces)) {
|
|
79
|
-
throw new v_error_1.VerificationError([
|
|
91
|
+
throw new v_error_1.VerificationError([
|
|
92
|
+
{
|
|
80
93
|
key: "",
|
|
81
|
-
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.maxDecimalPlaces, { maxDecimalPlaces: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.maxDecimalPlaces) }, dMessages.maxDecimalPlaces)
|
|
82
|
-
}
|
|
94
|
+
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.maxDecimalPlaces, { maxDecimalPlaces: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.maxDecimalPlaces) }, dMessages.maxDecimalPlaces),
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
83
97
|
}
|
|
84
98
|
}
|
|
85
99
|
if ((conds === null || conds === void 0 ? void 0 : conds.minDecimalPlaces) !== undefined) {
|
|
86
100
|
if (decimalPart.length < (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.minDecimalPlaces)) {
|
|
87
|
-
throw new v_error_1.VerificationError([
|
|
101
|
+
throw new v_error_1.VerificationError([
|
|
102
|
+
{
|
|
88
103
|
key: "",
|
|
89
|
-
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.minDecimalPlaces, { minDecimalPlaces: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.minDecimalPlaces) }, dMessages.minDecimalPlaces)
|
|
90
|
-
}
|
|
104
|
+
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.minDecimalPlaces, { minDecimalPlaces: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.minDecimalPlaces) }, dMessages.minDecimalPlaces),
|
|
105
|
+
},
|
|
106
|
+
]);
|
|
91
107
|
}
|
|
92
108
|
}
|
|
93
109
|
return Number(data);
|
|
94
110
|
}
|
|
95
111
|
class VNumberNotNull extends verifier_1.Verifier {
|
|
96
112
|
check(data) {
|
|
97
|
-
|
|
113
|
+
var _a;
|
|
114
|
+
return vNumber(this.isRequired(data, true, (_a = this.cond) === null || _a === void 0 ? void 0 : _a.defaultValue), this.badTypeMessage, this.cond);
|
|
98
115
|
}
|
|
99
116
|
constructor(cond) {
|
|
100
117
|
super(cond);
|
|
@@ -105,7 +122,8 @@ class VNumberNotNull extends verifier_1.Verifier {
|
|
|
105
122
|
exports.VNumberNotNull = VNumberNotNull;
|
|
106
123
|
class VNumber extends verifier_1.Verifier {
|
|
107
124
|
check(data) {
|
|
108
|
-
|
|
125
|
+
var _a;
|
|
126
|
+
let val = this.isRequired(data, undefined, (_a = this.cond) === null || _a === void 0 ? void 0 : _a.defaultValue);
|
|
109
127
|
if (val === null || val === undefined) {
|
|
110
128
|
return null;
|
|
111
129
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v_number.js","sourceRoot":"","sources":["../../../../src/src/verifiers/number/v_number.ts"],"names":[],"mappings":";;;AAAA,iDAAwD;
|
|
1
|
+
{"version":3,"file":"v_number.js","sourceRoot":"","sources":["../../../../src/src/verifiers/number/v_number.ts"],"names":[],"mappings":";;;AAAA,iDAAwD;AAQxD,qDAIiC;AACjC,0CAAuC;AAsBvC,MAAM,SAAS,GAA2B;IACxC,GAAG,EAAE;QACH,EAAE,EAAE,CAAC,MAAuB,EAAE,EAAE,CAAC,4BAA4B,MAAM,CAAC,GAAG,EAAE;QACzE,EAAE,EAAE,CAAC,MAAuB,EAAE,EAAE,CAC9B,+BAA+B,MAAM,CAAC,GAAG,EAAE;KAC9C;IACD,GAAG,EAAE;QACH,EAAE,EAAE,CAAC,MAAuB,EAAE,EAAE,CAAC,4BAA4B,MAAM,CAAC,GAAG,EAAE;QACzE,EAAE,EAAE,CAAC,MAAuB,EAAE,EAAE,CAAC,4BAA4B,MAAM,CAAC,GAAG,EAAE;KAC1E;IACD,EAAE,EAAE;QACF,EAAE,EAAE,CAAC,MAAwB,EAAE,EAAE,CAC/B,0CAA0C,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAClE,EAAE,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IAAI,CAAoB;QAE5C,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC,cAAc,CAAC;IACjD,CAAC;CACF;AAZD,wCAYC;AAED,MAAa,OAAQ,SAAQ,mBAAuB;IAClD,KAAK,CAAC,IAAS;;QACb,IAAI,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,MAAA,IAAI,CAAC,IAAI,0CAAE,YAAY,CAAC,CAAC;QACpE,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IACD,YAAsB,IAAwB;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAC;QADQ,SAAI,GAAJ,IAAI,CAAoB;QAE5C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC,cAAc,CAAC;IACjD,CAAC;CACF;AAbD,0BAaC"}
|
|
@@ -5,102 +5,126 @@ const v_error_1 = require("../../error/v_error");
|
|
|
5
5
|
const message_1 = require("../../languages/message");
|
|
6
6
|
const verifier_1 = require("../verifier");
|
|
7
7
|
function vString(data, badTypeMessage, conds) {
|
|
8
|
-
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.strictMode) === true && typeof data !==
|
|
9
|
-
throw new v_error_1.VerificationError([
|
|
8
|
+
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.strictMode) === true && typeof data !== "string") {
|
|
9
|
+
throw new v_error_1.VerificationError([
|
|
10
|
+
{
|
|
10
11
|
key: "",
|
|
11
|
-
message: (0, message_1.getMessage)((conds === null || conds === void 0 ? void 0 : conds.badTypeMessage) != undefined
|
|
12
|
-
|
|
12
|
+
message: (0, message_1.getMessage)((conds === null || conds === void 0 ? void 0 : conds.badTypeMessage) != undefined
|
|
13
|
+
? conds === null || conds === void 0 ? void 0 : conds.badTypeMessage
|
|
14
|
+
: undefined, undefined, badTypeMessage),
|
|
15
|
+
},
|
|
16
|
+
]);
|
|
13
17
|
}
|
|
14
18
|
data = String(data);
|
|
15
19
|
if ((conds === null || conds === void 0 ? void 0 : conds.minLength) !== undefined) {
|
|
16
20
|
if (data.length < (conds === null || conds === void 0 ? void 0 : conds.minLength)) {
|
|
17
|
-
throw new v_error_1.VerificationError([
|
|
21
|
+
throw new v_error_1.VerificationError([
|
|
22
|
+
{
|
|
18
23
|
key: "",
|
|
19
24
|
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.minLength, { minLength: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.minLength) }, {
|
|
20
25
|
es: (values) => `debe tener una longitud mínima de ${values.minLength}`,
|
|
21
|
-
en: (values) => `must have a minimum length of ${values.minLength}
|
|
22
|
-
})
|
|
23
|
-
}
|
|
26
|
+
en: (values) => `must have a minimum length of ${values.minLength}`,
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
]);
|
|
24
30
|
}
|
|
25
31
|
}
|
|
26
32
|
if ((conds === null || conds === void 0 ? void 0 : conds.maxLength) !== undefined) {
|
|
27
33
|
if (data.length > (conds === null || conds === void 0 ? void 0 : conds.maxLength)) {
|
|
28
|
-
throw new v_error_1.VerificationError([
|
|
34
|
+
throw new v_error_1.VerificationError([
|
|
35
|
+
{
|
|
29
36
|
key: "",
|
|
30
37
|
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.maxLength, { maxLength: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.maxLength) }, {
|
|
31
38
|
es: (values) => `debe tener una longitud máxima de ${values.maxLength}`,
|
|
32
|
-
en: (values) => `must have a maximum length of ${values.maxLength}
|
|
33
|
-
})
|
|
34
|
-
}
|
|
39
|
+
en: (values) => `must have a maximum length of ${values.maxLength}`,
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
42
|
+
]);
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
45
|
if ((conds === null || conds === void 0 ? void 0 : conds.regex) !== undefined) {
|
|
38
46
|
if (!(0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.regex).test(data)) {
|
|
39
|
-
throw new v_error_1.VerificationError([
|
|
47
|
+
throw new v_error_1.VerificationError([
|
|
48
|
+
{
|
|
40
49
|
key: "",
|
|
41
50
|
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.regex, { regex: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.regex) }, {
|
|
42
51
|
es: (values) => `debe cumplir con el patrón ${values.regex}`,
|
|
43
|
-
en: (values) => `must match the pattern ${values.regex}
|
|
44
|
-
})
|
|
45
|
-
}
|
|
52
|
+
en: (values) => `must match the pattern ${values.regex}`,
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
46
56
|
}
|
|
47
57
|
}
|
|
48
58
|
if ((conds === null || conds === void 0 ? void 0 : conds.notRegex) !== undefined) {
|
|
49
59
|
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.notRegex).test(data)) {
|
|
50
|
-
throw new v_error_1.VerificationError([
|
|
60
|
+
throw new v_error_1.VerificationError([
|
|
61
|
+
{
|
|
51
62
|
key: "",
|
|
52
63
|
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.notRegex, { notRegex: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.notRegex) }, {
|
|
53
64
|
es: (values) => `no debe cumplir con el patrón ${values.notRegex}`,
|
|
54
|
-
en: (values) => `must not match the pattern ${values.notRegex}
|
|
55
|
-
})
|
|
56
|
-
}
|
|
65
|
+
en: (values) => `must not match the pattern ${values.notRegex}`,
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
57
69
|
}
|
|
58
70
|
}
|
|
59
71
|
if ((conds === null || conds === void 0 ? void 0 : conds.in) !== undefined) {
|
|
60
72
|
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.ignoreCase) === true) {
|
|
61
|
-
if (!(0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.in)
|
|
62
|
-
|
|
73
|
+
if (!(0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.in)
|
|
74
|
+
.map((x) => x.toLowerCase())
|
|
75
|
+
.includes(data.toLowerCase())) {
|
|
76
|
+
throw new v_error_1.VerificationError([
|
|
77
|
+
{
|
|
63
78
|
key: "",
|
|
64
79
|
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.in, { in: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.in) }, {
|
|
65
80
|
es: (values) => `debe ser uno de los siguientes valores ${values.in.join(", ")}`,
|
|
66
|
-
en: (values) => `must be one of the following values ${values.in.join(", ")}
|
|
67
|
-
})
|
|
68
|
-
}
|
|
81
|
+
en: (values) => `must be one of the following values ${values.in.join(", ")}`,
|
|
82
|
+
}),
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
69
85
|
}
|
|
70
86
|
}
|
|
71
87
|
else {
|
|
72
88
|
if (!(0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.in).includes(data)) {
|
|
73
|
-
throw new v_error_1.VerificationError([
|
|
89
|
+
throw new v_error_1.VerificationError([
|
|
90
|
+
{
|
|
74
91
|
key: "",
|
|
75
92
|
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.in, { in: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.in) }, {
|
|
76
93
|
es: (values) => `debe ser uno de los siguientes valores ${values.in.join(", ")}`,
|
|
77
|
-
en: (values) => `must be one of the following values ${values.in.join(", ")}
|
|
78
|
-
})
|
|
79
|
-
}
|
|
94
|
+
en: (values) => `must be one of the following values ${values.in.join(", ")}`,
|
|
95
|
+
}),
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
80
98
|
}
|
|
81
99
|
}
|
|
82
100
|
}
|
|
83
101
|
if ((conds === null || conds === void 0 ? void 0 : conds.notIn) !== undefined) {
|
|
84
102
|
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.ignoreCase) === true) {
|
|
85
|
-
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.notIn)
|
|
86
|
-
|
|
103
|
+
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.notIn)
|
|
104
|
+
.map((x) => x.toLowerCase())
|
|
105
|
+
.includes(data.toLowerCase())) {
|
|
106
|
+
throw new v_error_1.VerificationError([
|
|
107
|
+
{
|
|
87
108
|
key: "",
|
|
88
109
|
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.notIn, { notIn: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.notIn) }, {
|
|
89
110
|
es: (values) => `no debe ser uno de los siguientes valores ${values.notIn.join(", ")}`,
|
|
90
|
-
en: (values) => `must not be one of the following values ${values.notIn.join(", ")}
|
|
91
|
-
})
|
|
92
|
-
}
|
|
111
|
+
en: (values) => `must not be one of the following values ${values.notIn.join(", ")}`,
|
|
112
|
+
}),
|
|
113
|
+
},
|
|
114
|
+
]);
|
|
93
115
|
}
|
|
94
116
|
}
|
|
95
117
|
else {
|
|
96
118
|
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.notIn).includes(data)) {
|
|
97
|
-
throw new v_error_1.VerificationError([
|
|
119
|
+
throw new v_error_1.VerificationError([
|
|
120
|
+
{
|
|
98
121
|
key: "",
|
|
99
122
|
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.notIn, { notIn: (0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.notIn) }, {
|
|
100
123
|
es: (values) => `no debe ser uno de los siguientes valores ${values.notIn.join(", ")}`,
|
|
101
|
-
en: (values) => `must not be one of the following values ${values.notIn.join(", ")}
|
|
102
|
-
})
|
|
103
|
-
}
|
|
124
|
+
en: (values) => `must not be one of the following values ${values.notIn.join(", ")}`,
|
|
125
|
+
}),
|
|
126
|
+
},
|
|
127
|
+
]);
|
|
104
128
|
}
|
|
105
129
|
}
|
|
106
130
|
}
|
|
@@ -108,21 +132,23 @@ function vString(data, badTypeMessage, conds) {
|
|
|
108
132
|
}
|
|
109
133
|
class VStringNotNull extends verifier_1.Verifier {
|
|
110
134
|
check(data) {
|
|
111
|
-
|
|
135
|
+
var _a;
|
|
136
|
+
return vString(this.isRequired(data, true, (_a = this.cond) === null || _a === void 0 ? void 0 : _a.defaultValue), this.badTypeMessage, this.cond);
|
|
112
137
|
}
|
|
113
138
|
constructor(cond) {
|
|
114
139
|
super(cond);
|
|
115
140
|
this.cond = cond;
|
|
116
141
|
this.badTypeMessage = {
|
|
117
142
|
es: () => `debe ser un texto`,
|
|
118
|
-
en: () => `must be a string
|
|
143
|
+
en: () => `must be a string`,
|
|
119
144
|
};
|
|
120
145
|
}
|
|
121
146
|
}
|
|
122
147
|
exports.VStringNotNull = VStringNotNull;
|
|
123
148
|
class VString extends verifier_1.Verifier {
|
|
124
149
|
check(data) {
|
|
125
|
-
|
|
150
|
+
var _a;
|
|
151
|
+
let val = this.isRequired(data, undefined, (_a = this.cond) === null || _a === void 0 ? void 0 : _a.defaultValue);
|
|
126
152
|
if (val === null || val === undefined) {
|
|
127
153
|
return null;
|
|
128
154
|
}
|
|
@@ -133,7 +159,7 @@ class VString extends verifier_1.Verifier {
|
|
|
133
159
|
this.cond = cond;
|
|
134
160
|
this.badTypeMessage = {
|
|
135
161
|
es: () => `debe ser un texto`,
|
|
136
|
-
en: () => `must be a string
|
|
162
|
+
en: () => `must be a string`,
|
|
137
163
|
};
|
|
138
164
|
}
|
|
139
165
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v_string.js","sourceRoot":"","sources":["../../../../src/src/verifiers/string/v_string.ts"],"names":[],"mappings":";;;AAAA,iDAAwD;
|
|
1
|
+
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AAG,KAAK,SAAS,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IACD,YAAsB,IAAwB;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAC;QADQ,SAAI,GAAJ,IAAI,CAAoB;QAE5C,IAAI,CAAC,cAAc,GAAG;YACpB,EAAE,EAAE,GAAG,EAAE,CAAC,mBAAmB;YAC7B,EAAE,EAAE,GAAG,EAAE,CAAC,kBAAkB;SAC7B,CAAC;IACJ,CAAC;CACF;AAfD,0BAeC"}
|
|
@@ -6,51 +6,59 @@ const v_error_1 = require("../../error/v_error");
|
|
|
6
6
|
const message_1 = require("../../languages/message");
|
|
7
7
|
function vUUID(data, badTypeMessage, conds) {
|
|
8
8
|
var _a;
|
|
9
|
-
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.strictMode) === true && typeof data !==
|
|
10
|
-
throw new v_error_1.VerificationError([
|
|
9
|
+
if ((0, message_1.getValue)(conds === null || conds === void 0 ? void 0 : conds.strictMode) === true && typeof data !== "string") {
|
|
10
|
+
throw new v_error_1.VerificationError([
|
|
11
|
+
{
|
|
11
12
|
key: "",
|
|
12
|
-
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.badTypeMessage, undefined, badTypeMessage)
|
|
13
|
-
}
|
|
13
|
+
message: (0, message_1.getMessage)(conds === null || conds === void 0 ? void 0 : conds.badTypeMessage, undefined, badTypeMessage),
|
|
14
|
+
},
|
|
15
|
+
]);
|
|
14
16
|
}
|
|
15
17
|
let uuid = String(data);
|
|
16
|
-
const hasHyphens = uuid.includes(
|
|
18
|
+
const hasHyphens = uuid.includes("-");
|
|
17
19
|
if (!(conds === null || conds === void 0 ? void 0 : conds.allowNoHyphens) && !hasHyphens) {
|
|
18
|
-
throw new v_error_1.VerificationError([
|
|
20
|
+
throw new v_error_1.VerificationError([
|
|
21
|
+
{
|
|
19
22
|
key: "",
|
|
20
23
|
message: (0, message_1.getMessage)(undefined, undefined, {
|
|
21
24
|
es: () => `UUID debe incluir guiones`,
|
|
22
|
-
en: () => `UUID must include hyphens
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
+
en: () => `UUID must include hyphens`,
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
25
29
|
}
|
|
26
30
|
const normalized = uuid.replace(/-/g, "");
|
|
27
31
|
if (normalized.length !== 32) {
|
|
28
|
-
throw new v_error_1.VerificationError([
|
|
32
|
+
throw new v_error_1.VerificationError([
|
|
33
|
+
{
|
|
29
34
|
key: "",
|
|
30
35
|
message: (0, message_1.getMessage)(undefined, undefined, {
|
|
31
36
|
es: () => `UUID inválido, longitud incorrecta`,
|
|
32
|
-
en: () => `Invalid UUID, wrong length
|
|
33
|
-
})
|
|
34
|
-
}
|
|
37
|
+
en: () => `Invalid UUID, wrong length`,
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
]);
|
|
35
41
|
}
|
|
36
42
|
const versionPattern = (_a = conds === null || conds === void 0 ? void 0 : conds.version) !== null && _a !== void 0 ? _a : "[1-5]";
|
|
37
43
|
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
44
|
if (!regex.test(normalized)) {
|
|
39
|
-
throw new v_error_1.VerificationError([
|
|
45
|
+
throw new v_error_1.VerificationError([
|
|
46
|
+
{
|
|
40
47
|
key: "",
|
|
41
48
|
message: (0, message_1.getMessage)(undefined, undefined, {
|
|
42
49
|
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
|
-
}
|
|
50
|
+
en: (values) => `Invalid UUID${(conds === null || conds === void 0 ? void 0 : conds.version) ? ` for version ${conds.version}` : ""}`,
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
]);
|
|
46
54
|
}
|
|
47
55
|
const formatted = [
|
|
48
56
|
normalized.slice(0, 8),
|
|
49
57
|
normalized.slice(8, 12),
|
|
50
58
|
normalized.slice(12, 16),
|
|
51
59
|
normalized.slice(16, 20),
|
|
52
|
-
normalized.slice(20, 32)
|
|
53
|
-
].join(
|
|
60
|
+
normalized.slice(20, 32),
|
|
61
|
+
].join("-");
|
|
54
62
|
return formatted.toLowerCase();
|
|
55
63
|
}
|
|
56
64
|
class VUUIDNotNull extends verifier_1.Verifier {
|
|
@@ -59,11 +67,12 @@ class VUUIDNotNull extends verifier_1.Verifier {
|
|
|
59
67
|
this.cond = cond;
|
|
60
68
|
this.badTypeMessage = {
|
|
61
69
|
es: () => `debe ser un UUID`,
|
|
62
|
-
en: () => `must be a UUID
|
|
70
|
+
en: () => `must be a UUID`,
|
|
63
71
|
};
|
|
64
72
|
}
|
|
65
73
|
check(data) {
|
|
66
|
-
|
|
74
|
+
var _a;
|
|
75
|
+
return vUUID(this.isRequired(data, true, (_a = this.cond) === null || _a === void 0 ? void 0 : _a.defaultValue), this.badTypeMessage, this.cond);
|
|
67
76
|
}
|
|
68
77
|
}
|
|
69
78
|
exports.VUUIDNotNull = VUUIDNotNull;
|
|
@@ -73,11 +82,12 @@ class VUUID extends verifier_1.Verifier {
|
|
|
73
82
|
this.cond = cond;
|
|
74
83
|
this.badTypeMessage = {
|
|
75
84
|
es: () => `debe ser un UUID`,
|
|
76
|
-
en: () => `must be a UUID
|
|
85
|
+
en: () => `must be a UUID`,
|
|
77
86
|
};
|
|
78
87
|
}
|
|
79
88
|
check(data) {
|
|
80
|
-
|
|
89
|
+
var _a;
|
|
90
|
+
const val = this.isRequired(data, undefined, (_a = this.cond) === null || _a === void 0 ? void 0 : _a.defaultValue);
|
|
81
91
|
if (val === null || val === undefined)
|
|
82
92
|
return null;
|
|
83
93
|
return vUUID(val, this.badTypeMessage, this.cond);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v_uuid.js","sourceRoot":"","sources":["../../../../src/src/verifiers/uuid/v_uuid.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,iDAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"v_uuid.js","sourceRoot":"","sources":["../../../../src/src/verifiers/uuid/v_uuid.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,iDAAwD;AACxD,qDAIiC;AAejC,SAAS,KAAK,CACZ,IAAS,EACT,cAAsC,EACtC,KAAuB;;IAEvB,IAAI,IAAA,kBAAQ,EAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,CAAC,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrE,MAAM,IAAI,2BAAiB,CAAC;YAC1B;gBACE,GAAG,EAAE,EAAE;gBACP,OAAO,EAAE,IAAA,oBAAU,EAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,EAAE,SAAS,EAAE,cAAc,CAAC;aACtE;SACF,CAAC,CAAC;IACL,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;QAC1C,MAAM,IAAI,2BAAiB,CAAC;YAC1B;gBACE,GAAG,EAAE,EAAE;gBACP,OAAO,EAAE,IAAA,oBAAU,EAAC,SAAS,EAAE,SAAS,EAAE;oBACxC,EAAE,EAAE,GAAG,EAAE,CAAC,2BAA2B;oBACrC,EAAE,EAAE,GAAG,EAAE,CAAC,2BAA2B;iBACtC,C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AE,SAAS,EAAE,MAAA,IAAI,CAAC,IAAI,0CAAE,YAAY,CAAC,CAAC;QACtE,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACnD,OAAO,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;CACF;AAdD,sBAcC"}
|
|
@@ -5,5 +5,5 @@ export declare abstract class Verifier<T> {
|
|
|
5
5
|
constructor(cond?: VVCIsRequired | undefined);
|
|
6
6
|
abstract check(data: any): T;
|
|
7
7
|
protected badTypeMessage: IMessageLanguage<void>;
|
|
8
|
-
protected isRequired(data: any, isRequired?: boolean): T;
|
|
8
|
+
protected isRequired(data: any, isRequired?: boolean, defaultValue?: T): T;
|
|
9
9
|
}
|
|
@@ -8,13 +8,16 @@ class Verifier {
|
|
|
8
8
|
constructor(cond) {
|
|
9
9
|
this.cond = cond;
|
|
10
10
|
}
|
|
11
|
-
isRequired(data, isRequired) {
|
|
11
|
+
isRequired(data, isRequired, defaultValue) {
|
|
12
12
|
var _a, _b;
|
|
13
13
|
let mReq = {
|
|
14
14
|
es: () => "es requerido y",
|
|
15
|
-
en: () => "is required and"
|
|
15
|
+
en: () => "is required and",
|
|
16
16
|
};
|
|
17
|
-
if (
|
|
17
|
+
if (data === undefined || (data === null && defaultValue !== undefined)) {
|
|
18
|
+
data = defaultValue;
|
|
19
|
+
}
|
|
20
|
+
if (typeof data === "string" && ((_a = this.cond) === null || _a === void 0 ? void 0 : _a.emptyAsNull) === true) {
|
|
18
21
|
if (data.length === 0) {
|
|
19
22
|
data = null;
|
|
20
23
|
}
|
|
@@ -23,7 +26,7 @@ class Verifier {
|
|
|
23
26
|
if (((_b = this.cond) === null || _b === void 0 ? void 0 : _b.isRequired) !== undefined) {
|
|
24
27
|
reqVal = this.cond.isRequired;
|
|
25
28
|
if (isRequired !== undefined) {
|
|
26
|
-
if (typeof reqVal ===
|
|
29
|
+
if (typeof reqVal === "boolean") {
|
|
27
30
|
reqVal = isRequired;
|
|
28
31
|
}
|
|
29
32
|
else {
|
|
@@ -37,11 +40,13 @@ class Verifier {
|
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
if (isRequired && (data === null || data === undefined)) {
|
|
40
|
-
throw new v_error_1.VerificationError([
|
|
43
|
+
throw new v_error_1.VerificationError([
|
|
44
|
+
{
|
|
41
45
|
key: "",
|
|
42
46
|
message: `${(0, message_1.getMessage)(reqVal, undefined, mReq)} ${this.badTypeMessage[verifierConfig_1.VerifierConfig.lang]()}`,
|
|
43
|
-
isEmpty: true
|
|
44
|
-
}
|
|
47
|
+
isEmpty: true,
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
45
50
|
}
|
|
46
51
|
return data;
|
|
47
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../../src/src/verifiers/verifier.ts"],"names":[],"mappings":";;;AAAA,6DAA0D;AAC1D,8CAAqD;AAErD,
|
|
1
|
+
{"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../../src/src/verifiers/verifier.ts"],"names":[],"mappings":";;;AAAA,6DAA0D;AAC1D,8CAAqD;AAErD,kDAI8B;AAE9B,MAAsB,QAAQ;IAC5B,YAAsB,IAAoB;QAApB,SAAI,GAAJ,IAAI,CAAgB;IAAG,CAAC;IAGpC,UAAU,CAAC,IAAS,EAAE,UAAoB,EAAE,YAAgB;;QACpE,IAAI,IAAI,GAA2B;YACjC,EAAE,EAAE,GAAG,EAAE,CAAC,gBAAgB;YAC1B,EAAE,EAAE,GAAG,EAAE,CAAC,iBAAiB;SAC5B,CAAC;QACF,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,YAAY,KAAK,SAAS,CAAC,EAAE,CAAC;YACxE,IAAI,GAAG,YAAY,CAAC;QACtB,CAAC;QACD,IAAI,OAAO,IAAI,KAAK,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