valgen 5.12.0 → 5.13.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/CHANGELOG.md +11 -0
- package/cjs/core/context.js +2 -0
- package/cjs/core/validation-error.js +2 -1
- package/cjs/core/validator.js +12 -6
- package/cjs/rules/format-rules/is-alpha.js +2 -2
- package/cjs/rules/format-rules/is-ascii.js +1 -1
- package/cjs/rules/format-rules/is-base64.js +1 -1
- package/cjs/rules/format-rules/is-btc-address.js +1 -1
- package/cjs/rules/format-rules/is-credit-card.js +1 -1
- package/cjs/rules/format-rules/is-decimal.js +1 -1
- package/cjs/rules/format-rules/is-ean.js +1 -1
- package/cjs/rules/format-rules/is-email.js +1 -10
- package/cjs/rules/format-rules/is-eth-address.js +1 -1
- package/cjs/rules/format-rules/is-fqdn.js +1 -2
- package/cjs/rules/format-rules/is-hash.js +1 -1
- package/cjs/rules/format-rules/is-hex-color.js +1 -1
- package/cjs/rules/format-rules/is-hex.js +1 -1
- package/cjs/rules/format-rules/is-iban.js +2 -2
- package/cjs/rules/format-rules/is-ip.js +2 -2
- package/cjs/rules/format-rules/is-issn.js +1 -2
- package/cjs/rules/format-rules/is-jwt.js +1 -1
- package/cjs/rules/format-rules/is-lowercase.js +2 -2
- package/cjs/rules/format-rules/is-mac-address.js +1 -2
- package/cjs/rules/format-rules/is-mobile-phone.js +1 -1
- package/cjs/rules/format-rules/is-object-id.js +1 -1
- package/cjs/rules/format-rules/is-passport-number.js +1 -1
- package/cjs/rules/format-rules/is-port.js +1 -1
- package/cjs/rules/format-rules/is-url.js +1 -1
- package/cjs/rules/format-rules/is-uuid.js +1 -1
- package/cjs/rules/format-rules/is-vat-number.js +1 -1
- package/cjs/rules/format-rules/matches.js +1 -1
- package/cjs/rules/logical-rules/is-defined.js +1 -1
- package/cjs/rules/logical-rules/is-empty.js +12 -12
- package/cjs/rules/logical-rules/range.js +5 -5
- package/cjs/rules/type-rules/is-array.js +6 -2
- package/cjs/rules/type-rules/is-bigint.js +1 -2
- package/cjs/rules/type-rules/is-boolean.js +1 -2
- package/cjs/rules/type-rules/is-date.js +4 -6
- package/cjs/rules/type-rules/is-integer.js +1 -6
- package/cjs/rules/type-rules/is-null.js +1 -1
- package/cjs/rules/type-rules/is-number.js +1 -6
- package/cjs/rules/type-rules/is-object.js +1 -1
- package/cjs/rules/type-rules/is-record.js +6 -4
- package/cjs/rules/type-rules/is-string.js +1 -1
- package/cjs/rules/type-rules/is-tuple.js +1 -1
- package/cjs/rules/type-rules/is-undefined.js +1 -1
- package/cjs/rules/utility-rules/get-length.js +1 -1
- package/cjs/rules/utility-rules/required.js +1 -1
- package/cjs/tsconfig-build-cjs.tsbuildinfo +1 -1
- package/esm/core/context.js +2 -0
- package/esm/core/validation-error.js +2 -1
- package/esm/core/validator.js +12 -6
- package/esm/rules/format-rules/is-alpha.js +2 -2
- package/esm/rules/format-rules/is-ascii.js +1 -1
- package/esm/rules/format-rules/is-base64.js +1 -1
- package/esm/rules/format-rules/is-btc-address.js +1 -1
- package/esm/rules/format-rules/is-credit-card.js +1 -1
- package/esm/rules/format-rules/is-decimal.js +1 -1
- package/esm/rules/format-rules/is-ean.js +1 -1
- package/esm/rules/format-rules/is-email.js +1 -10
- package/esm/rules/format-rules/is-eth-address.js +1 -1
- package/esm/rules/format-rules/is-fqdn.js +1 -2
- package/esm/rules/format-rules/is-hash.js +1 -1
- package/esm/rules/format-rules/is-hex-color.js +1 -1
- package/esm/rules/format-rules/is-hex.js +1 -1
- package/esm/rules/format-rules/is-iban.js +2 -2
- package/esm/rules/format-rules/is-ip.js +2 -2
- package/esm/rules/format-rules/is-issn.js +1 -2
- package/esm/rules/format-rules/is-jwt.js +1 -1
- package/esm/rules/format-rules/is-lowercase.js +2 -2
- package/esm/rules/format-rules/is-mac-address.js +1 -2
- package/esm/rules/format-rules/is-mobile-phone.js +1 -1
- package/esm/rules/format-rules/is-object-id.js +1 -1
- package/esm/rules/format-rules/is-passport-number.js +1 -1
- package/esm/rules/format-rules/is-port.js +1 -1
- package/esm/rules/format-rules/is-url.js +1 -1
- package/esm/rules/format-rules/is-uuid.js +1 -1
- package/esm/rules/format-rules/is-vat-number.js +1 -1
- package/esm/rules/format-rules/matches.js +1 -1
- package/esm/rules/logical-rules/is-defined.js +1 -1
- package/esm/rules/logical-rules/is-empty.js +12 -12
- package/esm/rules/logical-rules/range.js +5 -5
- package/esm/rules/type-rules/is-array.js +6 -2
- package/esm/rules/type-rules/is-bigint.js +1 -2
- package/esm/rules/type-rules/is-boolean.js +1 -2
- package/esm/rules/type-rules/is-date.js +4 -6
- package/esm/rules/type-rules/is-integer.js +1 -6
- package/esm/rules/type-rules/is-null.js +1 -1
- package/esm/rules/type-rules/is-number.js +1 -6
- package/esm/rules/type-rules/is-object.js +1 -1
- package/esm/rules/type-rules/is-record.js +6 -4
- package/esm/rules/type-rules/is-string.js +1 -1
- package/esm/rules/type-rules/is-tuple.js +1 -1
- package/esm/rules/type-rules/is-undefined.js +1 -1
- package/esm/rules/utility-rules/get-length.js +1 -1
- package/esm/rules/utility-rules/required.js +1 -1
- package/esm/tsconfig-build-esm.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/types/core/context.d.ts +1 -0
- package/types/index.d.cts +1 -1
- package/types/index.d.ts +1 -1
- package/types/rules/format-rules/is-object-id.d.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
# v5.13.0
|
|
2
|
+
[2025-02-03]
|
|
3
|
+
|
|
4
|
+
### Changes
|
|
5
|
+
|
|
6
|
+
* refactor: Updated dependencies ([`dca11c1`](https://github.com/panates/valgen/commit/dca11c1d094daca39974bbc9c70b8f30480c4d0a))
|
|
7
|
+
* refactor: Changed error messages to "positive sentences" ([`3b746df`](https://github.com/panates/valgen/commit/3b746df70ab0e25e32e3f5b957f1c24f3f0fcc70))
|
|
8
|
+
* chore: Updated github workflow ([`661738f`](https://github.com/panates/valgen/commit/661738f1fd90eed72ec2718e67159a8ab614e65e))
|
|
9
|
+
* dev: Fixed ts config ([`e3251ce`](https://github.com/panates/valgen/commit/e3251ce7776de3bd4afeb0c2d0ed5d19f6aabd4f))
|
|
10
|
+
* dev: Added missing script ([`dd019d9`](https://github.com/panates/valgen/commit/dd019d923f8305462e27cad1745564071c9c34bb))
|
|
11
|
+
|
|
1
12
|
# v5.12.0
|
|
2
13
|
[2024-11-04]
|
|
3
14
|
|
package/cjs/core/context.js
CHANGED
|
@@ -7,6 +7,7 @@ const VARIABLE_REPLACE_PATTERN = /{{([^}]*)}}/g;
|
|
|
7
7
|
const OPTIONAL_VAR_PATTERN = /^([^?]+)(?:\||(.*))?$/;
|
|
8
8
|
class Context {
|
|
9
9
|
constructor(options) {
|
|
10
|
+
this.isRoot = true;
|
|
10
11
|
this.errors = [];
|
|
11
12
|
Object.assign(this, options);
|
|
12
13
|
}
|
|
@@ -65,6 +66,7 @@ class Context {
|
|
|
65
66
|
extended[k] = v;
|
|
66
67
|
}
|
|
67
68
|
}
|
|
69
|
+
extended.isRoot = false;
|
|
68
70
|
Object.setPrototypeOf(extended, this);
|
|
69
71
|
return extended;
|
|
70
72
|
}
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ValidationError = void 0;
|
|
4
4
|
class ValidationError extends Error {
|
|
5
5
|
constructor(issues) {
|
|
6
|
-
super(issues[0].message
|
|
6
|
+
super(issues[0].message +
|
|
7
|
+
(issues[0].location ? `\n at ${issues[0].location}` : ''));
|
|
7
8
|
this.issues = [];
|
|
8
9
|
this.issues = issues;
|
|
9
10
|
}
|
package/cjs/core/validator.js
CHANGED
|
@@ -26,11 +26,17 @@ function validator(arg0, arg1, arg2) {
|
|
|
26
26
|
id = id || fn.name || 'validator' + ++unnamedValidatorIndex;
|
|
27
27
|
const name = fn.name || (0, string_utils_js_1.camelCase)(id);
|
|
28
28
|
const _rule = {
|
|
29
|
-
[name](input, options) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
[name](input, options, context) {
|
|
30
|
+
if (context) {
|
|
31
|
+
if (options || validatorOptions)
|
|
32
|
+
context = context.extend({ ...validatorOptions, ...options });
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
context =
|
|
36
|
+
options instanceof context_js_1.Context
|
|
37
|
+
? options.extend({ ...validatorOptions })
|
|
38
|
+
: new context_js_1.Context({ ...validatorOptions, ...options });
|
|
39
|
+
}
|
|
34
40
|
let value;
|
|
35
41
|
try {
|
|
36
42
|
value = fn(input, context, _rule);
|
|
@@ -40,7 +46,7 @@ function validator(arg0, arg1, arg2) {
|
|
|
40
46
|
throw e;
|
|
41
47
|
context.fail(_rule, e, input);
|
|
42
48
|
}
|
|
43
|
-
if (
|
|
49
|
+
if (context.isRoot && context.errors.length) {
|
|
44
50
|
throw new validation_error_js_1.ValidationError(context.errors);
|
|
45
51
|
}
|
|
46
52
|
return value;
|
|
@@ -13,7 +13,7 @@ function isAlpha(options) {
|
|
|
13
13
|
return (0, index_js_1.validator)('isLowercase', (input, context, _this) => {
|
|
14
14
|
if (typeof input === 'string' && validator_1.default.isAlpha(input))
|
|
15
15
|
return input;
|
|
16
|
-
context.fail(_this, `"
|
|
16
|
+
context.fail(_this, `"Value must be an alpha string`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -25,6 +25,6 @@ function isAlphanumeric(options) {
|
|
|
25
25
|
if (typeof input === 'string' && validator_1.default.isAlphanumeric(input)) {
|
|
26
26
|
return input;
|
|
27
27
|
}
|
|
28
|
-
context.fail(_this, `"
|
|
28
|
+
context.fail(_this, `"Value must be an alphanumeric string`, input);
|
|
29
29
|
}, options);
|
|
30
30
|
}
|
|
@@ -12,6 +12,6 @@ function isAscii(options) {
|
|
|
12
12
|
return (0, index_js_1.validator)('isAscii', (input, context, _this) => {
|
|
13
13
|
if (typeof input === 'string' && validator_1.default.isAscii(input))
|
|
14
14
|
return input;
|
|
15
|
-
context.fail(_this, `Value
|
|
15
|
+
context.fail(_this, `Value must be an ascii string`, input);
|
|
16
16
|
}, options);
|
|
17
17
|
}
|
|
@@ -13,6 +13,6 @@ function isBase64(options) {
|
|
|
13
13
|
if (typeof input === 'string' && validator_1.default.isBase64(input, options)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `"
|
|
16
|
+
context.fail(_this, `"Value must be a Base64 string`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -13,6 +13,6 @@ function isBtcAddress(options) {
|
|
|
13
13
|
if (typeof input === 'string' && validator_1.default.isBtcAddress(input)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `Value
|
|
16
|
+
context.fail(_this, `Value must be a valid BTC address`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -14,6 +14,6 @@ function isCreditCard(options) {
|
|
|
14
14
|
validator_1.default.isCreditCard(input, options)) {
|
|
15
15
|
return input;
|
|
16
16
|
}
|
|
17
|
-
context.fail(_this, `
|
|
17
|
+
context.fail(_this, `Value must be a valid Credit Card number`, input);
|
|
18
18
|
}, options);
|
|
19
19
|
}
|
|
@@ -14,6 +14,6 @@ function isDecimal(options) {
|
|
|
14
14
|
if (typeof input === 'string' && validator_1.default.isDecimal(input)) {
|
|
15
15
|
return input;
|
|
16
16
|
}
|
|
17
|
-
context.fail(_this, `
|
|
17
|
+
context.fail(_this, `Value must be a decimal number string`, input);
|
|
18
18
|
}, options);
|
|
19
19
|
}
|
|
@@ -12,6 +12,6 @@ function isEAN(options) {
|
|
|
12
12
|
return (0, index_js_1.validator)('isEAN', (input, context, _this) => {
|
|
13
13
|
if (typeof input === 'string' && validator_1.default.isEAN(input))
|
|
14
14
|
return input;
|
|
15
|
-
context.fail(_this, `
|
|
15
|
+
context.fail(_this, `Value must be a valid EAN (European Article Number)`, input);
|
|
16
16
|
}, options);
|
|
17
17
|
}
|
|
@@ -10,13 +10,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isEmail(options) {
|
|
12
12
|
const emailOptions = {
|
|
13
|
-
// eslint-disable-next-line camelcase
|
|
14
13
|
allow_display_name: true,
|
|
15
|
-
// eslint-disable-next-line camelcase
|
|
16
14
|
allow_utf8_local_part: options?.utf8LocalPart,
|
|
17
|
-
// eslint-disable-next-line camelcase
|
|
18
15
|
ignore_max_length: true,
|
|
19
|
-
// eslint-disable-next-line camelcase
|
|
20
16
|
allow_ip_domain: options?.allowIpDomain,
|
|
21
17
|
};
|
|
22
18
|
return (0, index_js_1.validator)('isEmail', (input, context, _this) => {
|
|
@@ -25,7 +21,6 @@ function isEmail(options) {
|
|
|
25
21
|
if (options?.requireDisplayName) {
|
|
26
22
|
if (!validator_1.default.isEmail(input, {
|
|
27
23
|
...emailOptions,
|
|
28
|
-
// eslint-disable-next-line camelcase
|
|
29
24
|
require_display_name: true,
|
|
30
25
|
})) {
|
|
31
26
|
context.fail(_this, `Display name for the email is required. Etc. ( Name <me@tempuri.org> ) `, input);
|
|
@@ -35,7 +30,6 @@ function isEmail(options) {
|
|
|
35
30
|
else if (!options?.allowDisplayName &&
|
|
36
31
|
!validator_1.default.isEmail(input, {
|
|
37
32
|
...emailOptions,
|
|
38
|
-
// eslint-disable-next-line camelcase
|
|
39
33
|
allow_display_name: false,
|
|
40
34
|
})) {
|
|
41
35
|
context.fail(_this, `Display name in email is not allowed`, input);
|
|
@@ -44,7 +38,6 @@ function isEmail(options) {
|
|
|
44
38
|
if (options?.hostBlacklist &&
|
|
45
39
|
!validator_1.default.isEmail(input, {
|
|
46
40
|
...emailOptions,
|
|
47
|
-
// eslint-disable-next-line camelcase
|
|
48
41
|
host_blacklist: options.hostBlacklist,
|
|
49
42
|
})) {
|
|
50
43
|
context.fail(_this, `Email "{{value}}" is in black-list`, input);
|
|
@@ -53,7 +46,6 @@ function isEmail(options) {
|
|
|
53
46
|
if (options?.hostWhitelist &&
|
|
54
47
|
!validator_1.default.isEmail(input, {
|
|
55
48
|
...emailOptions,
|
|
56
|
-
// eslint-disable-next-line camelcase
|
|
57
49
|
host_whitelist: options.hostWhitelist,
|
|
58
50
|
})) {
|
|
59
51
|
context.fail(_this, `Email "{{value}}" is in not white-list`, input);
|
|
@@ -62,7 +54,6 @@ function isEmail(options) {
|
|
|
62
54
|
if (options?.blacklistedChars &&
|
|
63
55
|
!validator_1.default.isEmail(input, {
|
|
64
56
|
...emailOptions,
|
|
65
|
-
// eslint-disable-next-line camelcase
|
|
66
57
|
blacklisted_chars: options.blacklistedChars,
|
|
67
58
|
})) {
|
|
68
59
|
context.fail(_this, `Black listed characters (${options.blacklistedChars}) found in name part`, input);
|
|
@@ -70,6 +61,6 @@ function isEmail(options) {
|
|
|
70
61
|
}
|
|
71
62
|
return input;
|
|
72
63
|
}
|
|
73
|
-
context.fail(_this, `
|
|
64
|
+
context.fail(_this, `Value must much required e-mail format`, input);
|
|
74
65
|
}, options);
|
|
75
66
|
}
|
|
@@ -13,6 +13,6 @@ function isETHAddress(options) {
|
|
|
13
13
|
if (typeof input === 'string' && validator_1.default.isEthereumAddress(input)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `Value
|
|
16
|
+
context.fail(_this, `Value must be valid ETH (Ethereum) address`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -10,13 +10,12 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isFQDN(options) {
|
|
12
12
|
const opts = {
|
|
13
|
-
// eslint-disable-next-line camelcase
|
|
14
13
|
allow_wildcard: options?.allowWildcard,
|
|
15
14
|
};
|
|
16
15
|
return (0, index_js_1.validator)('isFQDN', (input, context, _this) => {
|
|
17
16
|
if (typeof input === 'string' && validator_1.default.isFQDN(input, opts)) {
|
|
18
17
|
return input;
|
|
19
18
|
}
|
|
20
|
-
context.fail(_this, `
|
|
19
|
+
context.fail(_this, `Value must be valid FQDN`, input);
|
|
21
20
|
}, options);
|
|
22
21
|
}
|
|
@@ -13,6 +13,6 @@ function isHash(algorithm, options) {
|
|
|
13
13
|
if (typeof input === 'string' && validator_1.default.isHash(input, algorithm)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `Value
|
|
16
|
+
context.fail(_this, `Value must be a valid ${algorithm} hash`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -13,6 +13,6 @@ function isHexColor(options) {
|
|
|
13
13
|
if (typeof input === 'string' && validator_1.default.isHexColor(input)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `
|
|
16
|
+
context.fail(_this, `Value must be a valid Hex Color`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -13,6 +13,6 @@ function isHex(options) {
|
|
|
13
13
|
if (typeof input === 'string' && validator_1.default.isHexadecimal(input)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `
|
|
16
|
+
context.fail(_this, `Value must be an hexadecimal string`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -13,7 +13,7 @@ function isIBAN(options) {
|
|
|
13
13
|
return (0, index_js_1.validator)('isIBAN', (input, context, _this) => {
|
|
14
14
|
if (typeof input === 'string' && validator_1.default.isIBAN(input))
|
|
15
15
|
return input;
|
|
16
|
-
context.fail(_this, `
|
|
16
|
+
context.fail(_this, `Value must be a valid IBAN (International Bank Account Number)`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -24,6 +24,6 @@ function isSWIFT(options) {
|
|
|
24
24
|
return (0, index_js_1.validator)('isSWIFT', (input, context, _this) => {
|
|
25
25
|
if (typeof input === 'string' && validator_1.default.isBIC(input))
|
|
26
26
|
return input;
|
|
27
|
-
context.fail(_this, `
|
|
27
|
+
context.fail(_this, `Value must be a valid a BIC (Bank Identification Code) or SWIFT code`, input);
|
|
28
28
|
}, options);
|
|
29
29
|
}
|
|
@@ -16,7 +16,7 @@ function isIP(version, options) {
|
|
|
16
16
|
validator_1.default.isIP(input, version)) {
|
|
17
17
|
return input;
|
|
18
18
|
}
|
|
19
|
-
context.fail(_this, `
|
|
19
|
+
context.fail(_this, `Value must be a valid IP${version ? ' v' + version : ''}`, input);
|
|
20
20
|
}, options);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
@@ -30,6 +30,6 @@ function isIPRange(version, options) {
|
|
|
30
30
|
validator_1.default.isIPRange(input, version)) {
|
|
31
31
|
return input;
|
|
32
32
|
}
|
|
33
|
-
context.fail(_this, `
|
|
33
|
+
context.fail(_this, `Value must be a valid IP${version ? ' v' + version : ''} range`, input);
|
|
34
34
|
}, options);
|
|
35
35
|
}
|
|
@@ -10,13 +10,12 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isISSN(options) {
|
|
12
12
|
const opts = {
|
|
13
|
-
// eslint-disable-next-line camelcase
|
|
14
13
|
case_sensitive: options?.caseSensitive,
|
|
15
14
|
};
|
|
16
15
|
return (0, index_js_1.validator)('isISSN', (input, context, _this) => {
|
|
17
16
|
if (typeof input === 'string' && validator_1.default.isISSN(input, opts)) {
|
|
18
17
|
return input;
|
|
19
18
|
}
|
|
20
|
-
context.fail(_this, `
|
|
19
|
+
context.fail(_this, `Value must be a valid ISSN`, input);
|
|
21
20
|
}, options);
|
|
22
21
|
}
|
|
@@ -12,6 +12,6 @@ function isJWT(options) {
|
|
|
12
12
|
return (0, index_js_1.validator)('isJWT', (input, context, _this) => {
|
|
13
13
|
if (typeof input === 'string' && validator_1.default.isJWT(input))
|
|
14
14
|
return input;
|
|
15
|
-
context.fail(_this, `Value
|
|
15
|
+
context.fail(_this, `Value must be valid JWT token`, input);
|
|
16
16
|
}, options);
|
|
17
17
|
}
|
|
@@ -14,7 +14,7 @@ function isLowercase(options) {
|
|
|
14
14
|
if (typeof input === 'string' && validator_1.default.isLowercase(input)) {
|
|
15
15
|
return input;
|
|
16
16
|
}
|
|
17
|
-
context.fail(_this, `
|
|
17
|
+
context.fail(_this, `Value must be a lowercase string`, input);
|
|
18
18
|
}, options);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -26,6 +26,6 @@ function isUppercase(options) {
|
|
|
26
26
|
if (typeof input === 'string' && validator_1.default.isUppercase(input)) {
|
|
27
27
|
return input;
|
|
28
28
|
}
|
|
29
|
-
context.fail(_this, `
|
|
29
|
+
context.fail(_this, `Value must be an uppercase string`, input);
|
|
30
30
|
}, options);
|
|
31
31
|
}
|
|
@@ -10,7 +10,6 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isMACAddress(options) {
|
|
12
12
|
const opts = {
|
|
13
|
-
// eslint-disable-next-line camelcase
|
|
14
13
|
no_separators: options?.noSeparators,
|
|
15
14
|
eui: options?.eui,
|
|
16
15
|
};
|
|
@@ -20,6 +19,6 @@ function isMACAddress(options) {
|
|
|
20
19
|
validator_1.default.isMACAddress(input, opts)) {
|
|
21
20
|
return input;
|
|
22
21
|
}
|
|
23
|
-
context.fail(_this, `
|
|
22
|
+
context.fail(_this, `Value must be a valid MAC address`, input);
|
|
24
23
|
}, options);
|
|
25
24
|
}
|
|
@@ -17,6 +17,6 @@ function isMobilePhone(options) {
|
|
|
17
17
|
validator_1.default.isMobilePhone(input, options?.locale, opts)) {
|
|
18
18
|
return input;
|
|
19
19
|
}
|
|
20
|
-
context.fail(_this, `
|
|
20
|
+
context.fail(_this, `Value must be a valid a Mobile Phone Number`, input);
|
|
21
21
|
}, options);
|
|
22
22
|
}
|
|
@@ -17,7 +17,7 @@ function isObjectId(options) {
|
|
|
17
17
|
_isObjectIdValue(input.toHexString())))) {
|
|
18
18
|
return input;
|
|
19
19
|
}
|
|
20
|
-
context.fail(_this, `
|
|
20
|
+
context.fail(_this, `Value must be a valid ObjectId`, input);
|
|
21
21
|
}, options);
|
|
22
22
|
}
|
|
23
23
|
function _isObjectIdValue(input) {
|
|
@@ -14,6 +14,6 @@ function isPassportNumber(countryCode, options) {
|
|
|
14
14
|
validator_1.default.isPassportNumber(input, countryCode)) {
|
|
15
15
|
return input;
|
|
16
16
|
}
|
|
17
|
-
context.fail(_this, `
|
|
17
|
+
context.fail(_this, `Value must be a valid ${countryCode} PassportNumber)`, input);
|
|
18
18
|
}, options);
|
|
19
19
|
}
|
|
@@ -15,6 +15,6 @@ function isUUID(version, options) {
|
|
|
15
15
|
validator_1.default.isUUID(input, version)) {
|
|
16
16
|
return input;
|
|
17
17
|
}
|
|
18
|
-
context.fail(_this, `
|
|
18
|
+
context.fail(_this, `Value must be a valid UUID${version ? ' v' + version : ''}`, input);
|
|
19
19
|
}, options);
|
|
20
20
|
}
|
|
@@ -13,6 +13,6 @@ function isVATNumber(countryCode, options) {
|
|
|
13
13
|
if (typeof input === 'string' && validator_1.default.isVAT(input, countryCode)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `
|
|
16
|
+
context.fail(_this, `Value must be a valid VAT number`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -14,7 +14,7 @@ function matches(format, options) {
|
|
|
14
14
|
return;
|
|
15
15
|
if (typeof input === 'string' && regExp.test(input))
|
|
16
16
|
return input;
|
|
17
|
-
context.fail(_this, `
|
|
17
|
+
context.fail(_this, `Value must match ${formatName || 'requested'} format`, input, {
|
|
18
18
|
format,
|
|
19
19
|
formatName,
|
|
20
20
|
});
|
|
@@ -10,6 +10,6 @@ function isDefined(options) {
|
|
|
10
10
|
return (0, index_js_1.validator)('is-defined', (input, context, _this) => {
|
|
11
11
|
if (input !== undefined)
|
|
12
12
|
return input;
|
|
13
|
-
context.fail(_this, `
|
|
13
|
+
context.fail(_this, `Value must be defined`, input);
|
|
14
14
|
}, options);
|
|
15
15
|
}
|
|
@@ -14,29 +14,29 @@ function isEmpty(options) {
|
|
|
14
14
|
if (typeof input === 'string') {
|
|
15
15
|
if (!input)
|
|
16
16
|
return input;
|
|
17
|
-
context.fail(_this, `
|
|
17
|
+
context.fail(_this, `Value must be an empty string`, input);
|
|
18
18
|
}
|
|
19
19
|
else if (Array.isArray(input)) {
|
|
20
20
|
if (!input.length)
|
|
21
21
|
return input;
|
|
22
|
-
context.fail(_this, `
|
|
22
|
+
context.fail(_this, `Value must be an empty array`, input);
|
|
23
23
|
}
|
|
24
24
|
else if (input instanceof Set) {
|
|
25
25
|
if (!input.size)
|
|
26
26
|
return input;
|
|
27
|
-
context.fail(_this, `
|
|
27
|
+
context.fail(_this, `Value must be an empty Set`, input);
|
|
28
28
|
}
|
|
29
29
|
else if (input instanceof Map) {
|
|
30
30
|
if (!input.size)
|
|
31
31
|
return input;
|
|
32
|
-
context.fail(_this, `
|
|
32
|
+
context.fail(_this, `Value must be an empty Map`, input);
|
|
33
33
|
}
|
|
34
34
|
else if (typeof input === 'object') {
|
|
35
35
|
if (!Object.keys(input).length)
|
|
36
36
|
return input;
|
|
37
|
-
context.fail(_this, `
|
|
37
|
+
context.fail(_this, `Value must be an empty Object`, input);
|
|
38
38
|
}
|
|
39
|
-
context.fail(_this, `
|
|
39
|
+
context.fail(_this, `Value must be empty`, input);
|
|
40
40
|
}, options);
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
@@ -49,29 +49,29 @@ function isNotEmpty(options) {
|
|
|
49
49
|
if (typeof input === 'string') {
|
|
50
50
|
if (input)
|
|
51
51
|
return input;
|
|
52
|
-
context.fail(_this, `Value
|
|
52
|
+
context.fail(_this, `Value must not be empty`, input);
|
|
53
53
|
}
|
|
54
54
|
else if (Array.isArray(input)) {
|
|
55
55
|
if (input.length)
|
|
56
56
|
return input;
|
|
57
|
-
context.fail(_this, `
|
|
57
|
+
context.fail(_this, `Array must not be empty`, input);
|
|
58
58
|
}
|
|
59
59
|
else if (input instanceof Set) {
|
|
60
60
|
if (input.size)
|
|
61
61
|
return input;
|
|
62
|
-
context.fail(_this, `
|
|
62
|
+
context.fail(_this, `Set must not be empty`, input);
|
|
63
63
|
}
|
|
64
64
|
else if (input instanceof Map) {
|
|
65
65
|
if (input.size)
|
|
66
66
|
return input;
|
|
67
|
-
context.fail(_this, `
|
|
67
|
+
context.fail(_this, `Map must not be empty`, input);
|
|
68
68
|
}
|
|
69
69
|
else if (typeof input === 'object') {
|
|
70
70
|
if (Object.keys(input).length)
|
|
71
71
|
return input;
|
|
72
|
-
context.fail(_this, `
|
|
72
|
+
context.fail(_this, `Object must not be empty`, input);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
context.fail(_this, `Value
|
|
75
|
+
context.fail(_this, `Value must not be empty`, input);
|
|
76
76
|
}, options);
|
|
77
77
|
}
|
|
@@ -58,7 +58,7 @@ function isGt(minValue, options) {
|
|
|
58
58
|
input.toLowerCase() > minValue.toLowerCase()))) {
|
|
59
59
|
return input;
|
|
60
60
|
}
|
|
61
|
-
context.fail(_this, `
|
|
61
|
+
context.fail(_this, `Value must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
62
62
|
}, options);
|
|
63
63
|
}
|
|
64
64
|
function isGte(minValue, options) {
|
|
@@ -80,7 +80,7 @@ function isGte(minValue, options) {
|
|
|
80
80
|
input.toLowerCase() >= minValue.toLowerCase()))) {
|
|
81
81
|
return input;
|
|
82
82
|
}
|
|
83
|
-
context.fail(_this, `
|
|
83
|
+
context.fail(_this, `Value must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
84
84
|
}, options);
|
|
85
85
|
}
|
|
86
86
|
function isLt(maxValue, options) {
|
|
@@ -102,7 +102,7 @@ function isLt(maxValue, options) {
|
|
|
102
102
|
input.toLowerCase() < maxValue.toLowerCase()))) {
|
|
103
103
|
return input;
|
|
104
104
|
}
|
|
105
|
-
context.fail(_this, `
|
|
105
|
+
context.fail(_this, `Value must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
|
|
106
106
|
}, options);
|
|
107
107
|
}
|
|
108
108
|
function isLte(maxValue, options) {
|
|
@@ -124,7 +124,7 @@ function isLte(maxValue, options) {
|
|
|
124
124
|
input.toLowerCase() <= maxValue.toLowerCase()))) {
|
|
125
125
|
return input;
|
|
126
126
|
}
|
|
127
|
-
context.fail(_this, `
|
|
127
|
+
context.fail(_this, `Value must be lover than or equal to ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
|
|
128
128
|
}, options);
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
@@ -135,7 +135,7 @@ const lengthMin = (minValue) => (0, pipe_js_1.allOf)([
|
|
|
135
135
|
(0, pipe_js_1.pipe)([
|
|
136
136
|
(0, get_length_js_1.getLength)(),
|
|
137
137
|
isGte(minValue, {
|
|
138
|
-
onFail: () => `
|
|
138
|
+
onFail: () => `Value length must be at least ${minValue}`,
|
|
139
139
|
}),
|
|
140
140
|
]),
|
|
141
141
|
]);
|
|
@@ -14,7 +14,7 @@ function isArray(itemValidator, options) {
|
|
|
14
14
|
if (output != null && coerce && !Array.isArray(output))
|
|
15
15
|
output = [output];
|
|
16
16
|
if (!Array.isArray(output)) {
|
|
17
|
-
context.fail(_this, `
|
|
17
|
+
context.fail(_this, `Value must be an array`, input);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
if (!itemValidator)
|
|
@@ -33,7 +33,11 @@ function isArray(itemValidator, options) {
|
|
|
33
33
|
? context.location + `[${i}]`
|
|
34
34
|
: `<Array>[${i}]`;
|
|
35
35
|
itemContext.index = i;
|
|
36
|
-
v = itemValidator(v,
|
|
36
|
+
v = itemValidator(v, {
|
|
37
|
+
onFail(issue) {
|
|
38
|
+
return `Item at index [${i}] is not a valid. ` + issue.message;
|
|
39
|
+
},
|
|
40
|
+
}, itemContext);
|
|
37
41
|
out.push(v);
|
|
38
42
|
}
|
|
39
43
|
return out;
|
|
@@ -16,7 +16,6 @@ function isBigint(options) {
|
|
|
16
16
|
(typeof input === 'string' && coerce)) {
|
|
17
17
|
return BigInt(input);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
context.fail(_this, `${t}"{{value}}" is not a valid BigInt value`, input);
|
|
19
|
+
context.fail(_this, `Value must be a BigInt`, input);
|
|
21
20
|
}, options);
|
|
22
21
|
}
|
|
@@ -26,7 +26,6 @@ function isBoolean(options) {
|
|
|
26
26
|
}
|
|
27
27
|
if (typeof output === 'boolean')
|
|
28
28
|
return output;
|
|
29
|
-
|
|
30
|
-
context.fail(_this, `${t}"{{value}}" is not a valid boolean value`, input);
|
|
29
|
+
context.fail(_this, `Value must be a boolean`, input);
|
|
31
30
|
}, options);
|
|
32
31
|
}
|
|
@@ -4,10 +4,8 @@ exports.isDate = isDate;
|
|
|
4
4
|
exports.isDateString = isDateString;
|
|
5
5
|
const date_fns_1 = require("date-fns");
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
|
-
|
|
8
|
-
const DATE_PATTERN =
|
|
9
|
-
// eslint-disable-next-line max-len
|
|
10
|
-
/^(\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,3}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
|
|
7
|
+
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
8
|
+
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,3}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
|
|
11
9
|
/**
|
|
12
10
|
* Validates if value is instance of "Date".
|
|
13
11
|
* Converts input value to Date if coerce option is set to 'true'.
|
|
@@ -40,7 +38,7 @@ function isDate(options) {
|
|
|
40
38
|
d.setHours(0, 0, 0, 0);
|
|
41
39
|
return d;
|
|
42
40
|
}
|
|
43
|
-
context.fail(_this, `
|
|
41
|
+
context.fail(_this, `Value must be a valid date`, input, {
|
|
44
42
|
...options,
|
|
45
43
|
});
|
|
46
44
|
}, options);
|
|
@@ -93,7 +91,7 @@ function isDateString(options) {
|
|
|
93
91
|
? (0, date_fns_1.formatISO)(input, { representation: 'date' })
|
|
94
92
|
: (0, date_fns_1.formatISO)(input).substring(0, 19);
|
|
95
93
|
}
|
|
96
|
-
context.fail(_this, `
|
|
94
|
+
context.fail(_this, `Value must be a valid date string`, input, {
|
|
97
95
|
...options,
|
|
98
96
|
});
|
|
99
97
|
}, options);
|