valgen 5.10.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 +25 -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 +5 -5
- package/cjs/rules/format-rules/is-ascii.js +3 -3
- package/cjs/rules/format-rules/is-base64.js +3 -3
- package/cjs/rules/format-rules/is-btc-address.js +3 -3
- package/cjs/rules/format-rules/is-credit-card.js +3 -3
- package/cjs/rules/format-rules/is-decimal.js +3 -3
- package/cjs/rules/format-rules/is-ean.js +3 -3
- package/cjs/rules/format-rules/is-email.js +8 -17
- package/cjs/rules/format-rules/is-eth-address.js +3 -3
- package/cjs/rules/format-rules/is-fqdn.js +3 -4
- package/cjs/rules/format-rules/is-hash.js +3 -3
- package/cjs/rules/format-rules/is-hex-color.js +3 -3
- package/cjs/rules/format-rules/is-hex.js +3 -3
- package/cjs/rules/format-rules/is-iban.js +5 -5
- package/cjs/rules/format-rules/is-ip.js +5 -5
- package/cjs/rules/format-rules/is-issn.js +3 -4
- package/cjs/rules/format-rules/is-jwt.js +3 -3
- package/cjs/rules/format-rules/is-lowercase.js +5 -5
- package/cjs/rules/format-rules/is-mac-address.js +3 -4
- package/cjs/rules/format-rules/is-mobile-phone.js +3 -3
- package/cjs/rules/format-rules/is-object-id.js +2 -2
- package/cjs/rules/format-rules/is-passport-number.js +3 -3
- package/cjs/rules/format-rules/is-port.js +6 -4
- package/cjs/rules/format-rules/is-url.js +3 -3
- package/cjs/rules/format-rules/is-uuid.js +3 -3
- package/cjs/rules/format-rules/is-vat-number.js +3 -3
- 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 +3 -3
- package/esm/rules/format-rules/is-ascii.js +2 -2
- package/esm/rules/format-rules/is-base64.js +2 -2
- package/esm/rules/format-rules/is-btc-address.js +2 -2
- package/esm/rules/format-rules/is-credit-card.js +2 -2
- package/esm/rules/format-rules/is-decimal.js +2 -2
- package/esm/rules/format-rules/is-ean.js +2 -2
- package/esm/rules/format-rules/is-email.js +2 -11
- package/esm/rules/format-rules/is-eth-address.js +2 -2
- package/esm/rules/format-rules/is-fqdn.js +2 -3
- package/esm/rules/format-rules/is-hash.js +2 -2
- package/esm/rules/format-rules/is-hex-color.js +2 -2
- package/esm/rules/format-rules/is-hex.js +2 -2
- package/esm/rules/format-rules/is-iban.js +3 -3
- package/esm/rules/format-rules/is-ip.js +3 -3
- package/esm/rules/format-rules/is-issn.js +2 -3
- package/esm/rules/format-rules/is-jwt.js +2 -2
- package/esm/rules/format-rules/is-lowercase.js +3 -3
- package/esm/rules/format-rules/is-mac-address.js +2 -3
- package/esm/rules/format-rules/is-mobile-phone.js +2 -2
- package/esm/rules/format-rules/is-object-id.js +2 -2
- package/esm/rules/format-rules/is-passport-number.js +2 -2
- package/esm/rules/format-rules/is-port.js +5 -3
- package/esm/rules/format-rules/is-url.js +2 -2
- package/esm/rules/format-rules/is-uuid.js +2 -2
- package/esm/rules/format-rules/is-vat-number.js +2 -2
- 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 +5 -5
- package/types/core/context.d.ts +1 -0
- package/types/index.d.cts +2 -2
- package/types/index.d.ts +2 -2
- package/types/rules/format-rules/is-base64.d.ts +1 -1
- package/types/rules/format-rules/is-credit-card.d.ts +1 -1
- package/types/rules/format-rules/is-hash.d.ts +1 -1
- package/types/rules/format-rules/is-mobile-phone.d.ts +1 -1
- package/types/rules/format-rules/is-object-id.d.ts +1 -1
- package/types/rules/format-rules/is-port.d.ts +1 -1
- package/types/rules/format-rules/is-url.d.ts +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isObjectId = isObjectId;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const validator_1 = tslib_1.__importDefault(require("validator"));
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is an "ObjectId".
|
|
@@ -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) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isPassportNumber = isPassportNumber;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is a passport number
|
|
@@ -11,9 +11,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
11
11
|
function isPassportNumber(countryCode, options) {
|
|
12
12
|
return (0, index_js_1.validator)('isPassportNumber', (input, context, _this) => {
|
|
13
13
|
if (typeof input === 'string' &&
|
|
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
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isPort = isPort;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is a port number
|
|
@@ -10,11 +10,13 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isPort(options) {
|
|
12
12
|
return (0, index_js_1.validator)('isPort', (input, context, _this) => {
|
|
13
|
+
if (typeof input === 'number')
|
|
14
|
+
input = String(input);
|
|
13
15
|
if (input != null &&
|
|
14
16
|
typeof input === 'string' &&
|
|
15
|
-
|
|
16
|
-
return input;
|
|
17
|
+
validator_1.default.isPort(input)) {
|
|
18
|
+
return parseInt(input, 10);
|
|
17
19
|
}
|
|
18
|
-
context.fail(_this, `
|
|
20
|
+
context.fail(_this, `Value must be a valid port number`, input);
|
|
19
21
|
}, options);
|
|
20
22
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isURL = isURL;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is an URL
|
|
@@ -12,9 +12,9 @@ function isURL(options) {
|
|
|
12
12
|
return (0, index_js_1.validator)('isURL', (input, context, _this) => {
|
|
13
13
|
if (input != null &&
|
|
14
14
|
typeof input === 'string' &&
|
|
15
|
-
|
|
15
|
+
validator_1.default.isURL(input, options)) {
|
|
16
16
|
return input;
|
|
17
17
|
}
|
|
18
|
-
context.fail(_this, `
|
|
18
|
+
context.fail(_this, `Value must be a valid URL`, input);
|
|
19
19
|
}, options);
|
|
20
20
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isUUID = isUUID;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is an "UUID".
|
|
@@ -12,9 +12,9 @@ function isUUID(version, options) {
|
|
|
12
12
|
return (0, index_js_1.validator)('isUUID', (input, context, _this) => {
|
|
13
13
|
if (input != null &&
|
|
14
14
|
typeof input === 'string' &&
|
|
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
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isVATNumber = isVATNumber;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is an VAT number
|
|
@@ -10,9 +10,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isVATNumber(countryCode, options) {
|
|
12
12
|
return (0, index_js_1.validator)('isVATNumber', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' &&
|
|
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);
|
|
@@ -25,11 +25,6 @@ function isInteger(options) {
|
|
|
25
25
|
Number.isInteger(output)) {
|
|
26
26
|
return output;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
? 'BigInt '
|
|
30
|
-
: typeof input === 'string'
|
|
31
|
-
? 'String '
|
|
32
|
-
: '';
|
|
33
|
-
context.fail(_this, `${t}"{{value}}" is not a valid integer value`, input);
|
|
28
|
+
context.fail(_this, `Value must be a valid integer value`, input);
|
|
34
29
|
}, options);
|
|
35
30
|
}
|
|
@@ -13,7 +13,7 @@ function isNull(options) {
|
|
|
13
13
|
return (0, index_js_1.validator)('isNull', (input, context, _this) => {
|
|
14
14
|
if (input === null)
|
|
15
15
|
return input;
|
|
16
|
-
context.fail(_this, `
|
|
16
|
+
context.fail(_this, `Value must be null`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -22,11 +22,6 @@ function isNumber(options) {
|
|
|
22
22
|
}
|
|
23
23
|
if (typeof output === 'number' && !isNaN(output))
|
|
24
24
|
return output;
|
|
25
|
-
|
|
26
|
-
? 'BigInt '
|
|
27
|
-
: typeof input === 'string'
|
|
28
|
-
? 'String '
|
|
29
|
-
: '';
|
|
30
|
-
context.fail(_this, `${t}"{{value}}" is not a valid number value`, input);
|
|
25
|
+
context.fail(_this, `Value must be a number`, input);
|
|
31
26
|
}, options);
|
|
32
27
|
}
|
|
@@ -45,7 +45,7 @@ function isObject(schema, options) {
|
|
|
45
45
|
if (typeof output === 'string' && coerce)
|
|
46
46
|
output = JSON.parse(output);
|
|
47
47
|
if (!(output && typeof output === 'object')) {
|
|
48
|
-
context.fail(_this, `
|
|
48
|
+
context.fail(_this, `Value must be an object`, input);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
const keys = [...Object.keys(output), ...schemaKeys];
|
|
@@ -10,7 +10,7 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
function isRecord(keyRule, valueRule, options) {
|
|
11
11
|
return (0, index_js_1.validator)('isRecord', (input, context, _this) => {
|
|
12
12
|
if (!(input && typeof input === 'object')) {
|
|
13
|
-
context.fail(_this, `
|
|
13
|
+
context.fail(_this, `Value must be an object`, input);
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
const keyContext = context.extend();
|
|
@@ -26,9 +26,11 @@ function isRecord(keyRule, valueRule, options) {
|
|
|
26
26
|
k = keys[i];
|
|
27
27
|
v = input[k];
|
|
28
28
|
// Validate key
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
k = keyRule(k, {
|
|
30
|
+
onFail(issue) {
|
|
31
|
+
return `${k} is not a valid key. ` + issue.message;
|
|
32
|
+
},
|
|
33
|
+
}, keyContext);
|
|
32
34
|
// Validate value
|
|
33
35
|
valueContext.property = k;
|
|
34
36
|
valueContext.location = location + (location ? '.' : '') + k;
|
|
@@ -27,7 +27,7 @@ function isString(options) {
|
|
|
27
27
|
}
|
|
28
28
|
if (typeof output === 'string')
|
|
29
29
|
return output;
|
|
30
|
-
context.fail(_this, `
|
|
30
|
+
context.fail(_this, `Value must be a string`, input);
|
|
31
31
|
}, options);
|
|
32
32
|
}
|
|
33
33
|
function stringReplace(searchValue, replacer) {
|
|
@@ -9,7 +9,7 @@ function isTuple(items, options) {
|
|
|
9
9
|
if (output != null && coerce && !Array.isArray(output))
|
|
10
10
|
output = [output];
|
|
11
11
|
if (!Array.isArray(input)) {
|
|
12
|
-
context.fail(_this, `
|
|
12
|
+
context.fail(_this, `Value must be a tuple`, input);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
const location = context.location || '';
|
|
@@ -9,7 +9,7 @@ const index_js_1 = require("../../core/index.js");
|
|
|
9
9
|
function required(nested, options) {
|
|
10
10
|
return (0, index_js_1.validator)('required', (input, context, _this) => {
|
|
11
11
|
if (input == null) {
|
|
12
|
-
context.fail(_this, `
|
|
12
|
+
context.fail(_this, `Value required`, input);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
return nested(input, context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../src/constants.ts","../../src/factories.ts","../../src/index.ts","../../src/core/constants.ts","../../src/core/context.ts","../../src/core/index.ts","../../src/core/types.ts","../../src/core/utilities.ts","../../src/core/validation-error.ts","../../src/core/validator.ts","../../src/helpers/object.utils.ts","../../src/helpers/omit-undefined.ts","../../src/helpers/string.utils.ts","../../src/rules/index.ts","../../src/rules/format-rules/is-alpha.ts","../../src/rules/format-rules/is-ascii.ts","../../src/rules/format-rules/is-base64.ts","../../src/rules/format-rules/is-btc-address.ts","../../src/rules/format-rules/is-credit-card.ts","../../src/rules/format-rules/is-decimal.ts","../../src/rules/format-rules/is-ean.ts","../../src/rules/format-rules/is-email.ts","../../src/rules/format-rules/is-eth-address.ts","../../src/rules/format-rules/is-fqdn.ts","../../src/rules/format-rules/is-hash.ts","../../src/rules/format-rules/is-hex-color.ts","../../src/rules/format-rules/is-hex.ts","../../src/rules/format-rules/is-iban.ts","../../src/rules/format-rules/is-ip.ts","../../src/rules/format-rules/is-issn.ts","../../src/rules/format-rules/is-jwt.ts","../../src/rules/format-rules/is-lowercase.ts","../../src/rules/format-rules/is-mac-address.ts","../../src/rules/format-rules/is-mobile-phone.ts","../../src/rules/format-rules/is-object-id.ts","../../src/rules/format-rules/is-passport-number.ts","../../src/rules/format-rules/is-port.ts","../../src/rules/format-rules/is-url.ts","../../src/rules/format-rules/is-uuid.ts","../../src/rules/format-rules/is-vat-number.ts","../../src/rules/format-rules/matches.ts","../../src/rules/logical-rules/is-defined.ts","../../src/rules/logical-rules/is-empty.ts","../../src/rules/logical-rules/range.ts","../../src/rules/type-rules/is-any.ts","../../src/rules/type-rules/is-array.ts","../../src/rules/type-rules/is-bigint.ts","../../src/rules/type-rules/is-boolean.ts","../../src/rules/type-rules/is-date.ts","../../src/rules/type-rules/is-enum.ts","../../src/rules/type-rules/is-integer.ts","../../src/rules/type-rules/is-null.ts","../../src/rules/type-rules/is-number.ts","../../src/rules/type-rules/is-object.ts","../../src/rules/type-rules/is-record.ts","../../src/rules/type-rules/is-string.ts","../../src/rules/type-rules/is-tuple.ts","../../src/rules/type-rules/is-undefined.ts","../../src/rules/utility-rules/exists.ts","../../src/rules/utility-rules/get-length.ts","../../src/rules/utility-rules/optional.ts","../../src/rules/utility-rules/pipe.ts","../../src/rules/utility-rules/required.ts","../../src/rules/utility-rules/union.ts"],"version":"5.
|
|
1
|
+
{"root":["../../src/constants.ts","../../src/factories.ts","../../src/index.ts","../../src/core/constants.ts","../../src/core/context.ts","../../src/core/index.ts","../../src/core/types.ts","../../src/core/utilities.ts","../../src/core/validation-error.ts","../../src/core/validator.ts","../../src/helpers/object.utils.ts","../../src/helpers/omit-undefined.ts","../../src/helpers/string.utils.ts","../../src/rules/index.ts","../../src/rules/format-rules/is-alpha.ts","../../src/rules/format-rules/is-ascii.ts","../../src/rules/format-rules/is-base64.ts","../../src/rules/format-rules/is-btc-address.ts","../../src/rules/format-rules/is-credit-card.ts","../../src/rules/format-rules/is-decimal.ts","../../src/rules/format-rules/is-ean.ts","../../src/rules/format-rules/is-email.ts","../../src/rules/format-rules/is-eth-address.ts","../../src/rules/format-rules/is-fqdn.ts","../../src/rules/format-rules/is-hash.ts","../../src/rules/format-rules/is-hex-color.ts","../../src/rules/format-rules/is-hex.ts","../../src/rules/format-rules/is-iban.ts","../../src/rules/format-rules/is-ip.ts","../../src/rules/format-rules/is-issn.ts","../../src/rules/format-rules/is-jwt.ts","../../src/rules/format-rules/is-lowercase.ts","../../src/rules/format-rules/is-mac-address.ts","../../src/rules/format-rules/is-mobile-phone.ts","../../src/rules/format-rules/is-object-id.ts","../../src/rules/format-rules/is-passport-number.ts","../../src/rules/format-rules/is-port.ts","../../src/rules/format-rules/is-url.ts","../../src/rules/format-rules/is-uuid.ts","../../src/rules/format-rules/is-vat-number.ts","../../src/rules/format-rules/matches.ts","../../src/rules/logical-rules/is-defined.ts","../../src/rules/logical-rules/is-empty.ts","../../src/rules/logical-rules/range.ts","../../src/rules/type-rules/is-any.ts","../../src/rules/type-rules/is-array.ts","../../src/rules/type-rules/is-bigint.ts","../../src/rules/type-rules/is-boolean.ts","../../src/rules/type-rules/is-date.ts","../../src/rules/type-rules/is-enum.ts","../../src/rules/type-rules/is-integer.ts","../../src/rules/type-rules/is-null.ts","../../src/rules/type-rules/is-number.ts","../../src/rules/type-rules/is-object.ts","../../src/rules/type-rules/is-record.ts","../../src/rules/type-rules/is-string.ts","../../src/rules/type-rules/is-tuple.ts","../../src/rules/type-rules/is-undefined.ts","../../src/rules/utility-rules/exists.ts","../../src/rules/utility-rules/get-length.ts","../../src/rules/utility-rules/optional.ts","../../src/rules/utility-rules/pipe.ts","../../src/rules/utility-rules/required.ts","../../src/rules/utility-rules/union.ts"],"version":"5.7.3"}
|
package/esm/core/context.js
CHANGED
|
@@ -4,6 +4,7 @@ const VARIABLE_REPLACE_PATTERN = /{{([^}]*)}}/g;
|
|
|
4
4
|
const OPTIONAL_VAR_PATTERN = /^([^?]+)(?:\||(.*))?$/;
|
|
5
5
|
export class Context {
|
|
6
6
|
constructor(options) {
|
|
7
|
+
this.isRoot = true;
|
|
7
8
|
this.errors = [];
|
|
8
9
|
Object.assign(this, options);
|
|
9
10
|
}
|
|
@@ -62,6 +63,7 @@ export class Context {
|
|
|
62
63
|
extended[k] = v;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
66
|
+
extended.isRoot = false;
|
|
65
67
|
Object.setPrototypeOf(extended, this);
|
|
66
68
|
return extended;
|
|
67
69
|
}
|
package/esm/core/validator.js
CHANGED
|
@@ -22,11 +22,17 @@ export function validator(arg0, arg1, arg2) {
|
|
|
22
22
|
id = id || fn.name || 'validator' + ++unnamedValidatorIndex;
|
|
23
23
|
const name = fn.name || camelCase(id);
|
|
24
24
|
const _rule = {
|
|
25
|
-
[name](input, options) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
[name](input, options, context) {
|
|
26
|
+
if (context) {
|
|
27
|
+
if (options || validatorOptions)
|
|
28
|
+
context = context.extend({ ...validatorOptions, ...options });
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
context =
|
|
32
|
+
options instanceof Context
|
|
33
|
+
? options.extend({ ...validatorOptions })
|
|
34
|
+
: new Context({ ...validatorOptions, ...options });
|
|
35
|
+
}
|
|
30
36
|
let value;
|
|
31
37
|
try {
|
|
32
38
|
value = fn(input, context, _rule);
|
|
@@ -36,7 +42,7 @@ export function validator(arg0, arg1, arg2) {
|
|
|
36
42
|
throw e;
|
|
37
43
|
context.fail(_rule, e, input);
|
|
38
44
|
}
|
|
39
|
-
if (
|
|
45
|
+
if (context.isRoot && context.errors.length) {
|
|
40
46
|
throw new ValidationError(context.errors);
|
|
41
47
|
}
|
|
42
48
|
return value;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import validatorJS from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Check if the string contains only letters (a-zA-Z).
|
|
@@ -8,7 +8,7 @@ export function isAlpha(options) {
|
|
|
8
8
|
return validator('isLowercase', (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isAlpha(input))
|
|
10
10
|
return input;
|
|
11
|
-
context.fail(_this, `"
|
|
11
|
+
context.fail(_this, `"Value must be an alpha string`, input);
|
|
12
12
|
}, options);
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
@@ -20,6 +20,6 @@ export function isAlphanumeric(options) {
|
|
|
20
20
|
if (typeof input === 'string' && validatorJS.isAlphanumeric(input)) {
|
|
21
21
|
return input;
|
|
22
22
|
}
|
|
23
|
-
context.fail(_this, `"
|
|
23
|
+
context.fail(_this, `"Value must be an alphanumeric string`, input);
|
|
24
24
|
}, options);
|
|
25
25
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import validatorJS from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Check if the string contains ASCII chars only.
|
|
@@ -8,6 +8,6 @@ export function isAscii(options) {
|
|
|
8
8
|
return validator('isAscii', (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isAscii(input))
|
|
10
10
|
return input;
|
|
11
|
-
context.fail(_this, `Value
|
|
11
|
+
context.fail(_this, `Value must be an ascii string`, input);
|
|
12
12
|
}, options);
|
|
13
13
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import validatorJS from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is a "Base64" string.
|
|
@@ -9,6 +9,6 @@ export function isBase64(options) {
|
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isBase64(input, options)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
12
|
-
context.fail(_this, `"
|
|
12
|
+
context.fail(_this, `"Value must be a Base64 string`, input);
|
|
13
13
|
}, options);
|
|
14
14
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import validatorJS from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is a BTC address.
|
|
@@ -9,6 +9,6 @@ export function isBtcAddress(options) {
|
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isBtcAddress(input)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
12
|
-
context.fail(_this, `Value
|
|
12
|
+
context.fail(_this, `Value must be a valid BTC address`, input);
|
|
13
13
|
}, options);
|
|
14
14
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import validatorJS from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is a credit card number
|
|
@@ -10,6 +10,6 @@ export function isCreditCard(options) {
|
|
|
10
10
|
validatorJS.isCreditCard(input, options)) {
|
|
11
11
|
return input;
|
|
12
12
|
}
|
|
13
|
-
context.fail(_this, `
|
|
13
|
+
context.fail(_this, `Value must be a valid Credit Card number`, input);
|
|
14
14
|
}, options);
|
|
15
15
|
}
|