valgen 5.18.2 → 5.19.0
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/{types/constants.d.ts → constants.d.ts} +1 -0
- package/{esm/constants.js → constants.js} +1 -0
- package/{esm/core → core}/context.js +12 -2
- package/{esm/core → core}/validation-error.js +1 -1
- package/package.json +9 -25
- package/{types/rules → rules}/type-rules/is-date.d.ts +1 -0
- package/{esm/rules → rules}/type-rules/is-date.js +21 -10
- package/CHANGELOG.md +0 -384
- package/cjs/constants.js +0 -7
- package/cjs/core/constants.js +0 -5
- package/cjs/core/context.js +0 -74
- package/cjs/core/index.js +0 -9
- package/cjs/core/types.js +0 -2
- package/cjs/core/utilities.js +0 -30
- package/cjs/core/validation-error.js +0 -12
- package/cjs/core/validator.js +0 -71
- package/cjs/factories.js +0 -4
- package/cjs/helpers/object.utils.js +0 -18
- package/cjs/helpers/omit-undefined.js +0 -14
- package/cjs/helpers/string.utils.js +0 -6
- package/cjs/index.js +0 -129
- package/cjs/package.json +0 -3
- package/cjs/rules/format-rules/is-alpha.js +0 -30
- package/cjs/rules/format-rules/is-ascii.js +0 -17
- package/cjs/rules/format-rules/is-base64.js +0 -18
- package/cjs/rules/format-rules/is-btc-address.js +0 -18
- package/cjs/rules/format-rules/is-credit-card.js +0 -19
- package/cjs/rules/format-rules/is-decimal.js +0 -19
- package/cjs/rules/format-rules/is-ean.js +0 -17
- package/cjs/rules/format-rules/is-email.js +0 -66
- package/cjs/rules/format-rules/is-eth-address.js +0 -18
- package/cjs/rules/format-rules/is-fqdn.js +0 -21
- package/cjs/rules/format-rules/is-hash.js +0 -18
- package/cjs/rules/format-rules/is-hex-color.js +0 -18
- package/cjs/rules/format-rules/is-hex.js +0 -18
- package/cjs/rules/format-rules/is-iban.js +0 -29
- package/cjs/rules/format-rules/is-ip.js +0 -35
- package/cjs/rules/format-rules/is-issn.js +0 -21
- package/cjs/rules/format-rules/is-jwt.js +0 -17
- package/cjs/rules/format-rules/is-lowercase.js +0 -31
- package/cjs/rules/format-rules/is-mac-address.js +0 -24
- package/cjs/rules/format-rules/is-mobile-phone.js +0 -22
- package/cjs/rules/format-rules/is-object-id.js +0 -28
- package/cjs/rules/format-rules/is-passport-number.js +0 -19
- package/cjs/rules/format-rules/is-port.js +0 -22
- package/cjs/rules/format-rules/is-time.js +0 -51
- package/cjs/rules/format-rules/is-url.js +0 -20
- package/cjs/rules/format-rules/is-uuid.js +0 -20
- package/cjs/rules/format-rules/is-vat-number.js +0 -18
- package/cjs/rules/format-rules/matches.js +0 -22
- package/cjs/rules/index.js +0 -56
- package/cjs/rules/logical-rules/is-defined.js +0 -15
- package/cjs/rules/logical-rules/is-empty.js +0 -110
- package/cjs/rules/logical-rules/is-equal.js +0 -32
- package/cjs/rules/logical-rules/range.js +0 -175
- package/cjs/rules/type-rules/is-any.js +0 -10
- package/cjs/rules/type-rules/is-array.js +0 -45
- package/cjs/rules/type-rules/is-bigint.js +0 -21
- package/cjs/rules/type-rules/is-boolean.js +0 -31
- package/cjs/rules/type-rules/is-date.js +0 -180
- package/cjs/rules/type-rules/is-enum.js +0 -31
- package/cjs/rules/type-rules/is-integer.js +0 -30
- package/cjs/rules/type-rules/is-null.js +0 -54
- package/cjs/rules/type-rules/is-number.js +0 -27
- package/cjs/rules/type-rules/is-object.js +0 -113
- package/cjs/rules/type-rules/is-record.js +0 -42
- package/cjs/rules/type-rules/is-string.js +0 -81
- package/cjs/rules/type-rules/is-tuple.js +0 -38
- package/cjs/rules/type-rules/is-undefined.js +0 -17
- package/cjs/rules/utility-rules/all-of.js +0 -20
- package/cjs/rules/utility-rules/exists.js +0 -18
- package/cjs/rules/utility-rules/get-length.js +0 -29
- package/cjs/rules/utility-rules/one-of.js +0 -59
- package/cjs/rules/utility-rules/optional.js +0 -15
- package/cjs/rules/utility-rules/pipe.js +0 -28
- package/cjs/rules/utility-rules/required.js +0 -19
- package/cjs/tsconfig-build-cjs.tsbuildinfo +0 -1
- package/esm/package.json +0 -3
- package/esm/tsconfig-build-esm.tsbuildinfo +0 -1
- package/types/index.d.cts +0 -65
- /package/{types/core → core}/constants.d.ts +0 -0
- /package/{esm/core → core}/constants.js +0 -0
- /package/{types/core → core}/context.d.ts +0 -0
- /package/{types/core → core}/index.d.ts +0 -0
- /package/{esm/core → core}/index.js +0 -0
- /package/{types/core → core}/types.d.ts +0 -0
- /package/{esm/core → core}/types.js +0 -0
- /package/{types/core → core}/utilities.d.ts +0 -0
- /package/{esm/core → core}/utilities.js +0 -0
- /package/{types/core → core}/validation-error.d.ts +0 -0
- /package/{types/core → core}/validator.d.ts +0 -0
- /package/{esm/core → core}/validator.js +0 -0
- /package/{types/factories.d.ts → factories.d.ts} +0 -0
- /package/{esm/factories.js → factories.js} +0 -0
- /package/{types/helpers → helpers}/object.utils.d.ts +0 -0
- /package/{esm/helpers → helpers}/object.utils.js +0 -0
- /package/{types/helpers → helpers}/omit-undefined.d.ts +0 -0
- /package/{esm/helpers → helpers}/omit-undefined.js +0 -0
- /package/{types/helpers → helpers}/string.utils.d.ts +0 -0
- /package/{esm/helpers → helpers}/string.utils.js +0 -0
- /package/{types/index.d.ts → index.d.ts} +0 -0
- /package/{esm/index.js → index.js} +0 -0
- /package/{types/rules → rules}/format-rules/is-alpha.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-alpha.js +0 -0
- /package/{types/rules → rules}/format-rules/is-ascii.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-ascii.js +0 -0
- /package/{types/rules → rules}/format-rules/is-base64.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-base64.js +0 -0
- /package/{types/rules → rules}/format-rules/is-btc-address.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-btc-address.js +0 -0
- /package/{types/rules → rules}/format-rules/is-credit-card.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-credit-card.js +0 -0
- /package/{types/rules → rules}/format-rules/is-decimal.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-decimal.js +0 -0
- /package/{types/rules → rules}/format-rules/is-ean.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-ean.js +0 -0
- /package/{types/rules → rules}/format-rules/is-email.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-email.js +0 -0
- /package/{types/rules → rules}/format-rules/is-eth-address.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-eth-address.js +0 -0
- /package/{types/rules → rules}/format-rules/is-fqdn.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-fqdn.js +0 -0
- /package/{types/rules → rules}/format-rules/is-hash.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-hash.js +0 -0
- /package/{types/rules → rules}/format-rules/is-hex-color.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-hex-color.js +0 -0
- /package/{types/rules → rules}/format-rules/is-hex.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-hex.js +0 -0
- /package/{types/rules → rules}/format-rules/is-iban.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-iban.js +0 -0
- /package/{types/rules → rules}/format-rules/is-ip.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-ip.js +0 -0
- /package/{types/rules → rules}/format-rules/is-issn.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-issn.js +0 -0
- /package/{types/rules → rules}/format-rules/is-jwt.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-jwt.js +0 -0
- /package/{types/rules → rules}/format-rules/is-lowercase.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-lowercase.js +0 -0
- /package/{types/rules → rules}/format-rules/is-mac-address.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-mac-address.js +0 -0
- /package/{types/rules → rules}/format-rules/is-mobile-phone.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-mobile-phone.js +0 -0
- /package/{types/rules → rules}/format-rules/is-object-id.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-object-id.js +0 -0
- /package/{types/rules → rules}/format-rules/is-passport-number.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-passport-number.js +0 -0
- /package/{types/rules → rules}/format-rules/is-port.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-port.js +0 -0
- /package/{types/rules → rules}/format-rules/is-time.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-time.js +0 -0
- /package/{types/rules → rules}/format-rules/is-url.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-url.js +0 -0
- /package/{types/rules → rules}/format-rules/is-uuid.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-uuid.js +0 -0
- /package/{types/rules → rules}/format-rules/is-vat-number.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-vat-number.js +0 -0
- /package/{types/rules → rules}/format-rules/matches.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/matches.js +0 -0
- /package/{types/rules → rules}/index.d.ts +0 -0
- /package/{esm/rules → rules}/index.js +0 -0
- /package/{types/rules → rules}/logical-rules/is-defined.d.ts +0 -0
- /package/{esm/rules → rules}/logical-rules/is-defined.js +0 -0
- /package/{types/rules → rules}/logical-rules/is-empty.d.ts +0 -0
- /package/{esm/rules → rules}/logical-rules/is-empty.js +0 -0
- /package/{types/rules → rules}/logical-rules/is-equal.d.ts +0 -0
- /package/{esm/rules → rules}/logical-rules/is-equal.js +0 -0
- /package/{types/rules → rules}/logical-rules/range.d.ts +0 -0
- /package/{esm/rules → rules}/logical-rules/range.js +0 -0
- /package/{types/rules → rules}/type-rules/is-any.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-any.js +0 -0
- /package/{types/rules → rules}/type-rules/is-array.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-array.js +0 -0
- /package/{types/rules → rules}/type-rules/is-bigint.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-bigint.js +0 -0
- /package/{types/rules → rules}/type-rules/is-boolean.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-boolean.js +0 -0
- /package/{types/rules → rules}/type-rules/is-enum.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-enum.js +0 -0
- /package/{types/rules → rules}/type-rules/is-integer.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-integer.js +0 -0
- /package/{types/rules → rules}/type-rules/is-null.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-null.js +0 -0
- /package/{types/rules → rules}/type-rules/is-number.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-number.js +0 -0
- /package/{types/rules → rules}/type-rules/is-object.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-object.js +0 -0
- /package/{types/rules → rules}/type-rules/is-record.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-record.js +0 -0
- /package/{types/rules → rules}/type-rules/is-string.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-string.js +0 -0
- /package/{types/rules → rules}/type-rules/is-tuple.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-tuple.js +0 -0
- /package/{types/rules → rules}/type-rules/is-undefined.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-undefined.js +0 -0
- /package/{types/rules → rules}/utility-rules/all-of.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/all-of.js +0 -0
- /package/{types/rules → rules}/utility-rules/exists.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/exists.js +0 -0
- /package/{types/rules → rules}/utility-rules/get-length.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/get-length.js +0 -0
- /package/{types/rules → rules}/utility-rules/one-of.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/one-of.js +0 -0
- /package/{types/rules → rules}/utility-rules/optional.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/optional.js +0 -0
- /package/{types/rules → rules}/utility-rules/pipe.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/pipe.js +0 -0
- /package/{types/rules → rules}/utility-rules/required.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/required.js +0 -0
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lengthMax = exports.lengthMin = void 0;
|
|
4
|
-
exports.range = range;
|
|
5
|
-
exports.isGt = isGt;
|
|
6
|
-
exports.isGte = isGte;
|
|
7
|
-
exports.isLt = isLt;
|
|
8
|
-
exports.isLte = isLte;
|
|
9
|
-
const index_js_1 = require("../../core/index.js");
|
|
10
|
-
const all_of_js_1 = require("../utility-rules/all-of.js");
|
|
11
|
-
const get_length_js_1 = require("../utility-rules/get-length.js");
|
|
12
|
-
const pipe_js_1 = require("../utility-rules/pipe.js");
|
|
13
|
-
/**
|
|
14
|
-
* Checks if value is between minValue and maxValue
|
|
15
|
-
* @validator range
|
|
16
|
-
*/
|
|
17
|
-
function range(minValue, maxValue, options) {
|
|
18
|
-
return (0, index_js_1.validator)('range', (input, context, _this) => {
|
|
19
|
-
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
20
|
-
(typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
21
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
22
|
-
input >= minValue &&
|
|
23
|
-
input <= maxValue) {
|
|
24
|
-
return input;
|
|
25
|
-
}
|
|
26
|
-
if (minValue instanceof Date &&
|
|
27
|
-
maxValue instanceof Date &&
|
|
28
|
-
input instanceof Date &&
|
|
29
|
-
input >= minValue &&
|
|
30
|
-
input <= maxValue) {
|
|
31
|
-
return input;
|
|
32
|
-
}
|
|
33
|
-
if (typeof minValue === 'string' &&
|
|
34
|
-
typeof maxValue === 'string' &&
|
|
35
|
-
typeof input === 'string' &&
|
|
36
|
-
input >= minValue &&
|
|
37
|
-
input <= maxValue) {
|
|
38
|
-
return input;
|
|
39
|
-
}
|
|
40
|
-
context.fail(_this, `Value must be between ${minValue} and ${maxValue}`, input);
|
|
41
|
-
}, options);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Checks if value is grater than "minValue"
|
|
45
|
-
* @validator iGt
|
|
46
|
-
*/
|
|
47
|
-
function isGt(minValue, options) {
|
|
48
|
-
return (0, index_js_1.validator)('isGt', (input, context, _this) => {
|
|
49
|
-
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
50
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
51
|
-
input > minValue) {
|
|
52
|
-
return input;
|
|
53
|
-
}
|
|
54
|
-
if (minValue instanceof Date &&
|
|
55
|
-
input instanceof Date &&
|
|
56
|
-
input > minValue) {
|
|
57
|
-
return input;
|
|
58
|
-
}
|
|
59
|
-
if (typeof minValue === 'string' &&
|
|
60
|
-
typeof input === 'string' &&
|
|
61
|
-
(input > minValue ||
|
|
62
|
-
(options?.caseInsensitive &&
|
|
63
|
-
input.toLowerCase() > minValue.toLowerCase()))) {
|
|
64
|
-
return input;
|
|
65
|
-
}
|
|
66
|
-
context.fail(_this, `Value must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
67
|
-
}, options);
|
|
68
|
-
}
|
|
69
|
-
// *************************************************************
|
|
70
|
-
/**
|
|
71
|
-
* Checks if value is grater than or equal to minValue
|
|
72
|
-
* @validator isGte
|
|
73
|
-
*/
|
|
74
|
-
function isGte(minValue, options) {
|
|
75
|
-
return (0, index_js_1.validator)('isGte', (input, context, _this) => {
|
|
76
|
-
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
77
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
78
|
-
input >= minValue) {
|
|
79
|
-
return input;
|
|
80
|
-
}
|
|
81
|
-
if (minValue instanceof Date &&
|
|
82
|
-
input instanceof Date &&
|
|
83
|
-
input >= minValue) {
|
|
84
|
-
return input;
|
|
85
|
-
}
|
|
86
|
-
if (typeof minValue === 'string' &&
|
|
87
|
-
typeof input === 'string' &&
|
|
88
|
-
(input >= minValue ||
|
|
89
|
-
(options?.caseInsensitive &&
|
|
90
|
-
input.toLowerCase() >= minValue.toLowerCase()))) {
|
|
91
|
-
return input;
|
|
92
|
-
}
|
|
93
|
-
context.fail(_this, `Value must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
94
|
-
}, options);
|
|
95
|
-
}
|
|
96
|
-
// *************************************************************
|
|
97
|
-
/**
|
|
98
|
-
* Checks if number value is lover than maxValue
|
|
99
|
-
* @validator isLt
|
|
100
|
-
*/
|
|
101
|
-
function isLt(maxValue, options) {
|
|
102
|
-
return (0, index_js_1.validator)('isLt', (input, context, _this) => {
|
|
103
|
-
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
104
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
105
|
-
input < maxValue) {
|
|
106
|
-
return input;
|
|
107
|
-
}
|
|
108
|
-
if (maxValue instanceof Date &&
|
|
109
|
-
input instanceof Date &&
|
|
110
|
-
input < maxValue) {
|
|
111
|
-
return input;
|
|
112
|
-
}
|
|
113
|
-
if (typeof maxValue === 'string' &&
|
|
114
|
-
typeof input === 'string' &&
|
|
115
|
-
(input < maxValue ||
|
|
116
|
-
(options?.caseInsensitive &&
|
|
117
|
-
input.toLowerCase() < maxValue.toLowerCase()))) {
|
|
118
|
-
return input;
|
|
119
|
-
}
|
|
120
|
-
context.fail(_this, `Value must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
|
|
121
|
-
}, options);
|
|
122
|
-
}
|
|
123
|
-
// *************************************************************
|
|
124
|
-
/**
|
|
125
|
-
* Checks if value is lover than or equal to maxValue
|
|
126
|
-
* @validator isLte
|
|
127
|
-
*/
|
|
128
|
-
function isLte(maxValue, options) {
|
|
129
|
-
return (0, index_js_1.validator)('isLte', (input, context, _this) => {
|
|
130
|
-
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
131
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
132
|
-
input <= maxValue) {
|
|
133
|
-
return input;
|
|
134
|
-
}
|
|
135
|
-
if (maxValue instanceof Date &&
|
|
136
|
-
input instanceof Date &&
|
|
137
|
-
input <= maxValue) {
|
|
138
|
-
return input;
|
|
139
|
-
}
|
|
140
|
-
if (typeof maxValue === 'string' &&
|
|
141
|
-
typeof input === 'string' &&
|
|
142
|
-
(input <= maxValue ||
|
|
143
|
-
(options?.caseInsensitive &&
|
|
144
|
-
input.toLowerCase() <= maxValue.toLowerCase()))) {
|
|
145
|
-
return input;
|
|
146
|
-
}
|
|
147
|
-
context.fail(_this, `Value must be lover than or equal to ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
|
|
148
|
-
}, options);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Checks the length is at least "minValue"
|
|
152
|
-
* @validator lengthMin
|
|
153
|
-
*/
|
|
154
|
-
const lengthMin = (minValue) => (0, all_of_js_1.allOf)([
|
|
155
|
-
(0, pipe_js_1.pipe)([
|
|
156
|
-
(0, get_length_js_1.getLength)(),
|
|
157
|
-
isGte(minValue, {
|
|
158
|
-
onFail: () => `Value length must be at least ${minValue}`,
|
|
159
|
-
}),
|
|
160
|
-
]),
|
|
161
|
-
]);
|
|
162
|
-
exports.lengthMin = lengthMin;
|
|
163
|
-
/**
|
|
164
|
-
* Checks if the length is at most "maxValue"
|
|
165
|
-
* @validator lengthMax
|
|
166
|
-
*/
|
|
167
|
-
const lengthMax = (maxValue) => (0, all_of_js_1.allOf)([
|
|
168
|
-
(0, pipe_js_1.pipe)([
|
|
169
|
-
(0, get_length_js_1.getLength)(),
|
|
170
|
-
isLte(maxValue, {
|
|
171
|
-
onFail: () => `The length of {{label}} must be at most ${maxValue}`,
|
|
172
|
-
}),
|
|
173
|
-
]),
|
|
174
|
-
]);
|
|
175
|
-
exports.lengthMax = lengthMax;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isAny = void 0;
|
|
4
|
-
const index_js_1 = require("../../core/index.js");
|
|
5
|
-
/**
|
|
6
|
-
* Does nothing, just returns original input value.
|
|
7
|
-
* @validator isAny
|
|
8
|
-
*/
|
|
9
|
-
const isAny = () => (0, index_js_1.validator)('is-any', (input) => input);
|
|
10
|
-
exports.isAny = isAny;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isArray = isArray;
|
|
4
|
-
const index_js_1 = require("../../core/index.js");
|
|
5
|
-
/**
|
|
6
|
-
* Validates if value is "array" and applies validation for each item.
|
|
7
|
-
* Converts input value to array if coerce option is set to 'true'.
|
|
8
|
-
* @validator isArray
|
|
9
|
-
*/
|
|
10
|
-
function isArray(itemValidator, options) {
|
|
11
|
-
return (0, index_js_1.validator)('isArray', (input, context, _this) => {
|
|
12
|
-
const coerce = options?.coerce ?? context.coerce;
|
|
13
|
-
let output = input;
|
|
14
|
-
if (output != null && coerce && !Array.isArray(output))
|
|
15
|
-
output = [output];
|
|
16
|
-
if (!Array.isArray(output)) {
|
|
17
|
-
context.fail(_this, `Value must be an array`, input);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (!itemValidator)
|
|
21
|
-
return output;
|
|
22
|
-
// const location = context.location || '';
|
|
23
|
-
const itemContext = context.extend();
|
|
24
|
-
let i;
|
|
25
|
-
let v;
|
|
26
|
-
const l = output.length;
|
|
27
|
-
const out = [];
|
|
28
|
-
for (i = 0; i < l; i++) {
|
|
29
|
-
v = output[i];
|
|
30
|
-
itemContext.scope = output;
|
|
31
|
-
// itemContext.location = location + '[' + i + ']';
|
|
32
|
-
itemContext.location = context.location
|
|
33
|
-
? context.location + `[${i}]`
|
|
34
|
-
: `<Array>[${i}]`;
|
|
35
|
-
itemContext.index = i;
|
|
36
|
-
v = itemValidator(v, {
|
|
37
|
-
onFail(issue) {
|
|
38
|
-
return `Item at index [${i}] is not valid. ` + issue.message;
|
|
39
|
-
},
|
|
40
|
-
}, itemContext);
|
|
41
|
-
out.push(v);
|
|
42
|
-
}
|
|
43
|
-
return out;
|
|
44
|
-
}, options);
|
|
45
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBigint = isBigint;
|
|
4
|
-
const index_js_1 = require("../../core/index.js");
|
|
5
|
-
/**
|
|
6
|
-
* Validates if value is "BigInt".
|
|
7
|
-
* Converts input value to number if coerce option is set to 'true'.
|
|
8
|
-
* @validator isNumber
|
|
9
|
-
*/
|
|
10
|
-
function isBigint(options) {
|
|
11
|
-
return (0, index_js_1.validator)('isBigint', (input, context, _this) => {
|
|
12
|
-
const coerce = options?.coerce ?? context.coerce;
|
|
13
|
-
if (typeof input === 'bigint')
|
|
14
|
-
return input;
|
|
15
|
-
if ((typeof input === 'number' && !isNaN(input)) ||
|
|
16
|
-
(typeof input === 'string' && coerce)) {
|
|
17
|
-
return BigInt(input);
|
|
18
|
-
}
|
|
19
|
-
context.fail(_this, `Value must be a BigInt`, input);
|
|
20
|
-
}, options);
|
|
21
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBoolean = isBoolean;
|
|
4
|
-
const index_js_1 = require("../../core/index.js");
|
|
5
|
-
const TRUE_PATTERN = /^true|t|1|yes|y$/i;
|
|
6
|
-
const FALSE_PATTERN = /^false|f|0|no|n$/i;
|
|
7
|
-
/**
|
|
8
|
-
* Validates if value is "boolean".
|
|
9
|
-
* Converts input value to boolean if coerce option is set to 'true'.
|
|
10
|
-
* @validator isBoolean
|
|
11
|
-
*/
|
|
12
|
-
function isBoolean(options) {
|
|
13
|
-
return (0, index_js_1.validator)('isBoolean', (input, context, _this) => {
|
|
14
|
-
const coerce = options?.coerce ?? context.coerce;
|
|
15
|
-
let output = input;
|
|
16
|
-
if (output != null && typeof output !== 'boolean' && coerce) {
|
|
17
|
-
if (typeof input === 'string') {
|
|
18
|
-
if (TRUE_PATTERN.test(input))
|
|
19
|
-
return true;
|
|
20
|
-
if (FALSE_PATTERN.test(input))
|
|
21
|
-
return false;
|
|
22
|
-
throw new TypeError(`Invalid boolean string`);
|
|
23
|
-
}
|
|
24
|
-
if (input === 1 || input === 0)
|
|
25
|
-
output = !!input;
|
|
26
|
-
}
|
|
27
|
-
if (typeof output === 'boolean')
|
|
28
|
-
return output;
|
|
29
|
-
context.fail(_this, `Value must be a boolean`, input);
|
|
30
|
-
}, options);
|
|
31
|
-
}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDate = isDate;
|
|
4
|
-
exports.isDateString = isDateString;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const datefns = tslib_1.__importStar(require("date-fns"));
|
|
7
|
-
const index_js_1 = require("../../core/index.js");
|
|
8
|
-
/**
|
|
9
|
-
* Validates if value is a "Date" instance or ISO 8601 formatted date string.
|
|
10
|
-
* if a `coerce` option is `true`, converts input value to Date instance
|
|
11
|
-
* @validator isDate
|
|
12
|
-
*/
|
|
13
|
-
function isDate(options) {
|
|
14
|
-
const trim = options?.trim;
|
|
15
|
-
return (0, index_js_1.validator)('isDate', (input, context, _this) => {
|
|
16
|
-
const coerce = options?.coerce ?? context.coerce;
|
|
17
|
-
let d;
|
|
18
|
-
if (input instanceof Date)
|
|
19
|
-
d = input;
|
|
20
|
-
else if (coerce) {
|
|
21
|
-
if (typeof input === 'number')
|
|
22
|
-
d = new Date(input);
|
|
23
|
-
else if (typeof input === 'string') {
|
|
24
|
-
const parsed = coerceDateString(input);
|
|
25
|
-
if (parsed) {
|
|
26
|
-
d = new Date(parsed.value);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (datefns.isValid(d)) {
|
|
31
|
-
setPrecision(d, trim);
|
|
32
|
-
return d;
|
|
33
|
-
}
|
|
34
|
-
context.fail(_this, `Value is not valid date`, input, {
|
|
35
|
-
...options,
|
|
36
|
-
});
|
|
37
|
-
}, options);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Validates if value is DFS (date formatted string).
|
|
41
|
-
* Converts input value to DFS if the "coerce" option is set to 'true'.
|
|
42
|
-
* @validator isDateString
|
|
43
|
-
*/
|
|
44
|
-
function isDateString(options) {
|
|
45
|
-
const precisionMin = options?.precisionMin || 'minutes';
|
|
46
|
-
const precisionMax = options?.precisionMax || 'tz';
|
|
47
|
-
const precisionMaxIdx = PRECISION_INDEX[precisionMax] || 9;
|
|
48
|
-
const precisionMinIdx = Math.min(precisionMaxIdx, PRECISION_INDEX[precisionMin] || 6);
|
|
49
|
-
return (0, index_js_1.validator)('isDateString', (input, context, _this) => {
|
|
50
|
-
const coerce = options?.coerce ?? context.coerce;
|
|
51
|
-
const parsed = coerceDateString(input, options?.trim);
|
|
52
|
-
if (parsed) {
|
|
53
|
-
if (parsed.precision >= precisionMinIdx &&
|
|
54
|
-
parsed.precision <= precisionMaxIdx) {
|
|
55
|
-
return coerce ? parsed.value : input;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
context.fail(_this, `Value is not valid date string` +
|
|
59
|
-
(options?.precisionMin || options?.precisionMax
|
|
60
|
-
? ` with required precision`
|
|
61
|
-
: ''), input, {
|
|
62
|
-
...options,
|
|
63
|
-
});
|
|
64
|
-
}, options);
|
|
65
|
-
}
|
|
66
|
-
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
67
|
-
const DATE_PATTERN = /^(\d{4})(?:-(0[0-9]|1[0-2]))?(?:-([0-2][0-9]|3[0-1]))?(?:[T ](?:([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?(?:\.(\d{0,6}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
|
|
68
|
-
const DATE_PATTERN2 = /^(\d{4,14})(?:\.(\d{1,6}))?(?:(?:([+-])(0[0-9]|1[0-2])(\d{2})?)|Z)?$/;
|
|
69
|
-
function coerceDateString(input, precision) {
|
|
70
|
-
let dateParts;
|
|
71
|
-
let outPrecision = 0;
|
|
72
|
-
if (input instanceof Date || typeof input === 'number') {
|
|
73
|
-
const d = typeof input === 'number' ? new Date(input) : input;
|
|
74
|
-
dateParts = [
|
|
75
|
-
String(d.getFullYear()).padStart(4, '0'),
|
|
76
|
-
String(d.getMonth() + 1).padStart(2, '0'),
|
|
77
|
-
String(d.getDate()).padStart(2, '0'),
|
|
78
|
-
String(d.getHours()).padStart(2, '0'),
|
|
79
|
-
String(d.getMinutes()).padStart(2, '0'),
|
|
80
|
-
String(d.getSeconds()).padStart(2, '0'),
|
|
81
|
-
];
|
|
82
|
-
if (d.getMilliseconds() > 0)
|
|
83
|
-
dateParts.push(String(d.getMilliseconds()).padStart(3, '0'));
|
|
84
|
-
}
|
|
85
|
-
else if (typeof input === 'string') {
|
|
86
|
-
const d = datefns.parseISO(input);
|
|
87
|
-
let m = DATE_PATTERN.exec(input);
|
|
88
|
-
if (m && datefns.isValid(d)) {
|
|
89
|
-
m.shift();
|
|
90
|
-
dateParts = m;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
m = DATE_PATTERN2.exec(input);
|
|
94
|
-
if (m) {
|
|
95
|
-
dateParts = [
|
|
96
|
-
m[1].substring(0, 4),
|
|
97
|
-
m[1].substring(4, 6),
|
|
98
|
-
m[1].substring(6, 8),
|
|
99
|
-
m[1].substring(8, 10),
|
|
100
|
-
m[1].substring(10, 12),
|
|
101
|
-
m[1].substring(12, 14),
|
|
102
|
-
m[2],
|
|
103
|
-
m[3] ? m[3] + m[4] + (m[5] ? ':' + m[5] : '') : '',
|
|
104
|
-
];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (!dateParts)
|
|
109
|
-
return;
|
|
110
|
-
outPrecision = dateParts.findIndex(v => !v);
|
|
111
|
-
if (outPrecision === -1)
|
|
112
|
-
outPrecision = dateParts.length;
|
|
113
|
-
const precisionIndex = (precision ? PRECISION_INDEX[precision] : 9) || 9;
|
|
114
|
-
let value = dateParts[0] || '0000';
|
|
115
|
-
if (precisionIndex > 1)
|
|
116
|
-
value += '-' + (dateParts[1] || '01');
|
|
117
|
-
if (precisionIndex > 2)
|
|
118
|
-
value += '-' + (dateParts[2] || '01');
|
|
119
|
-
if (precisionIndex > 3)
|
|
120
|
-
value += 'T' + (dateParts[3] || '00');
|
|
121
|
-
if (precisionIndex > 4)
|
|
122
|
-
value += ':' + (dateParts[4] || '00');
|
|
123
|
-
if (precisionIndex > 5)
|
|
124
|
-
value += ':' + (dateParts[5] || '00');
|
|
125
|
-
if (precisionIndex > 5)
|
|
126
|
-
value += dateParts[6] ? '.' + dateParts[6] : '';
|
|
127
|
-
if (precisionIndex > 7)
|
|
128
|
-
value += dateParts[7] || '';
|
|
129
|
-
return {
|
|
130
|
-
value,
|
|
131
|
-
precision: outPrecision || 8,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
const PRECISION_INDEX = {
|
|
135
|
-
year: 1,
|
|
136
|
-
yr: 1,
|
|
137
|
-
month: 2,
|
|
138
|
-
mo: 2,
|
|
139
|
-
day: 3,
|
|
140
|
-
d: 4,
|
|
141
|
-
hours: 4,
|
|
142
|
-
hr: 4,
|
|
143
|
-
minutes: 5,
|
|
144
|
-
min: 5,
|
|
145
|
-
seconds: 6,
|
|
146
|
-
sec: 6,
|
|
147
|
-
milliseconds: 7,
|
|
148
|
-
ms: 7,
|
|
149
|
-
tz: 8,
|
|
150
|
-
};
|
|
151
|
-
function setPrecision(d, precision) {
|
|
152
|
-
switch (precision) {
|
|
153
|
-
case 'year': {
|
|
154
|
-
d.setMonth(0, 1);
|
|
155
|
-
d.setHours(0, 0, 0, 0);
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
case 'month': {
|
|
159
|
-
d.setDate(1);
|
|
160
|
-
d.setHours(0, 0, 0, 0);
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
case 'day': {
|
|
164
|
-
d.setHours(0, 0, 0, 0);
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
case 'hours': {
|
|
168
|
-
d.setMinutes(0, 0, 0);
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
case 'minutes': {
|
|
172
|
-
d.setSeconds(0, 0);
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
case 'seconds': {
|
|
176
|
-
d.setMilliseconds(0);
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEnum = isEnum;
|
|
4
|
-
const index_js_1 = require("../../core/index.js");
|
|
5
|
-
/**
|
|
6
|
-
* Validates if given value is one of enum values.
|
|
7
|
-
* @validator isEnum
|
|
8
|
-
*/
|
|
9
|
-
function isEnum(values, options) {
|
|
10
|
-
const caseInSensitive = !!options?.caseInSensitive;
|
|
11
|
-
const enumName = options?.enumName;
|
|
12
|
-
// Prepare an object for fast lookup
|
|
13
|
-
const valObj = (Array.isArray(values) ? values : [values]).reduce((a, v) => {
|
|
14
|
-
if (typeof v === 'string' && caseInSensitive)
|
|
15
|
-
a[v.toUpperCase()] = true;
|
|
16
|
-
else
|
|
17
|
-
a[v] = true;
|
|
18
|
-
return a;
|
|
19
|
-
}, {});
|
|
20
|
-
return (0, index_js_1.validator)('isEnum', (input, context, _this) => {
|
|
21
|
-
if (input != null &&
|
|
22
|
-
valObj[typeof input === 'string' && caseInSensitive
|
|
23
|
-
? input.toUpperCase()
|
|
24
|
-
: input]) {
|
|
25
|
-
return input;
|
|
26
|
-
}
|
|
27
|
-
context.fail(_this, `Value must be one of enumeration member${enumName ? ` (${enumName})` : ''}`, input, {
|
|
28
|
-
enum: enumName,
|
|
29
|
-
});
|
|
30
|
-
}, options);
|
|
31
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isInteger = isInteger;
|
|
4
|
-
const index_js_1 = require("../../core/index.js");
|
|
5
|
-
/**
|
|
6
|
-
* Validates if value is "integer".
|
|
7
|
-
* Converts input value to integer number if coerce option is set to 'true'.
|
|
8
|
-
* @validator isInteger
|
|
9
|
-
*/
|
|
10
|
-
function isInteger(options) {
|
|
11
|
-
return (0, index_js_1.validator)('isInteger', (input, context, _this) => {
|
|
12
|
-
const coerce = options?.coerce ?? context.coerce;
|
|
13
|
-
let output = input;
|
|
14
|
-
if (output != null && typeof output !== 'number' && coerce) {
|
|
15
|
-
if (typeof input === 'string')
|
|
16
|
-
output = parseFloat(input);
|
|
17
|
-
else if (typeof input === 'bigint') {
|
|
18
|
-
output = Number(input);
|
|
19
|
-
if (input === BigInt(output))
|
|
20
|
-
input = output;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (typeof output === 'number' &&
|
|
24
|
-
!isNaN(output) &&
|
|
25
|
-
Number.isInteger(output)) {
|
|
26
|
-
return output;
|
|
27
|
-
}
|
|
28
|
-
context.fail(_this, `Value must be a valid integer value`, input);
|
|
29
|
-
}, options);
|
|
30
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNull = isNull;
|
|
4
|
-
exports.isNotNull = isNotNull;
|
|
5
|
-
exports.isNullish = isNullish;
|
|
6
|
-
exports.isNotNullish = isNotNullish;
|
|
7
|
-
const index_js_1 = require("../../core/index.js");
|
|
8
|
-
/**
|
|
9
|
-
* Validates if value is "null".
|
|
10
|
-
* @validator isNull
|
|
11
|
-
*/
|
|
12
|
-
function isNull(options) {
|
|
13
|
-
return (0, index_js_1.validator)('isNull', (input, context, _this) => {
|
|
14
|
-
if (input === null)
|
|
15
|
-
return input;
|
|
16
|
-
context.fail(_this, `Value must be null`, input);
|
|
17
|
-
}, options);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Validates if value is not "null".
|
|
21
|
-
* @validator isNotNull
|
|
22
|
-
*/
|
|
23
|
-
function isNotNull(options) {
|
|
24
|
-
return (0, index_js_1.validator)('isNotNull', (input, context, _this) => {
|
|
25
|
-
if (input !== null)
|
|
26
|
-
return input;
|
|
27
|
-
context.fail(_this, `{{label}} is null`, input);
|
|
28
|
-
}, options);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Validates if value is "null" or "undefined".
|
|
32
|
-
* @validator isNullish
|
|
33
|
-
*/
|
|
34
|
-
function isNullish(options) {
|
|
35
|
-
return (0, index_js_1.validator)('isNullish', (input, context, _this) => {
|
|
36
|
-
if (input == null)
|
|
37
|
-
return input;
|
|
38
|
-
context.fail(_this, `{{label}} is not nullish`, input);
|
|
39
|
-
}, options);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Validates if value is not "null" nor "undefined".
|
|
43
|
-
* @validator isNotNullish
|
|
44
|
-
*/
|
|
45
|
-
function isNotNullish(options) {
|
|
46
|
-
return (0, index_js_1.validator)('isNotNullish', (input, context, _this) => {
|
|
47
|
-
if (input != null)
|
|
48
|
-
return input;
|
|
49
|
-
if (input === null)
|
|
50
|
-
context.fail(_this, `{{label}} is null`, input);
|
|
51
|
-
else
|
|
52
|
-
context.fail(_this, `{{label}} is undefined`, input);
|
|
53
|
-
}, options);
|
|
54
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNumber = isNumber;
|
|
4
|
-
const index_js_1 = require("../../core/index.js");
|
|
5
|
-
/**
|
|
6
|
-
* Validates if value is "number".
|
|
7
|
-
* Converts input value to number if coerce option is set to 'true'.
|
|
8
|
-
* @validator isNumber
|
|
9
|
-
*/
|
|
10
|
-
function isNumber(options) {
|
|
11
|
-
return (0, index_js_1.validator)('isNumber', (input, context, _this) => {
|
|
12
|
-
const coerce = options?.coerce ?? context.coerce;
|
|
13
|
-
let output = input;
|
|
14
|
-
if (output != null && typeof output !== 'number' && coerce) {
|
|
15
|
-
if (typeof input === 'string')
|
|
16
|
-
output = parseFloat(input);
|
|
17
|
-
else if (typeof input === 'bigint') {
|
|
18
|
-
output = Number(input);
|
|
19
|
-
if (input === BigInt(output))
|
|
20
|
-
return output;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (typeof output === 'number' && !isNaN(output))
|
|
24
|
-
return output;
|
|
25
|
-
context.fail(_this, `Value must be a number`, input);
|
|
26
|
-
}, options);
|
|
27
|
-
}
|