valgen 5.6.0 → 5.7.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 +7 -0
- package/cjs/core/index.js +7 -20
- package/cjs/factories.js +2 -15
- package/cjs/index.js +4 -29
- package/cjs/rules/format-rules/is-alpha.js +2 -24
- package/cjs/rules/format-rules/is-ascii.js +2 -24
- package/cjs/rules/format-rules/is-base64.js +2 -24
- package/cjs/rules/format-rules/is-btc-address.js +2 -24
- package/cjs/rules/format-rules/is-credit-card.js +2 -24
- package/cjs/rules/format-rules/is-decimal.js +2 -24
- package/cjs/rules/format-rules/is-ean.js +2 -24
- package/cjs/rules/format-rules/is-email.js +2 -24
- package/cjs/rules/format-rules/is-eth-address.js +2 -24
- package/cjs/rules/format-rules/is-fqdn.js +2 -24
- package/cjs/rules/format-rules/is-hash.js +2 -24
- package/cjs/rules/format-rules/is-hex-color.js +2 -24
- package/cjs/rules/format-rules/is-hex.js +2 -24
- package/cjs/rules/format-rules/is-iban.js +2 -24
- package/cjs/rules/format-rules/is-ip.js +2 -24
- package/cjs/rules/format-rules/is-issn.js +2 -24
- package/cjs/rules/format-rules/is-jwt.js +2 -24
- package/cjs/rules/format-rules/is-lowercase.js +2 -24
- package/cjs/rules/format-rules/is-mac-address.js +2 -24
- package/cjs/rules/format-rules/is-mobile-phone.js +2 -24
- package/cjs/rules/format-rules/is-object-id.js +2 -4
- package/cjs/rules/format-rules/is-passport-number.js +2 -24
- package/cjs/rules/format-rules/is-port.js +2 -24
- package/cjs/rules/format-rules/is-url.js +2 -24
- package/cjs/rules/format-rules/is-uuid.js +2 -24
- package/cjs/rules/format-rules/is-vat-number.js +2 -24
- package/cjs/rules/index.js +51 -64
- package/esm/constants.js +5 -2
- package/esm/core/constants.js +5 -2
- package/esm/core/context.js +9 -5
- package/esm/core/index.js +9 -6
- package/esm/core/types.js +2 -1
- package/esm/core/utilities.js +10 -6
- package/esm/core/validation-error.js +5 -1
- package/esm/core/validator.js +18 -14
- package/esm/factories.js +4 -1
- package/esm/helpers/object.utils.js +6 -2
- package/esm/helpers/omit-undefined.js +4 -1
- package/esm/helpers/string.utils.js +4 -1
- package/esm/index.js +67 -4
- package/esm/rules/format-rules/is-alpha.js +11 -6
- package/esm/rules/format-rules/is-ascii.js +8 -4
- package/esm/rules/format-rules/is-base64.js +8 -4
- package/esm/rules/format-rules/is-btc-address.js +8 -4
- package/esm/rules/format-rules/is-credit-card.js +8 -4
- package/esm/rules/format-rules/is-decimal.js +8 -4
- package/esm/rules/format-rules/is-ean.js +8 -4
- package/esm/rules/format-rules/is-email.js +8 -4
- package/esm/rules/format-rules/is-eth-address.js +8 -4
- package/esm/rules/format-rules/is-fqdn.js +8 -4
- package/esm/rules/format-rules/is-hash.js +8 -4
- package/esm/rules/format-rules/is-hex-color.js +8 -4
- package/esm/rules/format-rules/is-hex.js +8 -4
- package/esm/rules/format-rules/is-iban.js +11 -6
- package/esm/rules/format-rules/is-ip.js +11 -6
- package/esm/rules/format-rules/is-issn.js +8 -4
- package/esm/rules/format-rules/is-jwt.js +8 -4
- package/esm/rules/format-rules/is-lowercase.js +11 -6
- package/esm/rules/format-rules/is-mac-address.js +8 -4
- package/esm/rules/format-rules/is-mobile-phone.js +8 -4
- package/esm/rules/format-rules/is-object-id.js +9 -5
- package/esm/rules/format-rules/is-passport-number.js +8 -4
- package/esm/rules/format-rules/is-port.js +8 -4
- package/esm/rules/format-rules/is-url.js +8 -4
- package/esm/rules/format-rules/is-uuid.js +8 -4
- package/esm/rules/format-rules/is-vat-number.js +8 -4
- package/esm/rules/format-rules/matches.js +6 -3
- package/esm/rules/index.js +53 -50
- package/esm/rules/logical-rules/is-defined.js +6 -3
- package/esm/rules/logical-rules/is-empty.js +9 -5
- package/esm/rules/logical-rules/range.js +29 -19
- package/esm/rules/type-rules/is-any.js +6 -2
- package/esm/rules/type-rules/is-array.js +6 -3
- package/esm/rules/type-rules/is-bigint.js +6 -3
- package/esm/rules/type-rules/is-boolean.js +6 -3
- package/esm/rules/type-rules/is-date.js +14 -10
- package/esm/rules/type-rules/is-enum.js +6 -3
- package/esm/rules/type-rules/is-integer.js +6 -3
- package/esm/rules/type-rules/is-null.js +15 -9
- package/esm/rules/type-rules/is-number.js +6 -3
- package/esm/rules/type-rules/is-object.js +14 -11
- package/esm/rules/type-rules/is-record.js +6 -3
- package/esm/rules/type-rules/is-string.js +22 -13
- package/esm/rules/type-rules/is-tuple.js +6 -3
- package/esm/rules/type-rules/is-undefined.js +6 -3
- package/esm/rules/utility-rules/exists.js +6 -3
- package/esm/rules/utility-rules/get-length.js +6 -3
- package/esm/rules/utility-rules/optional.js +6 -3
- package/esm/rules/utility-rules/pipe.js +9 -5
- package/esm/rules/utility-rules/required.js +6 -3
- package/esm/rules/utility-rules/union.js +6 -3
- package/package.json +16 -16
- package/cjs/package.json +0 -3
- /package/{typings → types}/constants.d.ts +0 -0
- /package/{typings → types}/core/constants.d.ts +0 -0
- /package/{typings → types}/core/context.d.ts +0 -0
- /package/{typings → types}/core/index.d.ts +0 -0
- /package/{typings → types}/core/types.d.ts +0 -0
- /package/{typings → types}/core/utilities.d.ts +0 -0
- /package/{typings → types}/core/validation-error.d.ts +0 -0
- /package/{typings → types}/core/validator.d.ts +0 -0
- /package/{typings → types}/factories.d.ts +0 -0
- /package/{typings → types}/helpers/object.utils.d.ts +0 -0
- /package/{typings → types}/helpers/omit-undefined.d.ts +0 -0
- /package/{typings → types}/helpers/string.utils.d.ts +0 -0
- /package/{typings → types}/index.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-alpha.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-ascii.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-base64.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-btc-address.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-credit-card.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-decimal.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-ean.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-email.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-eth-address.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-fqdn.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-hash.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-hex-color.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-hex.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-iban.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-ip.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-issn.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-jwt.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-lowercase.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-mac-address.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-mobile-phone.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-object-id.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-passport-number.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-port.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-url.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-uuid.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-vat-number.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/matches.d.ts +0 -0
- /package/{typings → types}/rules/index.d.ts +0 -0
- /package/{typings → types}/rules/logical-rules/is-defined.d.ts +0 -0
- /package/{typings → types}/rules/logical-rules/is-empty.d.ts +0 -0
- /package/{typings → types}/rules/logical-rules/range.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-any.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-array.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-bigint.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-boolean.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-date.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-enum.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-integer.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-null.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-number.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-object.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-record.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-string.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-tuple.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-undefined.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/exists.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/get-length.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/optional.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/pipe.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/required.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/union.d.ts +0 -0
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMobilePhone = isMobilePhone;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const validatorJS = tslib_1.__importStar(require("validator"));
|
|
6
|
+
const index_js_1 = require("../../core/index.js");
|
|
3
7
|
/**
|
|
4
8
|
* Validates if value is a valid Email
|
|
5
9
|
* @validator isMobilePhone
|
|
6
10
|
*/
|
|
7
|
-
|
|
11
|
+
function isMobilePhone(options) {
|
|
8
12
|
const opts = {
|
|
9
13
|
strictMode: options?.strictMode,
|
|
10
14
|
};
|
|
11
|
-
return validator('isMobilePhone', (input, context, _this) => {
|
|
15
|
+
return (0, index_js_1.validator)('isMobilePhone', (input, context, _this) => {
|
|
12
16
|
if (typeof input === 'string' &&
|
|
13
17
|
validatorJS.isMobilePhone(input, options?.locale, opts)) {
|
|
14
18
|
return input;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isObjectId = isObjectId;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("validator"));
|
|
6
|
+
const index_js_1 = require("../../core/index.js");
|
|
3
7
|
/**
|
|
4
8
|
* Validates if value is an "ObjectId".
|
|
5
9
|
* @validator isObjectId
|
|
6
10
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isObjectId', (input, context, _this) => {
|
|
11
|
+
function isObjectId(options) {
|
|
12
|
+
return (0, index_js_1.validator)('isObjectId', (input, context, _this) => {
|
|
9
13
|
if (input != null &&
|
|
10
14
|
(_isObjectIdValue(input) ||
|
|
11
15
|
(typeof input === 'object' &&
|
|
@@ -20,5 +24,5 @@ function _isObjectIdValue(input) {
|
|
|
20
24
|
return ((input instanceof Uint8Array && input.length === 12) ||
|
|
21
25
|
(typeof input === 'string' &&
|
|
22
26
|
input.length === 24 &&
|
|
23
|
-
|
|
27
|
+
validator_1.default.isHexadecimal(input)));
|
|
24
28
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPassportNumber = isPassportNumber;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const validatorJS = tslib_1.__importStar(require("validator"));
|
|
6
|
+
const index_js_1 = require("../../core/index.js");
|
|
3
7
|
/**
|
|
4
8
|
* Validates if value is a passport number
|
|
5
9
|
* @validator isPassportNumber
|
|
6
10
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isPassportNumber', (input, context, _this) => {
|
|
11
|
+
function isPassportNumber(countryCode, options) {
|
|
12
|
+
return (0, index_js_1.validator)('isPassportNumber', (input, context, _this) => {
|
|
9
13
|
if (typeof input === 'string' &&
|
|
10
14
|
validatorJS.isPassportNumber(input, countryCode)) {
|
|
11
15
|
return input;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPort = isPort;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const validatorJS = tslib_1.__importStar(require("validator"));
|
|
6
|
+
const index_js_1 = require("../../core/index.js");
|
|
3
7
|
/**
|
|
4
8
|
* Validates if value is a port number
|
|
5
9
|
* @validator isPort
|
|
6
10
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isPort', (input, context, _this) => {
|
|
11
|
+
function isPort(options) {
|
|
12
|
+
return (0, index_js_1.validator)('isPort', (input, context, _this) => {
|
|
9
13
|
if (input != null &&
|
|
10
14
|
typeof input === 'string' &&
|
|
11
15
|
validatorJS.isPort(input)) {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isURL = isURL;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const validatorJS = tslib_1.__importStar(require("validator"));
|
|
6
|
+
const index_js_1 = require("../../core/index.js");
|
|
3
7
|
/**
|
|
4
8
|
* Validates if value is an URL
|
|
5
9
|
* @validator isURL
|
|
6
10
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isURL', (input, context, _this) => {
|
|
11
|
+
function isURL(options) {
|
|
12
|
+
return (0, index_js_1.validator)('isURL', (input, context, _this) => {
|
|
9
13
|
if (input != null &&
|
|
10
14
|
typeof input === 'string' &&
|
|
11
15
|
validatorJS.isURL(input, options)) {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUUID = isUUID;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const validatorJS = tslib_1.__importStar(require("validator"));
|
|
6
|
+
const index_js_1 = require("../../core/index.js");
|
|
3
7
|
/**
|
|
4
8
|
* Validates if value is an "UUID".
|
|
5
9
|
* @validator isUUID
|
|
6
10
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isUUID', (input, context, _this) => {
|
|
11
|
+
function isUUID(version, options) {
|
|
12
|
+
return (0, index_js_1.validator)('isUUID', (input, context, _this) => {
|
|
9
13
|
if (input != null &&
|
|
10
14
|
typeof input === 'string' &&
|
|
11
15
|
validatorJS.isUUID(input, version)) {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isVATNumber = isVATNumber;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const validatorJS = tslib_1.__importStar(require("validator"));
|
|
6
|
+
const index_js_1 = require("../../core/index.js");
|
|
3
7
|
/**
|
|
4
8
|
* Validates if value is an VAT number
|
|
5
9
|
* @validator isVAT
|
|
6
10
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isVATNumber', (input, context, _this) => {
|
|
11
|
+
function isVATNumber(countryCode, options) {
|
|
12
|
+
return (0, index_js_1.validator)('isVATNumber', (input, context, _this) => {
|
|
9
13
|
if (typeof input === 'string' && validatorJS.isVAT(input, countryCode)) {
|
|
10
14
|
return input;
|
|
11
15
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matches = matches;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Coerces given value to "UUID" format or returns undefined if nullish
|
|
4
7
|
* @validator uuid
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
function matches(format, options) {
|
|
7
10
|
const regExp = format instanceof RegExp ? format : new RegExp(format);
|
|
8
11
|
const formatName = options?.formatName;
|
|
9
|
-
return validator('matches', (input, context, _this) => {
|
|
12
|
+
return (0, index_js_1.validator)('matches', (input, context, _this) => {
|
|
10
13
|
if (input == null)
|
|
11
14
|
return;
|
|
12
15
|
if (typeof input === 'string' && regExp.test(input))
|
package/esm/rules/index.js
CHANGED
|
@@ -1,50 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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-url.js"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./format-rules/is-uuid.js"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./format-rules/is-vat-number.js"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./format-rules/matches.js"), exports);
|
|
31
|
+
tslib_1.__exportStar(require("./logical-rules/is-defined.js"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./logical-rules/is-empty.js"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./logical-rules/range.js"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./type-rules/is-any.js"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./type-rules/is-array.js"), exports);
|
|
36
|
+
tslib_1.__exportStar(require("./type-rules/is-bigint.js"), exports);
|
|
37
|
+
tslib_1.__exportStar(require("./type-rules/is-boolean.js"), exports);
|
|
38
|
+
tslib_1.__exportStar(require("./type-rules/is-date.js"), exports);
|
|
39
|
+
tslib_1.__exportStar(require("./type-rules/is-enum.js"), exports);
|
|
40
|
+
tslib_1.__exportStar(require("./type-rules/is-integer.js"), exports);
|
|
41
|
+
tslib_1.__exportStar(require("./type-rules/is-null.js"), exports);
|
|
42
|
+
tslib_1.__exportStar(require("./type-rules/is-number.js"), exports);
|
|
43
|
+
tslib_1.__exportStar(require("./type-rules/is-object.js"), exports);
|
|
44
|
+
tslib_1.__exportStar(require("./type-rules/is-record.js"), exports);
|
|
45
|
+
tslib_1.__exportStar(require("./type-rules/is-string.js"), exports);
|
|
46
|
+
tslib_1.__exportStar(require("./type-rules/is-tuple.js"), exports);
|
|
47
|
+
tslib_1.__exportStar(require("./type-rules/is-undefined.js"), exports);
|
|
48
|
+
tslib_1.__exportStar(require("./utility-rules/exists.js"), exports);
|
|
49
|
+
tslib_1.__exportStar(require("./utility-rules/get-length.js"), exports);
|
|
50
|
+
tslib_1.__exportStar(require("./utility-rules/optional.js"), exports);
|
|
51
|
+
tslib_1.__exportStar(require("./utility-rules/pipe.js"), exports);
|
|
52
|
+
tslib_1.__exportStar(require("./utility-rules/required.js"), exports);
|
|
53
|
+
tslib_1.__exportStar(require("./utility-rules/union.js"), exports);
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDefined = isDefined;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Validates if value is not "undefined" nor "null"
|
|
4
7
|
* @validator isDefined
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
return validator('is-defined', (input, context, _this) => {
|
|
9
|
+
function isDefined(options) {
|
|
10
|
+
return (0, index_js_1.validator)('is-defined', (input, context, _this) => {
|
|
8
11
|
if (input !== undefined)
|
|
9
12
|
return input;
|
|
10
13
|
context.fail(_this, `Is not defined`, input);
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
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");
|
|
2
6
|
/**
|
|
3
7
|
* Checks if value is an empty. Value should be string, array, set, map or object
|
|
4
8
|
* @validator isEmpty
|
|
5
9
|
*/
|
|
6
|
-
|
|
7
|
-
return validator('isEmpty', (input, context, _this) => {
|
|
10
|
+
function isEmpty(options) {
|
|
11
|
+
return (0, index_js_1.validator)('isEmpty', (input, context, _this) => {
|
|
8
12
|
if (input == null)
|
|
9
13
|
return input;
|
|
10
14
|
if (typeof input === 'string') {
|
|
@@ -39,8 +43,8 @@ export function isEmpty(options) {
|
|
|
39
43
|
* Checks if value is a not empty. Value should be string, array, set, map or object
|
|
40
44
|
* @validator isNotEmpty
|
|
41
45
|
*/
|
|
42
|
-
|
|
43
|
-
return validator('isNotEmpty', (input, context, _this) => {
|
|
46
|
+
function isNotEmpty(options) {
|
|
47
|
+
return (0, index_js_1.validator)('isNotEmpty', (input, context, _this) => {
|
|
44
48
|
if (input != null) {
|
|
45
49
|
if (typeof input === 'string') {
|
|
46
50
|
if (input)
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 get_length_js_1 = require("../utility-rules/get-length.js");
|
|
11
|
+
const pipe_js_1 = require("../utility-rules/pipe.js");
|
|
4
12
|
/**
|
|
5
13
|
* Checks if value is between minValue and maxValue
|
|
6
14
|
* @validator range
|
|
7
15
|
*/
|
|
8
|
-
|
|
9
|
-
return validator('range', (input, context, _this) => {
|
|
16
|
+
function range(minValue, maxValue, options) {
|
|
17
|
+
return (0, index_js_1.validator)('range', (input, context, _this) => {
|
|
10
18
|
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
11
19
|
(typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
12
20
|
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
@@ -31,8 +39,8 @@ export function range(minValue, maxValue, options) {
|
|
|
31
39
|
context.fail(_this, `Value must be between ${minValue} and ${maxValue}`, input);
|
|
32
40
|
}, options);
|
|
33
41
|
}
|
|
34
|
-
|
|
35
|
-
return validator('isGt', (input, context, _this) => {
|
|
42
|
+
function isGt(minValue, options) {
|
|
43
|
+
return (0, index_js_1.validator)('isGt', (input, context, _this) => {
|
|
36
44
|
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
37
45
|
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
38
46
|
input > minValue) {
|
|
@@ -53,8 +61,8 @@ export function isGt(minValue, options) {
|
|
|
53
61
|
context.fail(_this, `{{label}} must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
54
62
|
}, options);
|
|
55
63
|
}
|
|
56
|
-
|
|
57
|
-
return validator('isGte', (input, context, _this) => {
|
|
64
|
+
function isGte(minValue, options) {
|
|
65
|
+
return (0, index_js_1.validator)('isGte', (input, context, _this) => {
|
|
58
66
|
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
59
67
|
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
60
68
|
input >= minValue) {
|
|
@@ -75,8 +83,8 @@ export function isGte(minValue, options) {
|
|
|
75
83
|
context.fail(_this, `{{label}} must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
76
84
|
}, options);
|
|
77
85
|
}
|
|
78
|
-
|
|
79
|
-
return validator('isLt', (input, context, _this) => {
|
|
86
|
+
function isLt(maxValue, options) {
|
|
87
|
+
return (0, index_js_1.validator)('isLt', (input, context, _this) => {
|
|
80
88
|
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
81
89
|
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
82
90
|
input < maxValue) {
|
|
@@ -97,8 +105,8 @@ export function isLt(maxValue, options) {
|
|
|
97
105
|
context.fail(_this, `{{label}} must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
|
|
98
106
|
}, options);
|
|
99
107
|
}
|
|
100
|
-
|
|
101
|
-
return validator('isLte', (input, context, _this) => {
|
|
108
|
+
function isLte(maxValue, options) {
|
|
109
|
+
return (0, index_js_1.validator)('isLte', (input, context, _this) => {
|
|
102
110
|
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
103
111
|
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
104
112
|
input <= maxValue) {
|
|
@@ -123,23 +131,25 @@ export function isLte(maxValue, options) {
|
|
|
123
131
|
* Checks the length is at least "minValue"
|
|
124
132
|
* @validator lengthMin
|
|
125
133
|
*/
|
|
126
|
-
|
|
127
|
-
pipe([
|
|
128
|
-
getLength(),
|
|
134
|
+
const lengthMin = (minValue) => (0, pipe_js_1.allOf)([
|
|
135
|
+
(0, pipe_js_1.pipe)([
|
|
136
|
+
(0, get_length_js_1.getLength)(),
|
|
129
137
|
isGte(minValue, {
|
|
130
138
|
onFail: () => `The length of {{label}} must be at least ${minValue}`,
|
|
131
139
|
}),
|
|
132
140
|
]),
|
|
133
141
|
]);
|
|
142
|
+
exports.lengthMin = lengthMin;
|
|
134
143
|
/**
|
|
135
144
|
* Checks if the length is at most "maxValue"
|
|
136
145
|
* @validator lengthMax
|
|
137
146
|
*/
|
|
138
|
-
|
|
139
|
-
pipe([
|
|
140
|
-
getLength(),
|
|
147
|
+
const lengthMax = (maxValue) => (0, pipe_js_1.allOf)([
|
|
148
|
+
(0, pipe_js_1.pipe)([
|
|
149
|
+
(0, get_length_js_1.getLength)(),
|
|
141
150
|
isLte(maxValue, {
|
|
142
151
|
onFail: () => `The length of {{label}} must be at most ${maxValue}`,
|
|
143
152
|
}),
|
|
144
153
|
]),
|
|
145
154
|
]);
|
|
155
|
+
exports.lengthMax = lengthMax;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAny = void 0;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Does nothing, just returns original input value.
|
|
4
7
|
* @validator isAny
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
const isAny = () => (0, index_js_1.validator)('is-any', (input) => input);
|
|
10
|
+
exports.isAny = isAny;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isArray = isArray;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Validates if value is "array" and applies validation for each item.
|
|
4
7
|
* Converts input value to array if coerce option is set to 'true'.
|
|
5
8
|
* @validator isArray
|
|
6
9
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isArray', (input, context, _this) => {
|
|
10
|
+
function isArray(itemValidator, options) {
|
|
11
|
+
return (0, index_js_1.validator)('isArray', (input, context, _this) => {
|
|
9
12
|
const coerce = options?.coerce || context.coerce;
|
|
10
13
|
let output = input;
|
|
11
14
|
if (output != null && coerce && !Array.isArray(output))
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBigint = isBigint;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Validates if value is "BigInt".
|
|
4
7
|
* Converts input value to number if coerce option is set to 'true'.
|
|
5
8
|
* @validator isNumber
|
|
6
9
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isBigint', (input, context, _this) => {
|
|
10
|
+
function isBigint(options) {
|
|
11
|
+
return (0, index_js_1.validator)('isBigint', (input, context, _this) => {
|
|
9
12
|
const coerce = options?.coerce || context.coerce;
|
|
10
13
|
if (typeof input === 'bigint')
|
|
11
14
|
return input;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBoolean = isBoolean;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
const TRUE_PATTERN = /^true|t|1|yes|y$/i;
|
|
3
6
|
const FALSE_PATTERN = /^false|f|0|no|n$/i;
|
|
4
7
|
/**
|
|
@@ -6,8 +9,8 @@ const FALSE_PATTERN = /^false|f|0|no|n$/i;
|
|
|
6
9
|
* Converts input value to boolean if coerce option is set to 'true'.
|
|
7
10
|
* @validator isBoolean
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
return validator('isBoolean', (input, context, _this) => {
|
|
12
|
+
function isBoolean(options) {
|
|
13
|
+
return (0, index_js_1.validator)('isBoolean', (input, context, _this) => {
|
|
11
14
|
const coerce = options?.coerce || context.coerce;
|
|
12
15
|
let output = input;
|
|
13
16
|
if (output != null && typeof output !== 'boolean' && coerce) {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDate = isDate;
|
|
4
|
+
exports.isDateString = isDateString;
|
|
5
|
+
const date_fns_1 = require("date-fns");
|
|
6
|
+
const index_js_1 = require("../../core/index.js");
|
|
3
7
|
/* eslint-disable-next-line max-len */ // noinspection RegExpUnnecessaryNonCapturingGroup
|
|
4
8
|
const DATE_PATTERN =
|
|
5
9
|
// eslint-disable-next-line max-len
|
|
@@ -9,16 +13,16 @@ const DATE_PATTERN =
|
|
|
9
13
|
* Converts input value to Date if coerce option is set to 'true'.
|
|
10
14
|
* @validator isDate
|
|
11
15
|
*/
|
|
12
|
-
|
|
16
|
+
function isDate(options) {
|
|
13
17
|
const precision = options?.precision;
|
|
14
|
-
return validator('isDate', (input, context, _this) => {
|
|
18
|
+
return (0, index_js_1.validator)('isDate', (input, context, _this) => {
|
|
15
19
|
const coerce = options?.coerce || context.coerce;
|
|
16
20
|
let d;
|
|
17
21
|
if (input instanceof Date)
|
|
18
22
|
d = input;
|
|
19
23
|
else if (input != null && coerce) {
|
|
20
24
|
if (typeof input === 'string' && coerce) {
|
|
21
|
-
d = parseISO(input);
|
|
25
|
+
d = (0, date_fns_1.parseISO)(input);
|
|
22
26
|
}
|
|
23
27
|
else if (typeof input === 'number')
|
|
24
28
|
d = new Date(input);
|
|
@@ -46,15 +50,15 @@ export function isDate(options) {
|
|
|
46
50
|
* Converts input value to DFS if coerce option is set to 'true'.
|
|
47
51
|
* @validator isDateString
|
|
48
52
|
*/
|
|
49
|
-
|
|
53
|
+
function isDateString(options) {
|
|
50
54
|
const precision = options?.precision;
|
|
51
55
|
const trim = options?.trim;
|
|
52
|
-
return validator('isDateString', (input, context, _this) => {
|
|
56
|
+
return (0, index_js_1.validator)('isDateString', (input, context, _this) => {
|
|
53
57
|
const coerce = options?.coerce || context.coerce;
|
|
54
58
|
if (typeof input === 'string') {
|
|
55
59
|
const m = DATE_PATTERN.exec(input);
|
|
56
60
|
if (m) {
|
|
57
|
-
const d = parseISO(input);
|
|
61
|
+
const d = (0, date_fns_1.parseISO)(input);
|
|
58
62
|
if (d && !isNaN(d.getTime())) {
|
|
59
63
|
if (!precision ||
|
|
60
64
|
precision === 'year' ||
|
|
@@ -86,8 +90,8 @@ export function isDateString(options) {
|
|
|
86
90
|
}
|
|
87
91
|
else if (input instanceof Date) {
|
|
88
92
|
return trim === 'date'
|
|
89
|
-
? formatISO(input, { representation: 'date' })
|
|
90
|
-
: formatISO(input).substring(0, 19);
|
|
93
|
+
? (0, date_fns_1.formatISO)(input, { representation: 'date' })
|
|
94
|
+
: (0, date_fns_1.formatISO)(input).substring(0, 19);
|
|
91
95
|
}
|
|
92
96
|
context.fail(_this, `"{{value}}" is not a valid date string`, input, {
|
|
93
97
|
...options,
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEnum = isEnum;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Validates if given value is one of enum values.
|
|
4
7
|
* @validator isEnum
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
function isEnum(values, options) {
|
|
7
10
|
const caseInSensitive = !!options?.caseInSensitive;
|
|
8
11
|
const enumName = options?.enumName;
|
|
9
12
|
// Prepare an object for fast lookup
|
|
@@ -14,7 +17,7 @@ export function isEnum(values, options) {
|
|
|
14
17
|
a[v] = true;
|
|
15
18
|
return a;
|
|
16
19
|
}, {});
|
|
17
|
-
return validator('isEnum', (input, context, _this) => {
|
|
20
|
+
return (0, index_js_1.validator)('isEnum', (input, context, _this) => {
|
|
18
21
|
if (input != null &&
|
|
19
22
|
valObj[typeof input === 'string' && caseInSensitive
|
|
20
23
|
? input.toUpperCase()
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isInteger = isInteger;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Validates if value is "integer".
|
|
4
7
|
* Converts input value to integer number if coerce option is set to 'true'.
|
|
5
8
|
* @validator isInteger
|
|
6
9
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isInteger', (input, context, _this) => {
|
|
10
|
+
function isInteger(options) {
|
|
11
|
+
return (0, index_js_1.validator)('isInteger', (input, context, _this) => {
|
|
9
12
|
const coerce = options?.coerce || context.coerce;
|
|
10
13
|
let output = input;
|
|
11
14
|
if (output != null && typeof output !== 'number' && coerce) {
|