valgen 5.18.2 → 5.19.1
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/{types/index.d.ts → index.d.ts} +63 -59
- package/{esm/index.js → index.js} +10 -1
- package/package.json +9 -25
- package/{types/rules → rules}/type-rules/is-date.d.ts +6 -6
- 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/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,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPassportNumber = isPassportNumber;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
|
-
const index_js_1 = require("../../core/index.js");
|
|
7
|
-
/**
|
|
8
|
-
* Validates if value is a passport number
|
|
9
|
-
* @validator isPassportNumber
|
|
10
|
-
*/
|
|
11
|
-
function isPassportNumber(countryCode, options) {
|
|
12
|
-
return (0, index_js_1.validator)('isPassportNumber', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' &&
|
|
14
|
-
validator_1.default.isPassportNumber(input, countryCode)) {
|
|
15
|
-
return input;
|
|
16
|
-
}
|
|
17
|
-
context.fail(_this, `Value must be a valid ${countryCode} PassportNumber)`, input);
|
|
18
|
-
}, options);
|
|
19
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPort = isPort;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
|
-
const index_js_1 = require("../../core/index.js");
|
|
7
|
-
/**
|
|
8
|
-
* Validates if value is a port number
|
|
9
|
-
* @validator isPort
|
|
10
|
-
*/
|
|
11
|
-
function isPort(options) {
|
|
12
|
-
return (0, index_js_1.validator)('isPort', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'number')
|
|
14
|
-
input = String(input);
|
|
15
|
-
if (input != null &&
|
|
16
|
-
typeof input === 'string' &&
|
|
17
|
-
validator_1.default.isPort(input)) {
|
|
18
|
-
return parseInt(input, 10);
|
|
19
|
-
}
|
|
20
|
-
context.fail(_this, `Value must be a valid port number`, input);
|
|
21
|
-
}, options);
|
|
22
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isTime = isTime;
|
|
4
|
-
const index_js_1 = require("../../core/index.js");
|
|
5
|
-
const TIME_PATTERN = /^(\d{2}):?(\d{2})(?::?(\d{2})?(?:\.(\d{1,3}))?)?$/;
|
|
6
|
-
/**
|
|
7
|
-
* Validates if value is a time formatted string
|
|
8
|
-
* @validator isTime
|
|
9
|
-
*/
|
|
10
|
-
function isTime(options) {
|
|
11
|
-
return (0, index_js_1.validator)('isTime', (input, context, _this) => {
|
|
12
|
-
if (input != null) {
|
|
13
|
-
const coerce = options?.coerce ?? context.coerce;
|
|
14
|
-
let str;
|
|
15
|
-
if (input instanceof Date && coerce) {
|
|
16
|
-
str =
|
|
17
|
-
String(input.getHours()).padStart(2, '0') +
|
|
18
|
-
':' +
|
|
19
|
-
String(input.getMinutes()).padStart(2, '0') +
|
|
20
|
-
':' +
|
|
21
|
-
String(input.getSeconds()).padStart(2, '0');
|
|
22
|
-
if (input.getMilliseconds()) {
|
|
23
|
-
str += '.' + String(input.getMilliseconds()).padStart(3, '0');
|
|
24
|
-
}
|
|
25
|
-
return str;
|
|
26
|
-
}
|
|
27
|
-
else
|
|
28
|
-
str = input;
|
|
29
|
-
if (str && typeof str === 'string') {
|
|
30
|
-
const m = TIME_PATTERN.exec(str);
|
|
31
|
-
if (m) {
|
|
32
|
-
if (parseInt(m[1]) <= 23 &&
|
|
33
|
-
parseInt(m[2]) <= 59 &&
|
|
34
|
-
(!m[3] || parseInt(m[3]) <= 59)) {
|
|
35
|
-
if (!coerce)
|
|
36
|
-
return str;
|
|
37
|
-
let out = m[1];
|
|
38
|
-
if (m[2])
|
|
39
|
-
out += ':' + m[2];
|
|
40
|
-
if (m[3])
|
|
41
|
-
out += ':' + m[3];
|
|
42
|
-
if (m[4])
|
|
43
|
-
out += '.' + m[4];
|
|
44
|
-
return out;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
context.fail(_this, `Value must be a valid Time`, input);
|
|
50
|
-
}, options);
|
|
51
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isURL = isURL;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
|
-
const index_js_1 = require("../../core/index.js");
|
|
7
|
-
/**
|
|
8
|
-
* Validates if value is an URL
|
|
9
|
-
* @validator isURL
|
|
10
|
-
*/
|
|
11
|
-
function isURL(options) {
|
|
12
|
-
return (0, index_js_1.validator)('isURL', (input, context, _this) => {
|
|
13
|
-
if (input != null &&
|
|
14
|
-
typeof input === 'string' &&
|
|
15
|
-
validator_1.default.isURL(input, options)) {
|
|
16
|
-
return input;
|
|
17
|
-
}
|
|
18
|
-
context.fail(_this, `Value must be a valid URL`, input);
|
|
19
|
-
}, options);
|
|
20
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUUID = isUUID;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
|
-
const index_js_1 = require("../../core/index.js");
|
|
7
|
-
/**
|
|
8
|
-
* Validates if value is an "UUID".
|
|
9
|
-
* @validator isUUID
|
|
10
|
-
*/
|
|
11
|
-
function isUUID(version, options) {
|
|
12
|
-
return (0, index_js_1.validator)('isUUID', (input, context, _this) => {
|
|
13
|
-
if (input != null &&
|
|
14
|
-
typeof input === 'string' &&
|
|
15
|
-
validator_1.default.isUUID(input, version)) {
|
|
16
|
-
return input;
|
|
17
|
-
}
|
|
18
|
-
context.fail(_this, `Value must be a valid UUID${version ? ' v' + version : ''}`, input);
|
|
19
|
-
}, options);
|
|
20
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isVATNumber = isVATNumber;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
|
-
const index_js_1 = require("../../core/index.js");
|
|
7
|
-
/**
|
|
8
|
-
* Validates if value is an VAT number
|
|
9
|
-
* @validator isVAT
|
|
10
|
-
*/
|
|
11
|
-
function isVATNumber(countryCode, options) {
|
|
12
|
-
return (0, index_js_1.validator)('isVATNumber', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' && validator_1.default.isVAT(input, countryCode)) {
|
|
14
|
-
return input;
|
|
15
|
-
}
|
|
16
|
-
context.fail(_this, `Value must be a valid VAT number`, input);
|
|
17
|
-
}, options);
|
|
18
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.matches = matches;
|
|
4
|
-
const index_js_1 = require("../../core/index.js");
|
|
5
|
-
/**
|
|
6
|
-
* Coerces given value to "UUID" format or returns undefined if nullish
|
|
7
|
-
* @validator uuid
|
|
8
|
-
*/
|
|
9
|
-
function matches(format, options) {
|
|
10
|
-
const regExp = format instanceof RegExp ? format : new RegExp(format);
|
|
11
|
-
const formatName = options?.formatName;
|
|
12
|
-
return (0, index_js_1.validator)('matches', (input, context, _this) => {
|
|
13
|
-
if (input == null)
|
|
14
|
-
return;
|
|
15
|
-
if (typeof input === 'string' && regExp.test(input))
|
|
16
|
-
return input;
|
|
17
|
-
context.fail(_this, `Value must match ${formatName || 'requested'} format`, input, {
|
|
18
|
-
format,
|
|
19
|
-
formatName,
|
|
20
|
-
});
|
|
21
|
-
}, options);
|
|
22
|
-
}
|
package/cjs/rules/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./format-rules/is-alpha.js"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./format-rules/is-ascii.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./format-rules/is-base64.js"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./format-rules/is-btc-address.js"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./format-rules/is-credit-card.js"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./format-rules/is-decimal.js"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./format-rules/is-ean.js"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./format-rules/is-email.js"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./format-rules/is-eth-address.js"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./format-rules/is-fqdn.js"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./format-rules/is-hash.js"), exports);
|
|
15
|
-
tslib_1.__exportStar(require("./format-rules/is-hex.js"), exports);
|
|
16
|
-
tslib_1.__exportStar(require("./format-rules/is-hex-color.js"), exports);
|
|
17
|
-
tslib_1.__exportStar(require("./format-rules/is-iban.js"), exports);
|
|
18
|
-
tslib_1.__exportStar(require("./format-rules/is-ip.js"), exports);
|
|
19
|
-
tslib_1.__exportStar(require("./format-rules/is-issn.js"), exports);
|
|
20
|
-
tslib_1.__exportStar(require("./format-rules/is-jwt.js"), exports);
|
|
21
|
-
tslib_1.__exportStar(require("./format-rules/is-lowercase.js"), exports);
|
|
22
|
-
tslib_1.__exportStar(require("./format-rules/is-mac-address.js"), exports);
|
|
23
|
-
tslib_1.__exportStar(require("./format-rules/is-mobile-phone.js"), exports);
|
|
24
|
-
tslib_1.__exportStar(require("./format-rules/is-object-id.js"), exports);
|
|
25
|
-
tslib_1.__exportStar(require("./format-rules/is-passport-number.js"), exports);
|
|
26
|
-
tslib_1.__exportStar(require("./format-rules/is-port.js"), exports);
|
|
27
|
-
tslib_1.__exportStar(require("./format-rules/is-time.js"), exports);
|
|
28
|
-
tslib_1.__exportStar(require("./format-rules/is-url.js"), exports);
|
|
29
|
-
tslib_1.__exportStar(require("./format-rules/is-uuid.js"), exports);
|
|
30
|
-
tslib_1.__exportStar(require("./format-rules/is-vat-number.js"), exports);
|
|
31
|
-
tslib_1.__exportStar(require("./format-rules/matches.js"), exports);
|
|
32
|
-
tslib_1.__exportStar(require("./logical-rules/is-defined.js"), exports);
|
|
33
|
-
tslib_1.__exportStar(require("./logical-rules/is-empty.js"), exports);
|
|
34
|
-
tslib_1.__exportStar(require("./logical-rules/is-equal.js"), exports);
|
|
35
|
-
tslib_1.__exportStar(require("./logical-rules/range.js"), exports);
|
|
36
|
-
tslib_1.__exportStar(require("./type-rules/is-any.js"), exports);
|
|
37
|
-
tslib_1.__exportStar(require("./type-rules/is-array.js"), exports);
|
|
38
|
-
tslib_1.__exportStar(require("./type-rules/is-bigint.js"), exports);
|
|
39
|
-
tslib_1.__exportStar(require("./type-rules/is-boolean.js"), exports);
|
|
40
|
-
tslib_1.__exportStar(require("./type-rules/is-date.js"), exports);
|
|
41
|
-
tslib_1.__exportStar(require("./type-rules/is-enum.js"), exports);
|
|
42
|
-
tslib_1.__exportStar(require("./type-rules/is-integer.js"), exports);
|
|
43
|
-
tslib_1.__exportStar(require("./type-rules/is-null.js"), exports);
|
|
44
|
-
tslib_1.__exportStar(require("./type-rules/is-number.js"), exports);
|
|
45
|
-
tslib_1.__exportStar(require("./type-rules/is-object.js"), exports);
|
|
46
|
-
tslib_1.__exportStar(require("./type-rules/is-record.js"), exports);
|
|
47
|
-
tslib_1.__exportStar(require("./type-rules/is-string.js"), exports);
|
|
48
|
-
tslib_1.__exportStar(require("./type-rules/is-tuple.js"), exports);
|
|
49
|
-
tslib_1.__exportStar(require("./type-rules/is-undefined.js"), exports);
|
|
50
|
-
tslib_1.__exportStar(require("./utility-rules/all-of.js"), exports);
|
|
51
|
-
tslib_1.__exportStar(require("./utility-rules/exists.js"), exports);
|
|
52
|
-
tslib_1.__exportStar(require("./utility-rules/get-length.js"), exports);
|
|
53
|
-
tslib_1.__exportStar(require("./utility-rules/one-of.js"), exports);
|
|
54
|
-
tslib_1.__exportStar(require("./utility-rules/optional.js"), exports);
|
|
55
|
-
tslib_1.__exportStar(require("./utility-rules/pipe.js"), exports);
|
|
56
|
-
tslib_1.__exportStar(require("./utility-rules/required.js"), exports);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDefined = isDefined;
|
|
4
|
-
const index_js_1 = require("../../core/index.js");
|
|
5
|
-
/**
|
|
6
|
-
* Validates if value is not "undefined" nor "null"
|
|
7
|
-
* @validator isDefined
|
|
8
|
-
*/
|
|
9
|
-
function isDefined(options) {
|
|
10
|
-
return (0, index_js_1.validator)('is-defined', (input, context, _this) => {
|
|
11
|
-
if (input !== undefined)
|
|
12
|
-
return input;
|
|
13
|
-
context.fail(_this, `Value must be defined`, input);
|
|
14
|
-
}, options);
|
|
15
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEmpty = isEmpty;
|
|
4
|
-
exports.isNotEmpty = isNotEmpty;
|
|
5
|
-
const index_js_1 = require("../../core/index.js");
|
|
6
|
-
/**
|
|
7
|
-
* Checks if value is an empty. Value should be string, array, set, map or object
|
|
8
|
-
* @validator isEmpty
|
|
9
|
-
*/
|
|
10
|
-
function isEmpty(options) {
|
|
11
|
-
return (0, index_js_1.validator)('isEmpty', (input, context, _this) => {
|
|
12
|
-
if (input == null)
|
|
13
|
-
return input;
|
|
14
|
-
if (typeof input === 'string') {
|
|
15
|
-
if (input)
|
|
16
|
-
context.fail(_this, `Value must be an empty string`, input);
|
|
17
|
-
return input;
|
|
18
|
-
}
|
|
19
|
-
else if (Array.isArray(input)) {
|
|
20
|
-
if (input.length)
|
|
21
|
-
context.fail(_this, `Value must be an empty array`, input);
|
|
22
|
-
return input;
|
|
23
|
-
}
|
|
24
|
-
else if (input instanceof Set) {
|
|
25
|
-
if (input.size)
|
|
26
|
-
context.fail(_this, `Value must be an empty Set`, input);
|
|
27
|
-
return input;
|
|
28
|
-
}
|
|
29
|
-
else if (input instanceof Map) {
|
|
30
|
-
if (input.size)
|
|
31
|
-
context.fail(_this, `Value must be an empty Map`, input);
|
|
32
|
-
return input;
|
|
33
|
-
}
|
|
34
|
-
else if (Buffer.isBuffer(input)) {
|
|
35
|
-
if (input.length)
|
|
36
|
-
context.fail(_this, `Value must be an empty Buffer`, input);
|
|
37
|
-
return input;
|
|
38
|
-
}
|
|
39
|
-
else if (input instanceof ArrayBuffer) {
|
|
40
|
-
if (input.byteLength)
|
|
41
|
-
context.fail(_this, `Value must be an empty ArrayBuffer`, input);
|
|
42
|
-
return input;
|
|
43
|
-
}
|
|
44
|
-
else if (typeof input === 'object') {
|
|
45
|
-
if (input instanceof Date)
|
|
46
|
-
return input;
|
|
47
|
-
if (Object.keys(input).length)
|
|
48
|
-
context.fail(_this, `Value must be an empty Object`, input);
|
|
49
|
-
return input;
|
|
50
|
-
}
|
|
51
|
-
context.fail(_this, `Value must be empty`, input);
|
|
52
|
-
}, options);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Checks if value is a not empty. Value should be string, array, set, map or object
|
|
56
|
-
* @validator isNotEmpty
|
|
57
|
-
*/
|
|
58
|
-
function isNotEmpty(options) {
|
|
59
|
-
return (0, index_js_1.validator)('isNotEmpty', (input, context, _this) => {
|
|
60
|
-
if (input != null) {
|
|
61
|
-
if (typeof input === 'string') {
|
|
62
|
-
if (!input)
|
|
63
|
-
context.fail(_this, `Value must not be empty`, input);
|
|
64
|
-
return input;
|
|
65
|
-
}
|
|
66
|
-
else if (typeof input === 'number') {
|
|
67
|
-
if (Number.isNaN(input))
|
|
68
|
-
context.fail(_this, `Value must not be NaN`, input);
|
|
69
|
-
return input;
|
|
70
|
-
}
|
|
71
|
-
else if (typeof input === 'object') {
|
|
72
|
-
if (Array.isArray(input)) {
|
|
73
|
-
if (!input.length)
|
|
74
|
-
context.fail(_this, `Array must not be empty`, input);
|
|
75
|
-
return input;
|
|
76
|
-
}
|
|
77
|
-
else if (input instanceof Set) {
|
|
78
|
-
if (!input.size)
|
|
79
|
-
context.fail(_this, `Set must not be empty`, input);
|
|
80
|
-
return input;
|
|
81
|
-
}
|
|
82
|
-
else if (input instanceof Map) {
|
|
83
|
-
if (!input.size)
|
|
84
|
-
context.fail(_this, `Map must not be empty`, input);
|
|
85
|
-
return input;
|
|
86
|
-
}
|
|
87
|
-
else if (Buffer.isBuffer(input)) {
|
|
88
|
-
if (!input.length)
|
|
89
|
-
context.fail(_this, `Buffer must not be empty`, input);
|
|
90
|
-
return input;
|
|
91
|
-
}
|
|
92
|
-
else if (input instanceof ArrayBuffer) {
|
|
93
|
-
if (!input.byteLength)
|
|
94
|
-
context.fail(_this, `ArrayBuffer must not be empty`, input);
|
|
95
|
-
return input;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
if (input instanceof Date)
|
|
99
|
-
return input;
|
|
100
|
-
if (!Object.keys(input).length)
|
|
101
|
-
context.fail(_this, `Object must not be empty`, input);
|
|
102
|
-
return input;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return input;
|
|
106
|
-
}
|
|
107
|
-
context.fail(_this, `Value must not be empty`, input);
|
|
108
|
-
return input;
|
|
109
|
-
}, options);
|
|
110
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEqual = isEqual;
|
|
4
|
-
exports.isNotEqual = isNotEqual;
|
|
5
|
-
const index_js_1 = require("../../core/index.js");
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @validator isEqual
|
|
9
|
-
*/
|
|
10
|
-
function isEqual(compare, options) {
|
|
11
|
-
return (0, index_js_1.validator)('isEqual', (input, context, _this) => {
|
|
12
|
-
if (input == null)
|
|
13
|
-
return input;
|
|
14
|
-
if (input !== compare)
|
|
15
|
-
context.fail(_this, `Value must be equal to "${compare}"`, input);
|
|
16
|
-
return input;
|
|
17
|
-
}, options);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @validator isNotEqual
|
|
22
|
-
*/
|
|
23
|
-
function isNotEqual(compare, options) {
|
|
24
|
-
return (0, index_js_1.validator)('isNotEqual', (input, context, _this) => {
|
|
25
|
-
if (input == null)
|
|
26
|
-
return input;
|
|
27
|
-
if (input === compare) {
|
|
28
|
-
context.fail(_this, `Value must not be equal to "${compare}"`, input);
|
|
29
|
-
}
|
|
30
|
-
return input;
|
|
31
|
-
}, options);
|
|
32
|
-
}
|
|
@@ -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
|
-
}
|