valgen 5.4.1 → 5.6.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 +18 -0
- package/cjs/core/context.js +13 -10
- package/cjs/core/index.js +2 -2
- package/cjs/core/utilities.js +4 -5
- package/cjs/core/validator.js +10 -7
- package/cjs/helpers/object.utils.js +2 -3
- package/cjs/helpers/omit-undefined.js +1 -2
- package/cjs/helpers/string.utils.js +2 -5
- package/cjs/index.js +6 -2
- package/cjs/rules/format-rules/is-alpha.js +6 -6
- package/cjs/rules/format-rules/is-ascii.js +2 -3
- package/cjs/rules/format-rules/is-base64.js +4 -4
- package/cjs/rules/format-rules/is-btc-address.js +4 -4
- package/cjs/rules/format-rules/is-credit-card.js +5 -4
- package/cjs/rules/format-rules/is-decimal.js +4 -4
- package/cjs/rules/format-rules/is-ean.js +2 -3
- package/cjs/rules/format-rules/is-email.js +4 -4
- package/cjs/rules/format-rules/is-eth-address.js +4 -4
- package/cjs/rules/format-rules/is-fqdn.js +4 -4
- package/cjs/rules/format-rules/is-hash.js +4 -4
- package/cjs/rules/format-rules/is-hex-color.js +4 -4
- package/cjs/rules/format-rules/is-hex.js +4 -4
- package/cjs/rules/format-rules/is-iban.js +4 -5
- package/cjs/rules/format-rules/is-ip.js +12 -7
- package/cjs/rules/format-rules/is-issn.js +4 -4
- package/cjs/rules/format-rules/is-jwt.js +2 -3
- package/cjs/rules/format-rules/is-lowercase.js +8 -7
- package/cjs/rules/format-rules/is-mac-address.js +6 -4
- package/cjs/rules/format-rules/is-mobile-phone.js +5 -4
- package/cjs/rules/format-rules/is-object-id.js +7 -5
- package/cjs/rules/format-rules/is-passport-number.js +5 -4
- package/cjs/rules/format-rules/is-port.js +6 -4
- package/cjs/rules/format-rules/is-url.js +6 -4
- package/cjs/rules/format-rules/is-uuid.js +6 -4
- package/cjs/rules/format-rules/is-vat-number.js +4 -4
- package/cjs/rules/format-rules/matches.js +2 -3
- package/cjs/rules/index.js +14 -13
- package/cjs/rules/logical-rules/is-defined.js +2 -17
- package/cjs/rules/logical-rules/is-empty.js +4 -5
- package/cjs/rules/logical-rules/range.js +57 -26
- package/cjs/rules/type-rules/is-any.js +1 -3
- package/cjs/rules/type-rules/is-array.js +5 -4
- package/cjs/rules/type-rules/is-bigint.js +5 -4
- package/cjs/rules/type-rules/is-boolean.js +2 -3
- package/cjs/rules/type-rules/is-date.js +13 -8
- package/cjs/rules/type-rules/is-enum.js +7 -4
- package/cjs/rules/type-rules/is-integer.js +11 -5
- package/cjs/rules/type-rules/is-null.js +34 -14
- package/cjs/rules/type-rules/is-number.js +7 -4
- package/cjs/rules/type-rules/is-object.js +20 -12
- package/cjs/rules/type-rules/is-record.js +2 -3
- package/cjs/rules/type-rules/is-string.js +11 -11
- package/cjs/rules/type-rules/is-tuple.js +7 -5
- package/cjs/rules/type-rules/is-undefined.js +17 -0
- package/cjs/rules/utility-rules/exists.js +6 -4
- package/cjs/rules/utility-rules/get-length.js +10 -5
- package/cjs/rules/utility-rules/optional.js +2 -3
- package/cjs/rules/utility-rules/pipe.js +5 -6
- package/cjs/rules/utility-rules/required.js +2 -3
- package/cjs/rules/utility-rules/union.js +2 -3
- package/esm/core/context.js +13 -10
- package/esm/core/index.js +2 -2
- package/esm/core/utilities.js +3 -3
- package/esm/core/validator.js +8 -4
- package/esm/helpers/string.utils.js +1 -3
- package/esm/index.js +3 -1
- package/esm/rules/format-rules/is-alpha.js +4 -3
- package/esm/rules/format-rules/is-ascii.js +1 -1
- package/esm/rules/format-rules/is-base64.js +3 -2
- package/esm/rules/format-rules/is-btc-address.js +3 -2
- package/esm/rules/format-rules/is-credit-card.js +4 -2
- package/esm/rules/format-rules/is-decimal.js +3 -2
- package/esm/rules/format-rules/is-ean.js +1 -1
- package/esm/rules/format-rules/is-email.js +3 -2
- package/esm/rules/format-rules/is-eth-address.js +3 -2
- package/esm/rules/format-rules/is-fqdn.js +3 -2
- package/esm/rules/format-rules/is-hash.js +3 -2
- package/esm/rules/format-rules/is-hex-color.js +3 -2
- package/esm/rules/format-rules/is-hex.js +3 -2
- package/esm/rules/format-rules/is-iban.js +2 -2
- package/esm/rules/format-rules/is-ip.js +10 -4
- package/esm/rules/format-rules/is-issn.js +3 -2
- package/esm/rules/format-rules/is-jwt.js +1 -1
- package/esm/rules/format-rules/is-lowercase.js +6 -4
- package/esm/rules/format-rules/is-mac-address.js +5 -2
- package/esm/rules/format-rules/is-mobile-phone.js +4 -2
- package/esm/rules/format-rules/is-object-id.js +7 -4
- package/esm/rules/format-rules/is-passport-number.js +4 -2
- package/esm/rules/format-rules/is-port.js +5 -2
- package/esm/rules/format-rules/is-url.js +5 -2
- package/esm/rules/format-rules/is-uuid.js +5 -2
- package/esm/rules/format-rules/is-vat-number.js +3 -2
- package/esm/rules/format-rules/matches.js +2 -2
- package/esm/rules/index.js +14 -13
- package/esm/rules/logical-rules/is-defined.js +1 -14
- package/esm/rules/logical-rules/is-empty.js +2 -2
- package/esm/rules/logical-rules/range.js +52 -21
- package/esm/rules/type-rules/is-any.js +1 -3
- package/esm/rules/type-rules/is-array.js +5 -3
- package/esm/rules/type-rules/is-bigint.js +4 -2
- package/esm/rules/type-rules/is-boolean.js +2 -2
- package/esm/rules/type-rules/is-date.js +11 -5
- package/esm/rules/type-rules/is-enum.js +7 -3
- package/esm/rules/type-rules/is-integer.js +11 -4
- package/esm/rules/type-rules/is-null.js +30 -11
- package/esm/rules/type-rules/is-number.js +6 -2
- package/esm/rules/type-rules/is-object.js +19 -10
- package/esm/rules/type-rules/is-record.js +2 -2
- package/esm/rules/type-rules/is-string.js +7 -7
- package/esm/rules/type-rules/is-tuple.js +7 -4
- package/esm/rules/type-rules/is-undefined.js +14 -0
- package/esm/rules/utility-rules/exists.js +5 -2
- package/esm/rules/utility-rules/get-length.js +9 -3
- package/esm/rules/utility-rules/optional.js +2 -2
- package/esm/rules/utility-rules/pipe.js +4 -4
- package/esm/rules/utility-rules/required.js +2 -2
- package/esm/rules/utility-rules/union.js +1 -1
- package/package.json +2 -2
- package/typings/core/index.d.ts +3 -3
- package/typings/core/types.d.ts +1 -1
- package/typings/index.d.ts +3 -1
- package/typings/rules/index.d.ts +14 -13
- package/typings/rules/logical-rules/is-defined.d.ts +0 -5
- package/typings/rules/type-rules/is-null.d.ts +11 -1
- package/typings/rules/type-rules/is-tuple.d.ts +36 -4
- package/typings/rules/type-rules/is-undefined.d.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
# v5.6.0
|
|
2
|
+
[2024-07-14]
|
|
3
|
+
|
|
4
|
+
### Changes
|
|
5
|
+
|
|
6
|
+
* Added isNotNull and isNotNullish rules ([`19902a5`](https://github.com/panates/valgen/commit/19902a5e2a12f1958952671ffce6e2eab77457a5))
|
|
7
|
+
* Added isNotNull and isNotNullish rules ([`ff881d6`](https://github.com/panates/valgen/commit/ff881d6be81068c70e020109485b91854c355598))
|
|
8
|
+
|
|
9
|
+
# v5.5.0
|
|
10
|
+
[2024-07-14]
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
|
|
14
|
+
* Moved eslint config to @panates/eslint-config ([`c2f3e2d`](https://github.com/panates/valgen/commit/c2f3e2dfec484fe891de3b519b7f26779c451b43))
|
|
15
|
+
* Changed error message ([`3edf948`](https://github.com/panates/valgen/commit/3edf948a674d11a4ff5efcb97ca255b0723a11ca))
|
|
16
|
+
* Removed coercing of isNull and isNullish rules ([`4337d0a`](https://github.com/panates/valgen/commit/4337d0a4bd148718f33f744257b13afdd5c3ac50))
|
|
17
|
+
* Now pipe can return original input value when returnIndex = -1 ([`baf698c`](https://github.com/panates/valgen/commit/baf698c289254743d70ef815188f2300d7230f00))
|
|
18
|
+
|
|
1
19
|
# v5.4.1
|
|
2
20
|
[2024-05-18]
|
|
3
21
|
|
package/cjs/core/context.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Context = void 0;
|
|
4
4
|
const omit_undefined_js_1 = require("../helpers/omit-undefined.js");
|
|
5
|
-
const constants_js_1 = require("./constants.js");
|
|
6
5
|
const validation_error_js_1 = require("./validation-error.js");
|
|
7
6
|
const VARIABLE_REPLACE_PATTERN = /{{([^}]*)}}/g;
|
|
8
7
|
const OPTIONAL_VAR_PATTERN = /^([^?]+)(?:\||(.*))?$/;
|
|
@@ -25,11 +24,8 @@ class Context {
|
|
|
25
24
|
...details,
|
|
26
25
|
});
|
|
27
26
|
issue.value = value;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const proto = Object.getPrototypeOf(this);
|
|
31
|
-
const superOnFail = proto.onFail !== onFail ? proto.onFail : undefined;
|
|
32
|
-
const x = onFail(issue, this, superOnFail);
|
|
27
|
+
if (this.onFail) {
|
|
28
|
+
const x = this.onFail(issue, this);
|
|
33
29
|
if (!x)
|
|
34
30
|
return;
|
|
35
31
|
if (typeof x === 'object')
|
|
@@ -47,8 +43,9 @@ class Context {
|
|
|
47
43
|
const s = String(issue.value);
|
|
48
44
|
return s.length < 30 ? s : s.substring(0, 30) + '..';
|
|
49
45
|
}
|
|
50
|
-
if (!v && k === 'label' && (this.location || this.property))
|
|
46
|
+
if (!v && k === 'label' && (this.location || this.property)) {
|
|
51
47
|
v = '`' + (this.location || this.property) + '`';
|
|
48
|
+
}
|
|
52
49
|
if (v != null)
|
|
53
50
|
return v;
|
|
54
51
|
if (m[2])
|
|
@@ -56,13 +53,19 @@ class Context {
|
|
|
56
53
|
return m[1] === 'label' ? 'Value' : x;
|
|
57
54
|
});
|
|
58
55
|
this.errors.push(issue);
|
|
59
|
-
if (this.errors.length >= (this.maxErrors ?? Infinity))
|
|
56
|
+
if (this.errors.length >= (this.maxErrors ?? Infinity)) {
|
|
60
57
|
throw new validation_error_js_1.ValidationError(this.errors);
|
|
58
|
+
}
|
|
61
59
|
}
|
|
62
60
|
extend(options) {
|
|
63
|
-
const extended =
|
|
61
|
+
const extended = {};
|
|
62
|
+
if (options) {
|
|
63
|
+
for (const [k, v] of Object.entries(options)) {
|
|
64
|
+
if (v !== undefined)
|
|
65
|
+
extended[k] = v;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
64
68
|
Object.setPrototypeOf(extended, this);
|
|
65
|
-
delete extended.errors;
|
|
66
69
|
return extended;
|
|
67
70
|
}
|
|
68
71
|
}
|
package/cjs/core/index.js
CHANGED
|
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./context.js"), exports);
|
|
18
17
|
__exportStar(require("./constants.js"), exports);
|
|
18
|
+
__exportStar(require("./context.js"), exports);
|
|
19
19
|
__exportStar(require("./types.js"), exports);
|
|
20
|
+
__exportStar(require("./utilities.js"), exports);
|
|
20
21
|
__exportStar(require("./validation-error.js"), exports);
|
|
21
22
|
__exportStar(require("./validator.js"), exports);
|
|
22
|
-
__exportStar(require("./utilities.js"), exports);
|
package/cjs/core/utilities.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.forwardRef = forwardRef;
|
|
4
|
+
exports.iif = iif;
|
|
4
5
|
const index_js_1 = require("./index.js");
|
|
5
6
|
/**
|
|
6
7
|
* Forwards codec process to a sub codec. Useful for circular checks
|
|
7
8
|
* @validator forwardRef
|
|
8
9
|
*/
|
|
9
10
|
function forwardRef(fn) {
|
|
10
|
-
return (0, index_js_1.validator)('forwardRef',
|
|
11
|
+
return (0, index_js_1.validator)('forwardRef', (input, context) => {
|
|
11
12
|
const nested = fn(context);
|
|
12
13
|
return nested(input, context);
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
|
-
exports.forwardRef = forwardRef;
|
|
16
16
|
function iif(check, _then, _else) {
|
|
17
|
-
return (0, index_js_1.validator)('iif',
|
|
17
|
+
return (0, index_js_1.validator)('iif', (input, context) => {
|
|
18
18
|
let c = _else;
|
|
19
19
|
try {
|
|
20
20
|
if (check(input) !== undefined)
|
|
@@ -28,4 +28,3 @@ function iif(check, _then, _else) {
|
|
|
28
28
|
return c;
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
exports.iif = iif;
|
package/cjs/core/validator.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validator = validator;
|
|
4
|
+
exports.isValidator = isValidator;
|
|
4
5
|
const string_utils_js_1 = require("../helpers/string.utils.js");
|
|
5
6
|
const constants_js_1 = require("./constants.js");
|
|
6
7
|
const context_js_1 = require("./context.js");
|
|
7
8
|
const validation_error_js_1 = require("./validation-error.js");
|
|
9
|
+
let unnamedValidatorIndex = 0;
|
|
8
10
|
function validator(arg0, arg1, arg2) {
|
|
9
11
|
let id = '';
|
|
10
12
|
let fn;
|
|
@@ -18,15 +20,17 @@ function validator(arg0, arg1, arg2) {
|
|
|
18
20
|
fn = arg0;
|
|
19
21
|
validatorOptions = arg1;
|
|
20
22
|
}
|
|
21
|
-
if (typeof fn !== 'function')
|
|
23
|
+
if (typeof fn !== 'function') {
|
|
22
24
|
throw new TypeError('You must provide a rule function argument');
|
|
23
|
-
|
|
25
|
+
}
|
|
26
|
+
id = id || fn.name || 'validator' + ++unnamedValidatorIndex;
|
|
24
27
|
const name = fn.name || (0, string_utils_js_1.camelCase)(id);
|
|
25
28
|
const _rule = {
|
|
26
29
|
[name](input, options) {
|
|
27
30
|
const ctx = options instanceof context_js_1.Context ? options : undefined;
|
|
28
31
|
const opts = ctx ? undefined : options;
|
|
29
|
-
const context = ctx
|
|
32
|
+
const context = ctx?.extend({ ...validatorOptions, ...opts }) ||
|
|
33
|
+
new context_js_1.Context({ ...validatorOptions, ...opts });
|
|
30
34
|
let value;
|
|
31
35
|
try {
|
|
32
36
|
value = fn(input, context, _rule);
|
|
@@ -36,8 +40,9 @@ function validator(arg0, arg1, arg2) {
|
|
|
36
40
|
throw e;
|
|
37
41
|
context.fail(_rule, e, input);
|
|
38
42
|
}
|
|
39
|
-
if (!ctx && context.errors.length)
|
|
43
|
+
if (!ctx && context.errors.length) {
|
|
40
44
|
throw new validation_error_js_1.ValidationError(context.errors);
|
|
45
|
+
}
|
|
41
46
|
return value;
|
|
42
47
|
},
|
|
43
48
|
}[name];
|
|
@@ -55,8 +60,6 @@ function validator(arg0, arg1, arg2) {
|
|
|
55
60
|
};
|
|
56
61
|
return _rule;
|
|
57
62
|
}
|
|
58
|
-
exports.validator = validator;
|
|
59
63
|
function isValidator(x) {
|
|
60
64
|
return !!(typeof x === 'function' && x.id && x[constants_js_1.kValidatorFn]);
|
|
61
65
|
}
|
|
62
|
-
exports.isValidator = isValidator;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.omitKeys = omitKeys;
|
|
4
|
+
exports.pickKeys = pickKeys;
|
|
4
5
|
function omitKeys(o, keys) {
|
|
5
6
|
return Object.keys(o).reduce((a, k) => {
|
|
6
7
|
if (!keys.includes(k))
|
|
@@ -8,7 +9,6 @@ function omitKeys(o, keys) {
|
|
|
8
9
|
return a;
|
|
9
10
|
}, {});
|
|
10
11
|
}
|
|
11
|
-
exports.omitKeys = omitKeys;
|
|
12
12
|
function pickKeys(o, keys) {
|
|
13
13
|
return Object.keys(o).reduce((a, k) => {
|
|
14
14
|
if (keys.includes(k))
|
|
@@ -16,4 +16,3 @@ function pickKeys(o, keys) {
|
|
|
16
16
|
return a;
|
|
17
17
|
}, {});
|
|
18
18
|
}
|
|
19
|
-
exports.pickKeys = pickKeys;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.omitUndefined =
|
|
3
|
+
exports.omitUndefined = omitUndefined;
|
|
4
4
|
function omitUndefined(obj, recursive) {
|
|
5
5
|
if (!(obj && typeof obj === 'object'))
|
|
6
6
|
return obj;
|
|
@@ -12,4 +12,3 @@ function omitUndefined(obj, recursive) {
|
|
|
12
12
|
}
|
|
13
13
|
return obj;
|
|
14
14
|
}
|
|
15
|
-
exports.omitUndefined = omitUndefined;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.camelCase =
|
|
3
|
+
exports.camelCase = camelCase;
|
|
4
4
|
function camelCase(v) {
|
|
5
|
-
return v.replace(/[\W_\s]+([^\W_\s])/g, (arg$, c) =>
|
|
6
|
-
return c[0].toUpperCase();
|
|
7
|
-
});
|
|
5
|
+
return v.replace(/[\W_\s]+([^\W_\s])/g, (arg$, c) => c[0].toUpperCase());
|
|
8
6
|
}
|
|
9
|
-
exports.camelCase = camelCase;
|
package/cjs/index.js
CHANGED
|
@@ -26,8 +26,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
exports.toString = exports.toNumber = exports.toInteger = exports.toDateString = exports.toDate = exports.toBigint = exports.
|
|
29
|
+
exports.isUUID5 = exports.isUUID4 = exports.isUUID3 = exports.isUUID2 = exports.isUUID1 = exports.isUUID = exports.isURL = exports.isUppercase = exports.isUndefined = exports.isSWIFT = exports.isString = exports.isPort = exports.isObjectId = exports.isObject = exports.isNumber = exports.isNullish = exports.isNull = exports.isNotNullish = exports.isNotNull = exports.isNotEmpty = exports.isMobilePhone = exports.isMACAddress = exports.isLowercase = exports.isJWT = exports.isISSN = exports.isIPRange = exports.isIP = exports.isInteger = exports.isIBAN = exports.isHexColor = exports.isHex = exports.isFQDN = exports.isETHAddress = exports.isEmpty = exports.isEmail = exports.isEAN = exports.isDefined = exports.isDecimal = exports.isDateString = exports.isDate = exports.isCreditCard = exports.isBtcAddress = exports.isBoolean = exports.isBigint = exports.isBase64 = exports.isAscii = exports.isArray = exports.isAny = exports.isAlphanumeric = exports.isAlpha = void 0;
|
|
30
|
+
exports.vg = exports.toString = exports.toNumber = exports.toInteger = exports.toDateString = exports.toDate = exports.toBoolean = exports.toBigint = exports.toArray = void 0;
|
|
31
31
|
const vg = __importStar(require("./rules/index.js"));
|
|
32
32
|
exports.vg = vg;
|
|
33
33
|
__exportStar(require("./constants.js"), exports);
|
|
@@ -52,8 +52,12 @@ const isInteger = vg.isInteger();
|
|
|
52
52
|
exports.isInteger = isInteger;
|
|
53
53
|
const isNull = vg.isNull();
|
|
54
54
|
exports.isNull = isNull;
|
|
55
|
+
const isNotNull = vg.isNotNull();
|
|
56
|
+
exports.isNotNull = isNotNull;
|
|
55
57
|
const isNullish = vg.isNullish();
|
|
56
58
|
exports.isNullish = isNullish;
|
|
59
|
+
const isNotNullish = vg.isNotNullish();
|
|
60
|
+
exports.isNotNullish = isNotNullish;
|
|
57
61
|
const isDefined = vg.isDefined();
|
|
58
62
|
exports.isDefined = isDefined;
|
|
59
63
|
const isUndefined = vg.isUndefined();
|
|
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.isAlpha = isAlpha;
|
|
27
|
+
exports.isAlphanumeric = isAlphanumeric;
|
|
27
28
|
const validatorJS = __importStar(require("validator"));
|
|
28
29
|
const index_js_1 = require("../../core/index.js");
|
|
29
30
|
/**
|
|
@@ -31,22 +32,21 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
32
|
* @validator isAlpha
|
|
32
33
|
*/
|
|
33
34
|
function isAlpha(options) {
|
|
34
|
-
return (0, index_js_1.validator)('isLowercase',
|
|
35
|
+
return (0, index_js_1.validator)('isLowercase', (input, context, _this) => {
|
|
35
36
|
if (typeof input === 'string' && validatorJS.isAlpha(input))
|
|
36
37
|
return input;
|
|
37
38
|
context.fail(_this, `"{{value}}" is not an alpha string`, input);
|
|
38
39
|
}, options);
|
|
39
40
|
}
|
|
40
|
-
exports.isAlpha = isAlpha;
|
|
41
41
|
/**
|
|
42
42
|
* Check if the string contains only letters and numbers.
|
|
43
43
|
* @validator isAlphanumeric
|
|
44
44
|
*/
|
|
45
45
|
function isAlphanumeric(options) {
|
|
46
|
-
return (0, index_js_1.validator)('isAlphanumeric',
|
|
47
|
-
if (typeof input === 'string' && validatorJS.isAlphanumeric(input))
|
|
46
|
+
return (0, index_js_1.validator)('isAlphanumeric', (input, context, _this) => {
|
|
47
|
+
if (typeof input === 'string' && validatorJS.isAlphanumeric(input)) {
|
|
48
48
|
return input;
|
|
49
|
+
}
|
|
49
50
|
context.fail(_this, `"{{value}}" is not an alphanumeric string`, input);
|
|
50
51
|
}, options);
|
|
51
52
|
}
|
|
52
|
-
exports.isAlphanumeric = isAlphanumeric;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isAscii =
|
|
26
|
+
exports.isAscii = isAscii;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -31,10 +31,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
31
|
* @validator isAscii
|
|
32
32
|
*/
|
|
33
33
|
function isAscii(options) {
|
|
34
|
-
return (0, index_js_1.validator)('isAscii',
|
|
34
|
+
return (0, index_js_1.validator)('isAscii', (input, context, _this) => {
|
|
35
35
|
if (typeof input === 'string' && validatorJS.isAscii(input))
|
|
36
36
|
return input;
|
|
37
37
|
context.fail(_this, `Value is not an ascii string`, input);
|
|
38
38
|
}, options);
|
|
39
39
|
}
|
|
40
|
-
exports.isAscii = isAscii;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isBase64 =
|
|
26
|
+
exports.isBase64 = isBase64;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
31
|
* @validator isBase64
|
|
32
32
|
*/
|
|
33
33
|
function isBase64(options) {
|
|
34
|
-
return (0, index_js_1.validator)('isBase64',
|
|
35
|
-
if (typeof input === 'string' && validatorJS.isBase64(input, options))
|
|
34
|
+
return (0, index_js_1.validator)('isBase64', (input, context, _this) => {
|
|
35
|
+
if (typeof input === 'string' && validatorJS.isBase64(input, options)) {
|
|
36
36
|
return input;
|
|
37
|
+
}
|
|
37
38
|
context.fail(_this, `"{{value}}" is not a valid a Base64 string`, input);
|
|
38
39
|
}, options);
|
|
39
40
|
}
|
|
40
|
-
exports.isBase64 = isBase64;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isBtcAddress =
|
|
26
|
+
exports.isBtcAddress = isBtcAddress;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
31
|
* @validator isBtcAddress
|
|
32
32
|
*/
|
|
33
33
|
function isBtcAddress(options) {
|
|
34
|
-
return (0, index_js_1.validator)('isBtcAddress',
|
|
35
|
-
if (typeof input === 'string' && validatorJS.isBtcAddress(input))
|
|
34
|
+
return (0, index_js_1.validator)('isBtcAddress', (input, context, _this) => {
|
|
35
|
+
if (typeof input === 'string' && validatorJS.isBtcAddress(input)) {
|
|
36
36
|
return input;
|
|
37
|
+
}
|
|
37
38
|
context.fail(_this, `Value is not a valid a BTC address`, input);
|
|
38
39
|
}, options);
|
|
39
40
|
}
|
|
40
|
-
exports.isBtcAddress = isBtcAddress;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isCreditCard =
|
|
26
|
+
exports.isCreditCard = isCreditCard;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -31,10 +31,11 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
31
|
* @validator isCreditCard
|
|
32
32
|
*/
|
|
33
33
|
function isCreditCard(options) {
|
|
34
|
-
return (0, index_js_1.validator)('isCreditCard',
|
|
35
|
-
if (typeof input === 'string' &&
|
|
34
|
+
return (0, index_js_1.validator)('isCreditCard', (input, context, _this) => {
|
|
35
|
+
if (typeof input === 'string' &&
|
|
36
|
+
validatorJS.isCreditCard(input, options)) {
|
|
36
37
|
return input;
|
|
38
|
+
}
|
|
37
39
|
context.fail(_this, `"{{value}}" is not a valid Credit Card number`, input);
|
|
38
40
|
}, options);
|
|
39
41
|
}
|
|
40
|
-
exports.isCreditCard = isCreditCard;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isDecimal =
|
|
26
|
+
exports.isDecimal = isDecimal;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -32,10 +32,10 @@ const index_js_1 = require("../../core/index.js");
|
|
|
32
32
|
* @validator isDecimal
|
|
33
33
|
*/
|
|
34
34
|
function isDecimal(options) {
|
|
35
|
-
return (0, index_js_1.validator)('isDecimal',
|
|
36
|
-
if (typeof input === 'string' && validatorJS.isDecimal(input))
|
|
35
|
+
return (0, index_js_1.validator)('isDecimal', (input, context, _this) => {
|
|
36
|
+
if (typeof input === 'string' && validatorJS.isDecimal(input)) {
|
|
37
37
|
return input;
|
|
38
|
+
}
|
|
38
39
|
context.fail(_this, `"{{value}}" is not an decimal number string`, input);
|
|
39
40
|
}, options);
|
|
40
41
|
}
|
|
41
|
-
exports.isDecimal = isDecimal;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isEAN =
|
|
26
|
+
exports.isEAN = isEAN;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -31,10 +31,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
31
|
* @validator isEAN
|
|
32
32
|
*/
|
|
33
33
|
function isEAN(options) {
|
|
34
|
-
return (0, index_js_1.validator)('isEAN',
|
|
34
|
+
return (0, index_js_1.validator)('isEAN', (input, context, _this) => {
|
|
35
35
|
if (typeof input === 'string' && validatorJS.isEAN(input))
|
|
36
36
|
return input;
|
|
37
37
|
context.fail(_this, `"{{value}}" is not a valid EAN (European Article Number)`, input);
|
|
38
38
|
}, options);
|
|
39
39
|
}
|
|
40
|
-
exports.isEAN = isEAN;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isEmail =
|
|
26
|
+
exports.isEmail = isEmail;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -41,8 +41,9 @@ function isEmail(options) {
|
|
|
41
41
|
// eslint-disable-next-line camelcase
|
|
42
42
|
allow_ip_domain: options?.allowIpDomain,
|
|
43
43
|
};
|
|
44
|
-
return (0, index_js_1.validator)('isEmail',
|
|
45
|
-
if (typeof input === 'string' &&
|
|
44
|
+
return (0, index_js_1.validator)('isEmail', (input, context, _this) => {
|
|
45
|
+
if (typeof input === 'string' &&
|
|
46
|
+
validatorJS.isEmail(input, emailOptions)) {
|
|
46
47
|
if (options?.requireDisplayName) {
|
|
47
48
|
if (!validatorJS.isEmail(input, {
|
|
48
49
|
...emailOptions,
|
|
@@ -94,4 +95,3 @@ function isEmail(options) {
|
|
|
94
95
|
context.fail(_this, `"{{value}}" does not match required e-mail format`, input);
|
|
95
96
|
}, options);
|
|
96
97
|
}
|
|
97
|
-
exports.isEmail = isEmail;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isETHAddress =
|
|
26
|
+
exports.isETHAddress = isETHAddress;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
31
|
* @validator isETHAddress
|
|
32
32
|
*/
|
|
33
33
|
function isETHAddress(options) {
|
|
34
|
-
return (0, index_js_1.validator)('isETHAddress',
|
|
35
|
-
if (typeof input === 'string' && validatorJS.isEthereumAddress(input))
|
|
34
|
+
return (0, index_js_1.validator)('isETHAddress', (input, context, _this) => {
|
|
35
|
+
if (typeof input === 'string' && validatorJS.isEthereumAddress(input)) {
|
|
36
36
|
return input;
|
|
37
|
+
}
|
|
37
38
|
context.fail(_this, `Value is not a valid a ETH (Ethereum) address`, input);
|
|
38
39
|
}, options);
|
|
39
40
|
}
|
|
40
|
-
exports.isETHAddress = isETHAddress;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isFQDN =
|
|
26
|
+
exports.isFQDN = isFQDN;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -35,10 +35,10 @@ function isFQDN(options) {
|
|
|
35
35
|
// eslint-disable-next-line camelcase
|
|
36
36
|
allow_wildcard: options?.allowWildcard,
|
|
37
37
|
};
|
|
38
|
-
return (0, index_js_1.validator)('isFQDN',
|
|
39
|
-
if (typeof input === 'string' && validatorJS.isFQDN(input, opts))
|
|
38
|
+
return (0, index_js_1.validator)('isFQDN', (input, context, _this) => {
|
|
39
|
+
if (typeof input === 'string' && validatorJS.isFQDN(input, opts)) {
|
|
40
40
|
return input;
|
|
41
|
+
}
|
|
41
42
|
context.fail(_this, `"{{value}}" is not valid FQDN`, input);
|
|
42
43
|
}, options);
|
|
43
44
|
}
|
|
44
|
-
exports.isFQDN = isFQDN;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isHash =
|
|
26
|
+
exports.isHash = isHash;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
31
|
* @validator isHash
|
|
32
32
|
*/
|
|
33
33
|
function isHash(algorithm, options) {
|
|
34
|
-
return (0, index_js_1.validator)('isHash',
|
|
35
|
-
if (typeof input === 'string' && validatorJS.isHash(input, algorithm))
|
|
34
|
+
return (0, index_js_1.validator)('isHash', (input, context, _this) => {
|
|
35
|
+
if (typeof input === 'string' && validatorJS.isHash(input, algorithm)) {
|
|
36
36
|
return input;
|
|
37
|
+
}
|
|
37
38
|
context.fail(_this, `Value is not a valid ${algorithm} hash`, input);
|
|
38
39
|
}, options);
|
|
39
40
|
}
|
|
40
|
-
exports.isHash = isHash;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isHexColor =
|
|
26
|
+
exports.isHexColor = isHexColor;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
31
|
* @validator isHexColor
|
|
32
32
|
*/
|
|
33
33
|
function isHexColor(options) {
|
|
34
|
-
return (0, index_js_1.validator)('isHexColor',
|
|
35
|
-
if (typeof input === 'string' && validatorJS.isHexColor(input))
|
|
34
|
+
return (0, index_js_1.validator)('isHexColor', (input, context, _this) => {
|
|
35
|
+
if (typeof input === 'string' && validatorJS.isHexColor(input)) {
|
|
36
36
|
return input;
|
|
37
|
+
}
|
|
37
38
|
context.fail(_this, `{{label}} is not a valid Hex Color`, input);
|
|
38
39
|
}, options);
|
|
39
40
|
}
|
|
40
|
-
exports.isHexColor = isHexColor;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isHex =
|
|
26
|
+
exports.isHex = isHex;
|
|
27
27
|
const validatorJS = __importStar(require("validator"));
|
|
28
28
|
const index_js_1 = require("../../core/index.js");
|
|
29
29
|
/**
|
|
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
31
|
* @validator isHex
|
|
32
32
|
*/
|
|
33
33
|
function isHex(options) {
|
|
34
|
-
return (0, index_js_1.validator)('isHex',
|
|
35
|
-
if (typeof input === 'string' && validatorJS.isHexadecimal(input))
|
|
34
|
+
return (0, index_js_1.validator)('isHex', (input, context, _this) => {
|
|
35
|
+
if (typeof input === 'string' && validatorJS.isHexadecimal(input)) {
|
|
36
36
|
return input;
|
|
37
|
+
}
|
|
37
38
|
context.fail(_this, `{{label}} is not an hexadecimal string`, input);
|
|
38
39
|
}, options);
|
|
39
40
|
}
|
|
40
|
-
exports.isHex = isHex;
|
|
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.isIBAN = isIBAN;
|
|
27
|
+
exports.isSWIFT = isSWIFT;
|
|
27
28
|
const validatorJS = __importStar(require("validator"));
|
|
28
29
|
const index_js_1 = require("../../core/index.js");
|
|
29
30
|
/**
|
|
@@ -31,22 +32,20 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
32
|
* @validator isIBAN
|
|
32
33
|
*/
|
|
33
34
|
function isIBAN(options) {
|
|
34
|
-
return (0, index_js_1.validator)('isIBAN',
|
|
35
|
+
return (0, index_js_1.validator)('isIBAN', (input, context, _this) => {
|
|
35
36
|
if (typeof input === 'string' && validatorJS.isIBAN(input))
|
|
36
37
|
return input;
|
|
37
38
|
context.fail(_this, `{{label}} is not a valid IBAN (International Bank Account Number)`, input);
|
|
38
39
|
}, options);
|
|
39
40
|
}
|
|
40
|
-
exports.isIBAN = isIBAN;
|
|
41
41
|
/**
|
|
42
42
|
* Validates if value is a BIC (Bank Identification Code) or SWIFT code
|
|
43
43
|
* @validator isSWIFT
|
|
44
44
|
*/
|
|
45
45
|
function isSWIFT(options) {
|
|
46
|
-
return (0, index_js_1.validator)('isSWIFT',
|
|
46
|
+
return (0, index_js_1.validator)('isSWIFT', (input, context, _this) => {
|
|
47
47
|
if (typeof input === 'string' && validatorJS.isBIC(input))
|
|
48
48
|
return input;
|
|
49
49
|
context.fail(_this, `{{label}}is not a valid a BIC (Bank Identification Code) or SWIFT code`, input);
|
|
50
50
|
}, options);
|
|
51
51
|
}
|
|
52
|
-
exports.isSWIFT = isSWIFT;
|
|
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.isIP = isIP;
|
|
27
|
+
exports.isIPRange = isIPRange;
|
|
27
28
|
const validatorJS = __importStar(require("validator"));
|
|
28
29
|
const index_js_1 = require("../../core/index.js");
|
|
29
30
|
/**
|
|
@@ -31,22 +32,26 @@ const index_js_1 = require("../../core/index.js");
|
|
|
31
32
|
* @validator isIP
|
|
32
33
|
*/
|
|
33
34
|
function isIP(version, options) {
|
|
34
|
-
return (0, index_js_1.validator)('isIP',
|
|
35
|
-
if (input != null &&
|
|
35
|
+
return (0, index_js_1.validator)('isIP', (input, context, _this) => {
|
|
36
|
+
if (input != null &&
|
|
37
|
+
typeof input === 'string' &&
|
|
38
|
+
validatorJS.isIP(input, version)) {
|
|
36
39
|
return input;
|
|
40
|
+
}
|
|
37
41
|
context.fail(_this, `"{{value}}" is not a valid IP${version ? ' v' + version : ''}`, input);
|
|
38
42
|
}, options);
|
|
39
43
|
}
|
|
40
|
-
exports.isIP = isIP;
|
|
41
44
|
/**
|
|
42
45
|
* Validates if value is an IP
|
|
43
46
|
* @validator isIPRange
|
|
44
47
|
*/
|
|
45
48
|
function isIPRange(version, options) {
|
|
46
|
-
return (0, index_js_1.validator)('isIPRange',
|
|
47
|
-
if (input != null &&
|
|
49
|
+
return (0, index_js_1.validator)('isIPRange', (input, context, _this) => {
|
|
50
|
+
if (input != null &&
|
|
51
|
+
typeof input === 'string' &&
|
|
52
|
+
validatorJS.isIPRange(input, version)) {
|
|
48
53
|
return input;
|
|
54
|
+
}
|
|
49
55
|
context.fail(_this, `"{{value}}" is not a valid IP${version ? ' v' + version : ''} range`, input);
|
|
50
56
|
}, options);
|
|
51
57
|
}
|
|
52
|
-
exports.isIPRange = isIPRange;
|