valgen 5.2.2 → 5.3.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/CHANGELOG.md +16 -0
- package/cjs/core/context.js +7 -4
- package/cjs/core/validator.js +4 -4
- package/cjs/index.js +20 -5
- package/cjs/rules/format-rules/is-alpha.js +52 -0
- package/cjs/rules/format-rules/is-ascii.js +40 -0
- package/cjs/rules/format-rules/is-base64.js +40 -0
- package/cjs/rules/format-rules/is-btc-address.js +40 -0
- package/cjs/rules/format-rules/is-credit-card.js +40 -0
- package/cjs/rules/format-rules/is-decimal.js +41 -0
- package/cjs/rules/format-rules/is-ean.js +40 -0
- package/cjs/rules/format-rules/is-email.js +97 -0
- package/cjs/rules/format-rules/is-eth-address.js +40 -0
- package/cjs/rules/format-rules/is-fqdn.js +44 -0
- package/cjs/rules/format-rules/is-hash.js +40 -0
- package/cjs/rules/format-rules/is-hex-color.js +40 -0
- package/cjs/rules/format-rules/is-hex.js +40 -0
- package/cjs/rules/format-rules/is-iban.js +52 -0
- package/cjs/rules/format-rules/is-ip.js +52 -0
- package/cjs/rules/format-rules/is-issn.js +44 -0
- package/cjs/rules/format-rules/is-jwt.js +40 -0
- package/cjs/rules/format-rules/is-lowercase.js +52 -0
- package/cjs/rules/format-rules/is-mac-address.js +45 -0
- package/cjs/rules/format-rules/is-mobile-phone.js +43 -0
- package/cjs/rules/{is-object-id.js → format-rules/is-object-id.js} +4 -4
- package/cjs/rules/format-rules/is-passport-number.js +40 -0
- package/cjs/rules/format-rules/is-port.js +40 -0
- package/cjs/rules/format-rules/is-url.js +40 -0
- package/cjs/rules/format-rules/is-uuid.js +40 -0
- package/cjs/rules/format-rules/is-vat-number.js +40 -0
- package/cjs/rules/{is-regexp.js → format-rules/matches.js} +8 -5
- package/cjs/rules/index.js +49 -22
- package/cjs/rules/logical-rules/is-defined.js +30 -0
- package/cjs/rules/{is-empty.js → logical-rules/is-empty.js} +13 -3
- package/cjs/rules/logical-rules/range.js +114 -0
- package/cjs/rules/{is-any.js → type-rules/is-any.js} +1 -1
- package/cjs/rules/{is-array.js → type-rules/is-array.js} +5 -6
- package/cjs/rules/{is-bigint.js → type-rules/is-bigint.js} +5 -4
- package/cjs/rules/{is-boolean.js → type-rules/is-boolean.js} +5 -3
- package/cjs/rules/{is-date.js → type-rules/is-date.js} +12 -10
- package/cjs/rules/{is-enum.js → type-rules/is-enum.js} +6 -5
- package/cjs/rules/{is-integer.js → type-rules/is-integer.js} +5 -3
- package/cjs/rules/type-rules/is-null.js +34 -0
- package/cjs/rules/{is-number.js → type-rules/is-number.js} +6 -4
- package/cjs/rules/{is-object.js → type-rules/is-object.js} +5 -5
- package/cjs/rules/{is-record.js → type-rules/is-record.js} +1 -1
- package/cjs/rules/{is-string.js → type-rules/is-string.js} +3 -2
- package/cjs/rules/{is-tuple.js → type-rules/is-tuple.js} +5 -5
- package/cjs/rules/utility-rules/exists.js +16 -0
- package/cjs/rules/utility-rules/get-length.js +24 -0
- package/cjs/rules/utility-rules/optional.js +16 -0
- package/cjs/rules/{pipe.js → utility-rules/pipe.js} +1 -1
- package/cjs/rules/utility-rules/required.js +18 -0
- package/cjs/rules/{union.js → utility-rules/union.js} +3 -3
- package/esm/core/context.js +7 -4
- package/esm/core/validator.js +4 -4
- package/esm/index.js +10 -3
- package/esm/rules/format-rules/is-alpha.js +24 -0
- package/esm/rules/format-rules/is-ascii.js +13 -0
- package/esm/rules/format-rules/is-base64.js +13 -0
- package/esm/rules/format-rules/is-btc-address.js +13 -0
- package/esm/rules/format-rules/is-credit-card.js +13 -0
- package/esm/rules/format-rules/is-decimal.js +14 -0
- package/esm/rules/format-rules/is-ean.js +13 -0
- package/esm/rules/format-rules/is-email.js +70 -0
- package/esm/rules/format-rules/is-eth-address.js +13 -0
- package/esm/rules/format-rules/is-fqdn.js +17 -0
- package/esm/rules/format-rules/is-hash.js +13 -0
- package/esm/rules/format-rules/is-hex-color.js +13 -0
- package/esm/rules/format-rules/is-hex.js +13 -0
- package/esm/rules/format-rules/is-iban.js +24 -0
- package/esm/rules/format-rules/is-ip.js +24 -0
- package/esm/rules/format-rules/is-issn.js +17 -0
- package/esm/rules/format-rules/is-jwt.js +13 -0
- package/esm/rules/format-rules/is-lowercase.js +24 -0
- package/esm/rules/format-rules/is-mac-address.js +18 -0
- package/esm/rules/format-rules/is-mobile-phone.js +16 -0
- package/esm/rules/{is-object-id.js → format-rules/is-object-id.js} +4 -4
- package/esm/rules/format-rules/is-passport-number.js +13 -0
- package/esm/rules/format-rules/is-port.js +13 -0
- package/esm/rules/format-rules/is-url.js +13 -0
- package/esm/rules/format-rules/is-uuid.js +13 -0
- package/esm/rules/format-rules/is-vat-number.js +13 -0
- package/esm/rules/{is-regexp.js → format-rules/matches.js} +6 -3
- package/esm/rules/index.js +49 -22
- package/esm/rules/logical-rules/is-defined.js +25 -0
- package/esm/rules/{is-empty.js → logical-rules/is-empty.js} +13 -3
- package/esm/rules/{range.js → logical-rules/range.js} +59 -36
- package/esm/rules/{is-any.js → type-rules/is-any.js} +1 -1
- package/esm/rules/{is-array.js → type-rules/is-array.js} +5 -6
- package/esm/rules/{is-bigint.js → type-rules/is-bigint.js} +5 -4
- package/esm/rules/{is-boolean.js → type-rules/is-boolean.js} +5 -3
- package/esm/rules/{is-date.js → type-rules/is-date.js} +12 -10
- package/esm/rules/{is-enum.js → type-rules/is-enum.js} +6 -5
- package/esm/rules/{is-integer.js → type-rules/is-integer.js} +5 -3
- package/esm/rules/type-rules/is-null.js +29 -0
- package/esm/rules/{is-number.js → type-rules/is-number.js} +6 -4
- package/esm/rules/{is-object.js → type-rules/is-object.js} +5 -5
- package/esm/rules/{is-record.js → type-rules/is-record.js} +1 -1
- package/esm/rules/{is-string.js → type-rules/is-string.js} +3 -2
- package/esm/rules/{is-tuple.js → type-rules/is-tuple.js} +5 -5
- package/esm/rules/utility-rules/exists.js +12 -0
- package/esm/rules/utility-rules/get-length.js +20 -0
- package/esm/rules/utility-rules/optional.js +12 -0
- package/esm/rules/{pipe.js → utility-rules/pipe.js} +1 -1
- package/esm/rules/utility-rules/required.js +14 -0
- package/esm/rules/{union.js → utility-rules/union.js} +3 -3
- package/package.json +2 -2
- package/typings/core/types.d.ts +1 -0
- package/typings/index.d.ts +11 -4
- package/typings/rules/format-rules/is-alpha.d.ts +11 -0
- package/typings/rules/format-rules/is-ascii.d.ts +6 -0
- package/typings/rules/format-rules/is-base64.d.ts +9 -0
- package/typings/rules/format-rules/is-btc-address.d.ts +6 -0
- package/typings/rules/format-rules/is-credit-card.d.ts +9 -0
- package/typings/rules/format-rules/is-decimal.d.ts +7 -0
- package/typings/rules/format-rules/is-ean.d.ts +6 -0
- package/typings/rules/format-rules/is-email.d.ts +62 -0
- package/typings/rules/format-rules/is-eth-address.d.ts +6 -0
- package/typings/rules/format-rules/is-fqdn.d.ts +13 -0
- package/typings/rules/format-rules/is-hash.d.ts +8 -0
- package/typings/rules/format-rules/is-hex-color.d.ts +6 -0
- package/typings/rules/format-rules/is-hex.d.ts +6 -0
- package/typings/rules/format-rules/is-iban.d.ts +11 -0
- package/typings/rules/format-rules/is-ip.d.ts +11 -0
- package/typings/rules/format-rules/is-issn.d.ts +14 -0
- package/typings/rules/format-rules/is-jwt.d.ts +6 -0
- package/typings/rules/format-rules/is-lowercase.d.ts +11 -0
- package/typings/rules/format-rules/is-mac-address.d.ts +21 -0
- package/typings/rules/format-rules/is-mobile-phone.d.ts +20 -0
- package/typings/rules/{is-object-id.d.ts → format-rules/is-object-id.d.ts} +2 -2
- package/typings/rules/format-rules/is-passport-number.d.ts +6 -0
- package/typings/rules/format-rules/is-port.d.ts +6 -0
- package/typings/rules/format-rules/is-url.d.ts +9 -0
- package/typings/rules/format-rules/is-uuid.d.ts +6 -0
- package/typings/rules/format-rules/is-vat-number.d.ts +6 -0
- package/typings/rules/format-rules/matches.d.ts +9 -0
- package/typings/rules/index.d.ts +49 -22
- package/typings/rules/logical-rules/is-defined.d.ts +11 -0
- package/typings/rules/{is-empty.d.ts → logical-rules/is-empty.d.ts} +3 -3
- package/typings/rules/{range.d.ts → logical-rules/range.d.ts} +14 -4
- package/typings/rules/type-rules/is-any.d.ts +5 -0
- package/typings/rules/{is-array.d.ts → type-rules/is-array.d.ts} +2 -2
- package/typings/rules/{is-bigint.d.ts → type-rules/is-bigint.d.ts} +2 -2
- package/typings/rules/{is-boolean.d.ts → type-rules/is-boolean.d.ts} +2 -2
- package/typings/rules/{is-date.d.ts → type-rules/is-date.d.ts} +3 -3
- package/typings/rules/{is-enum.d.ts → type-rules/is-enum.d.ts} +1 -1
- package/typings/rules/{is-integer.d.ts → type-rules/is-integer.d.ts} +2 -2
- package/typings/rules/type-rules/is-null.d.ts +11 -0
- package/typings/rules/{is-number.d.ts → type-rules/is-number.d.ts} +2 -2
- package/typings/rules/{is-object.d.ts → type-rules/is-object.d.ts} +1 -1
- package/typings/rules/{is-record.d.ts → type-rules/is-record.d.ts} +2 -2
- package/typings/rules/{is-string.d.ts → type-rules/is-string.d.ts} +5 -5
- package/typings/rules/{is-tuple.d.ts → type-rules/is-tuple.d.ts} +2 -8
- package/typings/rules/utility-rules/exists.d.ts +6 -0
- package/typings/rules/utility-rules/get-length.d.ts +11 -0
- package/typings/rules/utility-rules/optional.d.ts +7 -0
- package/typings/rules/{pipe.d.ts → utility-rules/pipe.d.ts} +1 -1
- package/typings/rules/utility-rules/required.d.ts +7 -0
- package/typings/rules/utility-rules/union.d.ts +5 -0
- package/cjs/rules/is-null.js +0 -58
- package/cjs/rules/length.js +0 -41
- package/cjs/rules/optional.js +0 -44
- package/cjs/rules/range.js +0 -89
- package/cjs/rules/string-formats.js +0 -377
- package/esm/rules/is-null.js +0 -51
- package/esm/rules/length.js +0 -35
- package/esm/rules/optional.js +0 -38
- package/esm/rules/string-formats.js +0 -322
- package/typings/rules/is-any.d.ts +0 -5
- package/typings/rules/is-null.d.ts +0 -21
- package/typings/rules/is-regexp.d.ts +0 -9
- package/typings/rules/length.d.ts +0 -21
- package/typings/rules/optional.d.ts +0 -17
- package/typings/rules/string-formats.d.ts +0 -166
- package/typings/rules/union.d.ts +0 -5
package/cjs/rules/range.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.range = exports.isLte = exports.isLt = exports.isGte = exports.isGt = void 0;
|
|
4
|
-
const index_js_1 = require("../core/index.js");
|
|
5
|
-
function isGt(minValue, options) {
|
|
6
|
-
return (0, index_js_1.validator)('isGt', function (input, context, _this) {
|
|
7
|
-
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
8
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
9
|
-
input > minValue)
|
|
10
|
-
return input;
|
|
11
|
-
if (minValue instanceof Date && input instanceof Date && input > minValue)
|
|
12
|
-
return input;
|
|
13
|
-
if (typeof minValue === 'string' && typeof input === 'string' &&
|
|
14
|
-
(input > minValue ||
|
|
15
|
-
(options?.caseInsensitive && input.toLowerCase() > minValue.toLowerCase())))
|
|
16
|
-
return input;
|
|
17
|
-
context.fail(_this, `{{label}} must be greater than ${(typeof minValue === 'string' ? `"${minValue}"` : minValue)}`, input);
|
|
18
|
-
}, options);
|
|
19
|
-
}
|
|
20
|
-
exports.isGt = isGt;
|
|
21
|
-
function isGte(minValue, options) {
|
|
22
|
-
return (0, index_js_1.validator)('isGte', function (input, context, _this) {
|
|
23
|
-
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
24
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
25
|
-
input >= minValue)
|
|
26
|
-
return input;
|
|
27
|
-
if (minValue instanceof Date && input instanceof Date && input >= minValue)
|
|
28
|
-
return input;
|
|
29
|
-
if (typeof minValue === 'string' && typeof input === 'string' &&
|
|
30
|
-
(input >= minValue ||
|
|
31
|
-
(options?.caseInsensitive && input.toLowerCase() >= minValue.toLowerCase())))
|
|
32
|
-
return input;
|
|
33
|
-
context.fail(_this, `{{label}} must be greater than or equal to ${(typeof minValue === 'string' ? `"${minValue}"` : minValue)}`, input);
|
|
34
|
-
}, options);
|
|
35
|
-
}
|
|
36
|
-
exports.isGte = isGte;
|
|
37
|
-
function isLt(maxValue, options) {
|
|
38
|
-
return (0, index_js_1.validator)('isLt', function (input, context, _this) {
|
|
39
|
-
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
40
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
41
|
-
input < maxValue)
|
|
42
|
-
return input;
|
|
43
|
-
if (maxValue instanceof Date && input instanceof Date && input < maxValue)
|
|
44
|
-
return input;
|
|
45
|
-
if (typeof maxValue === 'string' && typeof input === 'string' &&
|
|
46
|
-
(input < maxValue ||
|
|
47
|
-
(options?.caseInsensitive && input.toLowerCase() < maxValue.toLowerCase())))
|
|
48
|
-
return input;
|
|
49
|
-
context.fail(_this, `{{label}} must be lover than ${(typeof maxValue === 'string' ? `"${maxValue}"` : maxValue)}`, input);
|
|
50
|
-
}, options);
|
|
51
|
-
}
|
|
52
|
-
exports.isLt = isLt;
|
|
53
|
-
function isLte(maxValue, options) {
|
|
54
|
-
return (0, index_js_1.validator)('isLt', function (input, context, _this) {
|
|
55
|
-
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
56
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
57
|
-
input <= maxValue)
|
|
58
|
-
return input;
|
|
59
|
-
if (maxValue instanceof Date && input instanceof Date && input <= maxValue)
|
|
60
|
-
return input;
|
|
61
|
-
if (typeof maxValue === 'string' && typeof input === 'string' &&
|
|
62
|
-
(input <= maxValue ||
|
|
63
|
-
(options?.caseInsensitive && input.toLowerCase() <= maxValue.toLowerCase())))
|
|
64
|
-
return input;
|
|
65
|
-
context.fail(_this, `{{label}} must be lover than or equal to ${(typeof maxValue === 'string' ? `"${maxValue}"` : maxValue)}`, input);
|
|
66
|
-
}, options);
|
|
67
|
-
}
|
|
68
|
-
exports.isLte = isLte;
|
|
69
|
-
/**
|
|
70
|
-
* Checks if value is between minValue and maxValue
|
|
71
|
-
* @validator range
|
|
72
|
-
*/
|
|
73
|
-
function range(minValue, maxValue, options) {
|
|
74
|
-
return (0, index_js_1.validator)('range', function (input, context, _this) {
|
|
75
|
-
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
76
|
-
(typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
77
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
78
|
-
input >= minValue && input <= maxValue)
|
|
79
|
-
return input;
|
|
80
|
-
if (minValue instanceof Date && maxValue instanceof Date &&
|
|
81
|
-
input instanceof Date && input >= minValue && input <= maxValue)
|
|
82
|
-
return input;
|
|
83
|
-
if (typeof minValue === 'string' && typeof maxValue === 'string' &&
|
|
84
|
-
typeof input === 'string' && input >= minValue && input <= maxValue)
|
|
85
|
-
return input;
|
|
86
|
-
context.fail(_this, `{{label}} must be between ${minValue} and ${maxValue}`, input);
|
|
87
|
-
}, options);
|
|
88
|
-
}
|
|
89
|
-
exports.range = range;
|
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isHexadecimal = exports.isDecimal = exports.isAscii = exports.isAlphanumeric = exports.isAlpha = exports.isUppercase = exports.isLowercase = exports.isJWT = exports.isHexColor = exports.isHash = exports.isETHAddress = exports.isBtcAddress = exports.isVAT = exports.isISSN = exports.isFQDN = exports.isEAN = exports.isPassportNumber = exports.isIBAN = exports.isCreditCard = exports.isBIC = exports.isBase64 = exports.isURL = exports.isPort = exports.isMACAddress = exports.isIPRange = exports.isIP = exports.isMobilePhone = exports.isEmail = exports.isUUID = void 0;
|
|
27
|
-
const validatorJS = __importStar(require("validator"));
|
|
28
|
-
const index_js_1 = require("../core/index.js");
|
|
29
|
-
/**
|
|
30
|
-
* Validates if value is an "UUID".
|
|
31
|
-
* @validator isUUID
|
|
32
|
-
*/
|
|
33
|
-
function isUUID(version, options) {
|
|
34
|
-
return (0, index_js_1.validator)('isUUID', function (input, context, _this) {
|
|
35
|
-
if (input != null && typeof input === 'string' && validatorJS.isUUID(input, version))
|
|
36
|
-
return input;
|
|
37
|
-
context.fail(_this, `{{label}} is not a valid UUID${version ? ' v' + version : ''}`, input);
|
|
38
|
-
}, options);
|
|
39
|
-
}
|
|
40
|
-
exports.isUUID = isUUID;
|
|
41
|
-
/**
|
|
42
|
-
* Validates if value is a valid Email
|
|
43
|
-
* @validator isEmail
|
|
44
|
-
*/
|
|
45
|
-
function isEmail(options) {
|
|
46
|
-
return (0, index_js_1.validator)('isEmail', function (input, context, _this) {
|
|
47
|
-
if (typeof input === 'string' && validatorJS.isEmail(input, options))
|
|
48
|
-
return input;
|
|
49
|
-
context.fail(_this, `{{label}} is not a valid a EMail`, input);
|
|
50
|
-
}, options);
|
|
51
|
-
}
|
|
52
|
-
exports.isEmail = isEmail;
|
|
53
|
-
/**
|
|
54
|
-
* Validates if value is a valid Email
|
|
55
|
-
* @validator isMobilePhone
|
|
56
|
-
*/
|
|
57
|
-
function isMobilePhone(options) {
|
|
58
|
-
return (0, index_js_1.validator)('isMobilePhone', function (input, context, _this) {
|
|
59
|
-
if (typeof input === 'string' && validatorJS.isMobilePhone(input, options?.locale, options))
|
|
60
|
-
return input;
|
|
61
|
-
context.fail(_this, `{{label}} is not a valid a Mobile Phone Number`, input);
|
|
62
|
-
}, options);
|
|
63
|
-
}
|
|
64
|
-
exports.isMobilePhone = isMobilePhone;
|
|
65
|
-
/**
|
|
66
|
-
* Validates if value is an IP
|
|
67
|
-
* @validator isIP
|
|
68
|
-
*/
|
|
69
|
-
function isIP(version, options) {
|
|
70
|
-
return (0, index_js_1.validator)('isIP', function (input, context, _this) {
|
|
71
|
-
if (input != null && typeof input === 'string' && validatorJS.isIP(input, version))
|
|
72
|
-
return input;
|
|
73
|
-
context.fail(_this, `{{label}} is not a valid IP${version ? ' v' + version : ''}`, input);
|
|
74
|
-
}, options);
|
|
75
|
-
}
|
|
76
|
-
exports.isIP = isIP;
|
|
77
|
-
/**
|
|
78
|
-
* Validates if value is an IP
|
|
79
|
-
* @validator isUUID
|
|
80
|
-
*/
|
|
81
|
-
function isIPRange(version, options) {
|
|
82
|
-
return (0, index_js_1.validator)('isIPRange', function (input, context, _this) {
|
|
83
|
-
if (input != null && typeof input === 'string' && validatorJS.isIPRange(input, version))
|
|
84
|
-
return input;
|
|
85
|
-
context.fail(_this, `{{label}} is not a valid IP${version ? ' v' + version : ''} range`, input);
|
|
86
|
-
}, options);
|
|
87
|
-
}
|
|
88
|
-
exports.isIPRange = isIPRange;
|
|
89
|
-
/**
|
|
90
|
-
* Validates if value is an MACAddress
|
|
91
|
-
* @validator isMACAddress
|
|
92
|
-
*/
|
|
93
|
-
function isMACAddress(options) {
|
|
94
|
-
return (0, index_js_1.validator)('isMACAddress', function (input, context, _this) {
|
|
95
|
-
if (input != null && typeof input === 'string' && validatorJS.isMACAddress(input, options))
|
|
96
|
-
return input;
|
|
97
|
-
context.fail(_this, `{{label}} is not a valid MAC address`, input);
|
|
98
|
-
}, options);
|
|
99
|
-
}
|
|
100
|
-
exports.isMACAddress = isMACAddress;
|
|
101
|
-
/**
|
|
102
|
-
* Validates if value is a port number
|
|
103
|
-
* @validator isPort
|
|
104
|
-
*/
|
|
105
|
-
function isPort(options) {
|
|
106
|
-
return (0, index_js_1.validator)('isPort', function (input, context, _this) {
|
|
107
|
-
if (input != null && typeof input === 'string' && validatorJS.isPort(input))
|
|
108
|
-
return input;
|
|
109
|
-
context.fail(_this, `{{label}} is not a valid port number`, input);
|
|
110
|
-
}, options);
|
|
111
|
-
}
|
|
112
|
-
exports.isPort = isPort;
|
|
113
|
-
/**
|
|
114
|
-
* Validates if value is an MACAddress
|
|
115
|
-
* @validator isURL
|
|
116
|
-
*/
|
|
117
|
-
function isURL(options) {
|
|
118
|
-
return (0, index_js_1.validator)('isURL', function (input, context, _this) {
|
|
119
|
-
if (input != null && typeof input === 'string' && validatorJS.isURL(input, options))
|
|
120
|
-
return input;
|
|
121
|
-
context.fail(_this, `{{label}} is not a valid URL`, input);
|
|
122
|
-
}, options);
|
|
123
|
-
}
|
|
124
|
-
exports.isURL = isURL;
|
|
125
|
-
/**
|
|
126
|
-
* Validates if value is a "Base64" string.
|
|
127
|
-
* @validator isBase64
|
|
128
|
-
*/
|
|
129
|
-
function isBase64(options) {
|
|
130
|
-
return (0, index_js_1.validator)('isBase64', function (input, context, _this) {
|
|
131
|
-
if (typeof input === 'string' && validatorJS.isBase64(input, options))
|
|
132
|
-
return input;
|
|
133
|
-
context.fail(_this, `{{label}} is not a valid a Base64 string`, input);
|
|
134
|
-
}, options);
|
|
135
|
-
}
|
|
136
|
-
exports.isBase64 = isBase64;
|
|
137
|
-
/**
|
|
138
|
-
* Validates if value is a BIC (Bank Identification Code) or SWIFT code
|
|
139
|
-
* @validator isBIC
|
|
140
|
-
*/
|
|
141
|
-
function isBIC(options) {
|
|
142
|
-
return (0, index_js_1.validator)('isBIC', function (input, context, _this) {
|
|
143
|
-
if (typeof input === 'string' && validatorJS.isBIC(input))
|
|
144
|
-
return input;
|
|
145
|
-
context.fail(_this, `{{label}}is not a valid a BIC (Bank Identification Code) or SWIFT code`, input);
|
|
146
|
-
}, options);
|
|
147
|
-
}
|
|
148
|
-
exports.isBIC = isBIC;
|
|
149
|
-
/**
|
|
150
|
-
* Validates if value is a "Base64" formatted string.
|
|
151
|
-
* @validator isCreditCard
|
|
152
|
-
*/
|
|
153
|
-
function isCreditCard(options) {
|
|
154
|
-
return (0, index_js_1.validator)('isCreditCard', function (input, context, _this) {
|
|
155
|
-
if (typeof input === 'string' && validatorJS.isCreditCard(input, options))
|
|
156
|
-
return input;
|
|
157
|
-
context.fail(_this, `{{label}} is not a valid Credit Card number`, input);
|
|
158
|
-
}, options);
|
|
159
|
-
}
|
|
160
|
-
exports.isCreditCard = isCreditCard;
|
|
161
|
-
/**
|
|
162
|
-
* Validates if value is an IBAN (International Bank Account Number)
|
|
163
|
-
* @validator isEAN
|
|
164
|
-
*/
|
|
165
|
-
function isIBAN(options) {
|
|
166
|
-
return (0, index_js_1.validator)('isIBAN', function (input, context, _this) {
|
|
167
|
-
if (typeof input === 'string' && validatorJS.isIBAN(input))
|
|
168
|
-
return input;
|
|
169
|
-
context.fail(_this, `{{label}} is not a valid IBAN (International Bank Account Number)`, input);
|
|
170
|
-
}, options);
|
|
171
|
-
}
|
|
172
|
-
exports.isIBAN = isIBAN;
|
|
173
|
-
/**
|
|
174
|
-
* Validates if value is an passport number
|
|
175
|
-
* @validator isPassportNumber
|
|
176
|
-
*/
|
|
177
|
-
function isPassportNumber(countryCode, options) {
|
|
178
|
-
return (0, index_js_1.validator)('isPassportNumber', function (input, context, _this) {
|
|
179
|
-
if (typeof input === 'string' && validatorJS.isPassportNumber(input, countryCode))
|
|
180
|
-
return input;
|
|
181
|
-
context.fail(_this, `{{label}} is not a valid ${countryCode} PassportNumber)`, input);
|
|
182
|
-
}, options);
|
|
183
|
-
}
|
|
184
|
-
exports.isPassportNumber = isPassportNumber;
|
|
185
|
-
/**
|
|
186
|
-
* Validates if value is an EAN (European Article Number)
|
|
187
|
-
* @validator isEAN
|
|
188
|
-
*/
|
|
189
|
-
function isEAN(options) {
|
|
190
|
-
return (0, index_js_1.validator)('isEAN', function (input, context, _this) {
|
|
191
|
-
if (typeof input === 'string' && validatorJS.isEAN(input))
|
|
192
|
-
return input;
|
|
193
|
-
context.fail(_this, `{{label}} is not a valid EAN (European Article Number)`, input);
|
|
194
|
-
}, options);
|
|
195
|
-
}
|
|
196
|
-
exports.isEAN = isEAN;
|
|
197
|
-
/**
|
|
198
|
-
* Validates if value is an FQDN
|
|
199
|
-
* @validator isFQDN
|
|
200
|
-
*/
|
|
201
|
-
function isFQDN(options) {
|
|
202
|
-
return (0, index_js_1.validator)('isFQDN', function (input, context, _this) {
|
|
203
|
-
if (typeof input === 'string' && validatorJS.isFQDN(input, options))
|
|
204
|
-
return input;
|
|
205
|
-
context.fail(_this, `{{label}} is not valid FQDN`, input);
|
|
206
|
-
}, options);
|
|
207
|
-
}
|
|
208
|
-
exports.isFQDN = isFQDN;
|
|
209
|
-
/**
|
|
210
|
-
* Validates if value is an ISSN
|
|
211
|
-
* @validator isISSN
|
|
212
|
-
*/
|
|
213
|
-
function isISSN(options) {
|
|
214
|
-
return (0, index_js_1.validator)('isISSN', function (input, context, _this) {
|
|
215
|
-
if (typeof input === 'string' && validatorJS.isISSN(input, options))
|
|
216
|
-
return input;
|
|
217
|
-
context.fail(_this, `{{label}} is not a valid ISSN`, input);
|
|
218
|
-
}, options);
|
|
219
|
-
}
|
|
220
|
-
exports.isISSN = isISSN;
|
|
221
|
-
/**
|
|
222
|
-
* Validates if value is an VAT number
|
|
223
|
-
* @validator isVAT
|
|
224
|
-
*/
|
|
225
|
-
function isVAT(countryCode, options) {
|
|
226
|
-
return (0, index_js_1.validator)('isVAT', function (input, context, _this) {
|
|
227
|
-
if (typeof input === 'string' && validatorJS.isVAT(input, countryCode))
|
|
228
|
-
return input;
|
|
229
|
-
context.fail(_this, `{{label}} is not a valid VAT number`, input);
|
|
230
|
-
}, options);
|
|
231
|
-
}
|
|
232
|
-
exports.isVAT = isVAT;
|
|
233
|
-
/**
|
|
234
|
-
* Validates if value is a BTC address.
|
|
235
|
-
* @validator isBtcAddress
|
|
236
|
-
*/
|
|
237
|
-
function isBtcAddress(options) {
|
|
238
|
-
return (0, index_js_1.validator)('isBtcAddress', function (input, context, _this) {
|
|
239
|
-
if (typeof input === 'string' && validatorJS.isBtcAddress(input))
|
|
240
|
-
return input;
|
|
241
|
-
context.fail(_this, `{{label}} is not a valid a BTC address`, input);
|
|
242
|
-
}, options);
|
|
243
|
-
}
|
|
244
|
-
exports.isBtcAddress = isBtcAddress;
|
|
245
|
-
/**
|
|
246
|
-
* Validates if value is a ETH (Ethereum) address.
|
|
247
|
-
* @validator isBtcAddress
|
|
248
|
-
*/
|
|
249
|
-
function isETHAddress(options) {
|
|
250
|
-
return (0, index_js_1.validator)('isETHAddress', function (input, context, _this) {
|
|
251
|
-
if (typeof input === 'string' && validatorJS.isEthereumAddress(input))
|
|
252
|
-
return input;
|
|
253
|
-
context.fail(_this, `{{label}} is not a valid a ETH (Ethereum) address`, input);
|
|
254
|
-
}, options);
|
|
255
|
-
}
|
|
256
|
-
exports.isETHAddress = isETHAddress;
|
|
257
|
-
/**
|
|
258
|
-
* Validates if value a hash of type algorithm
|
|
259
|
-
* @validator isHash
|
|
260
|
-
*/
|
|
261
|
-
function isHash(algorithm, options) {
|
|
262
|
-
return (0, index_js_1.validator)('isHash', function (input, context, _this) {
|
|
263
|
-
if (typeof input === 'string' && validatorJS.isHash(input, algorithm))
|
|
264
|
-
return input;
|
|
265
|
-
context.fail(_this, `{{label}} is not a valid ${algorithm} hash`, input);
|
|
266
|
-
}, options);
|
|
267
|
-
}
|
|
268
|
-
exports.isHash = isHash;
|
|
269
|
-
/**
|
|
270
|
-
* Validates if value is a Hex Color
|
|
271
|
-
* @validator isHexColor
|
|
272
|
-
*/
|
|
273
|
-
function isHexColor(options) {
|
|
274
|
-
return (0, index_js_1.validator)('isHexColor', function (input, context, _this) {
|
|
275
|
-
if (typeof input === 'string' && validatorJS.isHexColor(input))
|
|
276
|
-
return input;
|
|
277
|
-
context.fail(_this, `{{label}} is not a valid Hex Color`, input);
|
|
278
|
-
}, options);
|
|
279
|
-
}
|
|
280
|
-
exports.isHexColor = isHexColor;
|
|
281
|
-
/**
|
|
282
|
-
* Validates if value a valid JWT token
|
|
283
|
-
* @validator isHash
|
|
284
|
-
*/
|
|
285
|
-
function isJWT(options) {
|
|
286
|
-
return (0, index_js_1.validator)('isJWT', function (input, context, _this) {
|
|
287
|
-
if (typeof input === 'string' && validatorJS.isJWT(input))
|
|
288
|
-
return input;
|
|
289
|
-
context.fail(_this, `{{label}} is not a valid JWT token`, input);
|
|
290
|
-
}, options);
|
|
291
|
-
}
|
|
292
|
-
exports.isJWT = isJWT;
|
|
293
|
-
/**
|
|
294
|
-
* Validates if value a Lowercase string
|
|
295
|
-
* @validator isLowercase
|
|
296
|
-
*/
|
|
297
|
-
function isLowercase(options) {
|
|
298
|
-
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
299
|
-
if (typeof input === 'string' && validatorJS.isLowercase(input))
|
|
300
|
-
return input;
|
|
301
|
-
context.fail(_this, `{{label}} is not a lowercase string`, input);
|
|
302
|
-
}, options);
|
|
303
|
-
}
|
|
304
|
-
exports.isLowercase = isLowercase;
|
|
305
|
-
/**
|
|
306
|
-
* Validates if value a Uppercase string
|
|
307
|
-
* @validator isUppercase
|
|
308
|
-
*/
|
|
309
|
-
function isUppercase(options) {
|
|
310
|
-
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
311
|
-
if (typeof input === 'string' && validatorJS.isUppercase(input))
|
|
312
|
-
return input;
|
|
313
|
-
context.fail(_this, `{{label}} is not an uppercase string`, input);
|
|
314
|
-
}, options);
|
|
315
|
-
}
|
|
316
|
-
exports.isUppercase = isUppercase;
|
|
317
|
-
/**
|
|
318
|
-
* Check if the string contains only letters (a-zA-Z).
|
|
319
|
-
* @validator isAlpha
|
|
320
|
-
*/
|
|
321
|
-
function isAlpha(options) {
|
|
322
|
-
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
323
|
-
if (typeof input === 'string' && validatorJS.isAlpha(input))
|
|
324
|
-
return input;
|
|
325
|
-
context.fail(_this, `{{label}} is not an alpha string`, input);
|
|
326
|
-
}, options);
|
|
327
|
-
}
|
|
328
|
-
exports.isAlpha = isAlpha;
|
|
329
|
-
/**
|
|
330
|
-
* Check if the string contains only letters and numbers.
|
|
331
|
-
* @validator isAlphanumeric
|
|
332
|
-
*/
|
|
333
|
-
function isAlphanumeric(options) {
|
|
334
|
-
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
335
|
-
if (typeof input === 'string' && validatorJS.isAlphanumeric(input))
|
|
336
|
-
return input;
|
|
337
|
-
context.fail(_this, `{{label}} is not an alphanumeric string`, input);
|
|
338
|
-
}, options);
|
|
339
|
-
}
|
|
340
|
-
exports.isAlphanumeric = isAlphanumeric;
|
|
341
|
-
/**
|
|
342
|
-
* Check if the string contains ASCII chars only.
|
|
343
|
-
* @validator isAscii
|
|
344
|
-
*/
|
|
345
|
-
function isAscii(options) {
|
|
346
|
-
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
347
|
-
if (typeof input === 'string' && validatorJS.isAscii(input))
|
|
348
|
-
return input;
|
|
349
|
-
context.fail(_this, `{{label}} is not an ascii string`, input);
|
|
350
|
-
}, options);
|
|
351
|
-
}
|
|
352
|
-
exports.isAscii = isAscii;
|
|
353
|
-
/**
|
|
354
|
-
* Check if the string represents a decimal number,
|
|
355
|
-
* such as `0.1`, `.3`, `1.1`, `1.00003`, `4.0` etc.
|
|
356
|
-
* @validator isDecimal
|
|
357
|
-
*/
|
|
358
|
-
function isDecimal(options) {
|
|
359
|
-
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
360
|
-
if (typeof input === 'string' && validatorJS.isDecimal(input))
|
|
361
|
-
return input;
|
|
362
|
-
context.fail(_this, `{{label}} is not an decimal number string`, input);
|
|
363
|
-
}, options);
|
|
364
|
-
}
|
|
365
|
-
exports.isDecimal = isDecimal;
|
|
366
|
-
/**
|
|
367
|
-
* Check if the string is a hexadecimal number.
|
|
368
|
-
* @validator isHexadecimal
|
|
369
|
-
*/
|
|
370
|
-
function isHexadecimal(options) {
|
|
371
|
-
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
372
|
-
if (typeof input === 'string' && validatorJS.isHexadecimal(input))
|
|
373
|
-
return input;
|
|
374
|
-
context.fail(_this, `{{label}} is not an hexadecimal string`, input);
|
|
375
|
-
}, options);
|
|
376
|
-
}
|
|
377
|
-
exports.isHexadecimal = isHexadecimal;
|
package/esm/rules/is-null.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { validator } from '../core/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Validates if value is "null".
|
|
4
|
-
* @validator isNull
|
|
5
|
-
*/
|
|
6
|
-
export function isNull(options) {
|
|
7
|
-
return validator('isNull', function (input, context, _this) {
|
|
8
|
-
if (input === null)
|
|
9
|
-
return input;
|
|
10
|
-
if (context.coerce)
|
|
11
|
-
return null;
|
|
12
|
-
context.fail(_this, `{{label}} must be null`, input);
|
|
13
|
-
}, options);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Validates if value is "null" or "undefined".
|
|
17
|
-
* @validator isNull
|
|
18
|
-
*/
|
|
19
|
-
export function isNullish(options) {
|
|
20
|
-
return validator('isNullish', function (input, context, _this) {
|
|
21
|
-
if (input == null)
|
|
22
|
-
return input;
|
|
23
|
-
if (context.coerce)
|
|
24
|
-
return null;
|
|
25
|
-
context.fail(_this, `{{label}} must be null or undefined`, input);
|
|
26
|
-
}, options);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Validates if value is not "undefined" nor "null"
|
|
30
|
-
* @validator isDefined
|
|
31
|
-
*/
|
|
32
|
-
export function isDefined(options) {
|
|
33
|
-
return validator('is-defined', function (input, context, _this) {
|
|
34
|
-
if (input !== undefined)
|
|
35
|
-
return input;
|
|
36
|
-
context.fail(_this, `{{label}} must be defined`, input);
|
|
37
|
-
}, options);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Validates if value is "undefined"
|
|
41
|
-
* @validator isUndefined
|
|
42
|
-
*/
|
|
43
|
-
export function isUndefined(options) {
|
|
44
|
-
return validator('isUndefined', function (input, context, _this) {
|
|
45
|
-
if (context.coerce)
|
|
46
|
-
return undefined;
|
|
47
|
-
if (input === undefined)
|
|
48
|
-
return;
|
|
49
|
-
context.fail(_this, `{{label}} mustn\'t be defined`, input);
|
|
50
|
-
}, options);
|
|
51
|
-
}
|
package/esm/rules/length.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { validator } from '../core/index.js';
|
|
2
|
-
import { allOf, pipe } from './pipe.js';
|
|
3
|
-
import { isGte, isLte } from './range.js';
|
|
4
|
-
/**
|
|
5
|
-
* Returns length of an Array, String, ArrayBuffer, Buffer or any object with the "length" property.
|
|
6
|
-
* @validator getLength
|
|
7
|
-
*/
|
|
8
|
-
export const extractLength = () => extractLengthRule;
|
|
9
|
-
const extractLengthRule = validator('extractLength', function (input, context, _this) {
|
|
10
|
-
if (typeof input === 'string')
|
|
11
|
-
return input.length;
|
|
12
|
-
if (Array.isArray(input))
|
|
13
|
-
return input.length;
|
|
14
|
-
if (input instanceof ArrayBuffer)
|
|
15
|
-
return input.byteLength;
|
|
16
|
-
if (input && typeof input === 'object' && typeof input.length === 'number')
|
|
17
|
-
return input.length;
|
|
18
|
-
if (input && typeof input === 'object' && typeof input.size === 'number')
|
|
19
|
-
return input.size;
|
|
20
|
-
context.fail(_this, `Unable to extract length of {{label}}`, input);
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* Checks the length is at least "minValue"
|
|
24
|
-
* @validator lengthMin
|
|
25
|
-
*/
|
|
26
|
-
export const lengthMin = (minValue) => allOf(pipe(extractLength(), isGte(minValue, {
|
|
27
|
-
onFail: () => `The length of {{label}} must be at least ${minValue}`
|
|
28
|
-
})));
|
|
29
|
-
/**
|
|
30
|
-
* Checks if the length is at most "maxValue"
|
|
31
|
-
* @validator charLengthMax
|
|
32
|
-
*/
|
|
33
|
-
export const lengthMax = (maxValue) => allOf(pipe(extractLength(), isLte(maxValue, {
|
|
34
|
-
onFail: () => `The length of {{label}} must be at most ${maxValue}`
|
|
35
|
-
})));
|
package/esm/rules/optional.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { validator } from '../core/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Makes sub-rule optional
|
|
4
|
-
* @validator optional
|
|
5
|
-
*/
|
|
6
|
-
export function optional(nested, options) {
|
|
7
|
-
return validator('optional', function (input, context) {
|
|
8
|
-
if (input == null)
|
|
9
|
-
return input;
|
|
10
|
-
return nested(input, context);
|
|
11
|
-
}, options);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Makes sub-rule required
|
|
15
|
-
* @validator required
|
|
16
|
-
*/
|
|
17
|
-
export function required(nested, options) {
|
|
18
|
-
return validator('required', function (input, context, _this) {
|
|
19
|
-
if (input == null) {
|
|
20
|
-
context.fail(_this, `{{label}} is required`, input);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
return nested(input, context);
|
|
24
|
-
}, options);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Validates if property exists
|
|
28
|
-
* @validator exists
|
|
29
|
-
*/
|
|
30
|
-
export function exists(options) {
|
|
31
|
-
return validator('exists', function (input, context, _this) {
|
|
32
|
-
if (input !== undefined ||
|
|
33
|
-
(context.scope &&
|
|
34
|
-
Object.getOwnPropertyDescriptor(context.scope, input)))
|
|
35
|
-
return input;
|
|
36
|
-
context.fail(_this, `{{label}} must exist`, input);
|
|
37
|
-
}, options);
|
|
38
|
-
}
|