valgen 5.10.0 → 5.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/cjs/core/context.js +2 -0
- package/cjs/core/validation-error.js +2 -1
- package/cjs/core/validator.js +12 -6
- package/cjs/rules/format-rules/is-alpha.js +5 -5
- package/cjs/rules/format-rules/is-ascii.js +3 -3
- package/cjs/rules/format-rules/is-base64.js +3 -3
- package/cjs/rules/format-rules/is-btc-address.js +3 -3
- package/cjs/rules/format-rules/is-credit-card.js +3 -3
- package/cjs/rules/format-rules/is-decimal.js +3 -3
- package/cjs/rules/format-rules/is-ean.js +3 -3
- package/cjs/rules/format-rules/is-email.js +8 -17
- package/cjs/rules/format-rules/is-eth-address.js +3 -3
- package/cjs/rules/format-rules/is-fqdn.js +3 -4
- package/cjs/rules/format-rules/is-hash.js +3 -3
- package/cjs/rules/format-rules/is-hex-color.js +3 -3
- package/cjs/rules/format-rules/is-hex.js +3 -3
- package/cjs/rules/format-rules/is-iban.js +5 -5
- package/cjs/rules/format-rules/is-ip.js +5 -5
- package/cjs/rules/format-rules/is-issn.js +3 -4
- package/cjs/rules/format-rules/is-jwt.js +3 -3
- package/cjs/rules/format-rules/is-lowercase.js +5 -5
- package/cjs/rules/format-rules/is-mac-address.js +3 -4
- package/cjs/rules/format-rules/is-mobile-phone.js +3 -3
- package/cjs/rules/format-rules/is-object-id.js +2 -2
- package/cjs/rules/format-rules/is-passport-number.js +3 -3
- package/cjs/rules/format-rules/is-port.js +6 -4
- package/cjs/rules/format-rules/is-url.js +3 -3
- package/cjs/rules/format-rules/is-uuid.js +3 -3
- package/cjs/rules/format-rules/is-vat-number.js +3 -3
- package/cjs/rules/format-rules/matches.js +1 -1
- package/cjs/rules/logical-rules/is-defined.js +1 -1
- package/cjs/rules/logical-rules/is-empty.js +12 -12
- package/cjs/rules/logical-rules/range.js +5 -5
- package/cjs/rules/type-rules/is-array.js +6 -2
- package/cjs/rules/type-rules/is-bigint.js +1 -2
- package/cjs/rules/type-rules/is-boolean.js +1 -2
- package/cjs/rules/type-rules/is-date.js +4 -6
- package/cjs/rules/type-rules/is-integer.js +1 -6
- package/cjs/rules/type-rules/is-null.js +1 -1
- package/cjs/rules/type-rules/is-number.js +1 -6
- package/cjs/rules/type-rules/is-object.js +1 -1
- package/cjs/rules/type-rules/is-record.js +6 -4
- package/cjs/rules/type-rules/is-string.js +1 -1
- package/cjs/rules/type-rules/is-tuple.js +1 -1
- package/cjs/rules/type-rules/is-undefined.js +1 -1
- package/cjs/rules/utility-rules/get-length.js +1 -1
- package/cjs/rules/utility-rules/required.js +1 -1
- package/cjs/tsconfig-build-cjs.tsbuildinfo +1 -1
- package/esm/core/context.js +2 -0
- package/esm/core/validation-error.js +2 -1
- package/esm/core/validator.js +12 -6
- package/esm/rules/format-rules/is-alpha.js +3 -3
- package/esm/rules/format-rules/is-ascii.js +2 -2
- package/esm/rules/format-rules/is-base64.js +2 -2
- package/esm/rules/format-rules/is-btc-address.js +2 -2
- package/esm/rules/format-rules/is-credit-card.js +2 -2
- package/esm/rules/format-rules/is-decimal.js +2 -2
- package/esm/rules/format-rules/is-ean.js +2 -2
- package/esm/rules/format-rules/is-email.js +2 -11
- package/esm/rules/format-rules/is-eth-address.js +2 -2
- package/esm/rules/format-rules/is-fqdn.js +2 -3
- package/esm/rules/format-rules/is-hash.js +2 -2
- package/esm/rules/format-rules/is-hex-color.js +2 -2
- package/esm/rules/format-rules/is-hex.js +2 -2
- package/esm/rules/format-rules/is-iban.js +3 -3
- package/esm/rules/format-rules/is-ip.js +3 -3
- package/esm/rules/format-rules/is-issn.js +2 -3
- package/esm/rules/format-rules/is-jwt.js +2 -2
- package/esm/rules/format-rules/is-lowercase.js +3 -3
- package/esm/rules/format-rules/is-mac-address.js +2 -3
- package/esm/rules/format-rules/is-mobile-phone.js +2 -2
- package/esm/rules/format-rules/is-object-id.js +2 -2
- package/esm/rules/format-rules/is-passport-number.js +2 -2
- package/esm/rules/format-rules/is-port.js +5 -3
- package/esm/rules/format-rules/is-url.js +2 -2
- package/esm/rules/format-rules/is-uuid.js +2 -2
- package/esm/rules/format-rules/is-vat-number.js +2 -2
- package/esm/rules/format-rules/matches.js +1 -1
- package/esm/rules/logical-rules/is-defined.js +1 -1
- package/esm/rules/logical-rules/is-empty.js +12 -12
- package/esm/rules/logical-rules/range.js +5 -5
- package/esm/rules/type-rules/is-array.js +6 -2
- package/esm/rules/type-rules/is-bigint.js +1 -2
- package/esm/rules/type-rules/is-boolean.js +1 -2
- package/esm/rules/type-rules/is-date.js +4 -6
- package/esm/rules/type-rules/is-integer.js +1 -6
- package/esm/rules/type-rules/is-null.js +1 -1
- package/esm/rules/type-rules/is-number.js +1 -6
- package/esm/rules/type-rules/is-object.js +1 -1
- package/esm/rules/type-rules/is-record.js +6 -4
- package/esm/rules/type-rules/is-string.js +1 -1
- package/esm/rules/type-rules/is-tuple.js +1 -1
- package/esm/rules/type-rules/is-undefined.js +1 -1
- package/esm/rules/utility-rules/get-length.js +1 -1
- package/esm/rules/utility-rules/required.js +1 -1
- package/esm/tsconfig-build-esm.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/types/core/context.d.ts +1 -0
- package/types/index.d.cts +2 -2
- package/types/index.d.ts +2 -2
- package/types/rules/format-rules/is-base64.d.ts +1 -1
- package/types/rules/format-rules/is-credit-card.d.ts +1 -1
- package/types/rules/format-rules/is-hash.d.ts +1 -1
- package/types/rules/format-rules/is-mobile-phone.d.ts +1 -1
- package/types/rules/format-rules/is-object-id.d.ts +1 -1
- package/types/rules/format-rules/is-port.d.ts +1 -1
- package/types/rules/format-rules/is-url.d.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
# v5.13.0
|
|
2
|
+
[2025-02-03]
|
|
3
|
+
|
|
4
|
+
### Changes
|
|
5
|
+
|
|
6
|
+
* refactor: Updated dependencies ([`dca11c1`](https://github.com/panates/valgen/commit/dca11c1d094daca39974bbc9c70b8f30480c4d0a))
|
|
7
|
+
* refactor: Changed error messages to "positive sentences" ([`3b746df`](https://github.com/panates/valgen/commit/3b746df70ab0e25e32e3f5b957f1c24f3f0fcc70))
|
|
8
|
+
* chore: Updated github workflow ([`661738f`](https://github.com/panates/valgen/commit/661738f1fd90eed72ec2718e67159a8ab614e65e))
|
|
9
|
+
* dev: Fixed ts config ([`e3251ce`](https://github.com/panates/valgen/commit/e3251ce7776de3bd4afeb0c2d0ed5d19f6aabd4f))
|
|
10
|
+
* dev: Added missing script ([`dd019d9`](https://github.com/panates/valgen/commit/dd019d923f8305462e27cad1745564071c9c34bb))
|
|
11
|
+
|
|
12
|
+
# v5.12.0
|
|
13
|
+
[2024-11-04]
|
|
14
|
+
|
|
15
|
+
### Changes
|
|
16
|
+
|
|
17
|
+
* refactor: Move from 'validator' library to "@browsery/validator" for ESM compatibility ([`5a0d1bd`](https://github.com/panates/valgen/commit/5a0d1bd499581c80033b063942247fe550930dec))
|
|
18
|
+
|
|
19
|
+
# v5.11.0
|
|
20
|
+
[2024-11-04]
|
|
21
|
+
|
|
22
|
+
### Changes
|
|
23
|
+
|
|
24
|
+
* nit: Updated dependencies ([`f348c6c`](https://github.com/panates/valgen/commit/f348c6c52cb8efa9716e36d96e233fdbda605cec))
|
|
25
|
+
|
|
1
26
|
# v5.10.0
|
|
2
27
|
[2024-09-14]
|
|
3
28
|
|
package/cjs/core/context.js
CHANGED
|
@@ -7,6 +7,7 @@ const VARIABLE_REPLACE_PATTERN = /{{([^}]*)}}/g;
|
|
|
7
7
|
const OPTIONAL_VAR_PATTERN = /^([^?]+)(?:\||(.*))?$/;
|
|
8
8
|
class Context {
|
|
9
9
|
constructor(options) {
|
|
10
|
+
this.isRoot = true;
|
|
10
11
|
this.errors = [];
|
|
11
12
|
Object.assign(this, options);
|
|
12
13
|
}
|
|
@@ -65,6 +66,7 @@ class Context {
|
|
|
65
66
|
extended[k] = v;
|
|
66
67
|
}
|
|
67
68
|
}
|
|
69
|
+
extended.isRoot = false;
|
|
68
70
|
Object.setPrototypeOf(extended, this);
|
|
69
71
|
return extended;
|
|
70
72
|
}
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ValidationError = void 0;
|
|
4
4
|
class ValidationError extends Error {
|
|
5
5
|
constructor(issues) {
|
|
6
|
-
super(issues[0].message
|
|
6
|
+
super(issues[0].message +
|
|
7
|
+
(issues[0].location ? `\n at ${issues[0].location}` : ''));
|
|
7
8
|
this.issues = [];
|
|
8
9
|
this.issues = issues;
|
|
9
10
|
}
|
package/cjs/core/validator.js
CHANGED
|
@@ -26,11 +26,17 @@ function validator(arg0, arg1, arg2) {
|
|
|
26
26
|
id = id || fn.name || 'validator' + ++unnamedValidatorIndex;
|
|
27
27
|
const name = fn.name || (0, string_utils_js_1.camelCase)(id);
|
|
28
28
|
const _rule = {
|
|
29
|
-
[name](input, options) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
[name](input, options, context) {
|
|
30
|
+
if (context) {
|
|
31
|
+
if (options || validatorOptions)
|
|
32
|
+
context = context.extend({ ...validatorOptions, ...options });
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
context =
|
|
36
|
+
options instanceof context_js_1.Context
|
|
37
|
+
? options.extend({ ...validatorOptions })
|
|
38
|
+
: new context_js_1.Context({ ...validatorOptions, ...options });
|
|
39
|
+
}
|
|
34
40
|
let value;
|
|
35
41
|
try {
|
|
36
42
|
value = fn(input, context, _rule);
|
|
@@ -40,7 +46,7 @@ function validator(arg0, arg1, arg2) {
|
|
|
40
46
|
throw e;
|
|
41
47
|
context.fail(_rule, e, input);
|
|
42
48
|
}
|
|
43
|
-
if (
|
|
49
|
+
if (context.isRoot && context.errors.length) {
|
|
44
50
|
throw new validation_error_js_1.ValidationError(context.errors);
|
|
45
51
|
}
|
|
46
52
|
return value;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isAlpha = isAlpha;
|
|
4
4
|
exports.isAlphanumeric = isAlphanumeric;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
-
const
|
|
6
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
7
7
|
const index_js_1 = require("../../core/index.js");
|
|
8
8
|
/**
|
|
9
9
|
* Check if the string contains only letters (a-zA-Z).
|
|
@@ -11,9 +11,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
11
11
|
*/
|
|
12
12
|
function isAlpha(options) {
|
|
13
13
|
return (0, index_js_1.validator)('isLowercase', (input, context, _this) => {
|
|
14
|
-
if (typeof input === 'string' &&
|
|
14
|
+
if (typeof input === 'string' && validator_1.default.isAlpha(input))
|
|
15
15
|
return input;
|
|
16
|
-
context.fail(_this, `"
|
|
16
|
+
context.fail(_this, `"Value must be an alpha string`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -22,9 +22,9 @@ function isAlpha(options) {
|
|
|
22
22
|
*/
|
|
23
23
|
function isAlphanumeric(options) {
|
|
24
24
|
return (0, index_js_1.validator)('isAlphanumeric', (input, context, _this) => {
|
|
25
|
-
if (typeof input === 'string' &&
|
|
25
|
+
if (typeof input === 'string' && validator_1.default.isAlphanumeric(input)) {
|
|
26
26
|
return input;
|
|
27
27
|
}
|
|
28
|
-
context.fail(_this, `"
|
|
28
|
+
context.fail(_this, `"Value must be an alphanumeric string`, input);
|
|
29
29
|
}, options);
|
|
30
30
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isAscii = isAscii;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Check if the string contains ASCII chars only.
|
|
@@ -10,8 +10,8 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isAscii(options) {
|
|
12
12
|
return (0, index_js_1.validator)('isAscii', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' &&
|
|
13
|
+
if (typeof input === 'string' && validator_1.default.isAscii(input))
|
|
14
14
|
return input;
|
|
15
|
-
context.fail(_this, `Value
|
|
15
|
+
context.fail(_this, `Value must be an ascii string`, input);
|
|
16
16
|
}, options);
|
|
17
17
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isBase64 = isBase64;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is a "Base64" string.
|
|
@@ -10,9 +10,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isBase64(options) {
|
|
12
12
|
return (0, index_js_1.validator)('isBase64', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' &&
|
|
13
|
+
if (typeof input === 'string' && validator_1.default.isBase64(input, options)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `"
|
|
16
|
+
context.fail(_this, `"Value must be a Base64 string`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isBtcAddress = isBtcAddress;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is a BTC address.
|
|
@@ -10,9 +10,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isBtcAddress(options) {
|
|
12
12
|
return (0, index_js_1.validator)('isBtcAddress', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' &&
|
|
13
|
+
if (typeof input === 'string' && validator_1.default.isBtcAddress(input)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `Value
|
|
16
|
+
context.fail(_this, `Value must be a valid BTC address`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isCreditCard = isCreditCard;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is a credit card number
|
|
@@ -11,9 +11,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
11
11
|
function isCreditCard(options) {
|
|
12
12
|
return (0, index_js_1.validator)('isCreditCard', (input, context, _this) => {
|
|
13
13
|
if (typeof input === 'string' &&
|
|
14
|
-
|
|
14
|
+
validator_1.default.isCreditCard(input, options)) {
|
|
15
15
|
return input;
|
|
16
16
|
}
|
|
17
|
-
context.fail(_this, `
|
|
17
|
+
context.fail(_this, `Value must be a valid Credit Card number`, input);
|
|
18
18
|
}, options);
|
|
19
19
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isDecimal = isDecimal;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Check if the string represents a decimal number,
|
|
@@ -11,9 +11,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
11
11
|
*/
|
|
12
12
|
function isDecimal(options) {
|
|
13
13
|
return (0, index_js_1.validator)('isDecimal', (input, context, _this) => {
|
|
14
|
-
if (typeof input === 'string' &&
|
|
14
|
+
if (typeof input === 'string' && validator_1.default.isDecimal(input)) {
|
|
15
15
|
return input;
|
|
16
16
|
}
|
|
17
|
-
context.fail(_this, `
|
|
17
|
+
context.fail(_this, `Value must be a decimal number string`, input);
|
|
18
18
|
}, options);
|
|
19
19
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isEAN = isEAN;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is an EAN (European Article Number)
|
|
@@ -10,8 +10,8 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isEAN(options) {
|
|
12
12
|
return (0, index_js_1.validator)('isEAN', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' &&
|
|
13
|
+
if (typeof input === 'string' && validator_1.default.isEAN(input))
|
|
14
14
|
return input;
|
|
15
|
-
context.fail(_this, `
|
|
15
|
+
context.fail(_this, `Value must be a valid EAN (European Article Number)`, input);
|
|
16
16
|
}, options);
|
|
17
17
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isEmail = isEmail;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is a valid Email
|
|
@@ -10,22 +10,17 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isEmail(options) {
|
|
12
12
|
const emailOptions = {
|
|
13
|
-
// eslint-disable-next-line camelcase
|
|
14
13
|
allow_display_name: true,
|
|
15
|
-
// eslint-disable-next-line camelcase
|
|
16
14
|
allow_utf8_local_part: options?.utf8LocalPart,
|
|
17
|
-
// eslint-disable-next-line camelcase
|
|
18
15
|
ignore_max_length: true,
|
|
19
|
-
// eslint-disable-next-line camelcase
|
|
20
16
|
allow_ip_domain: options?.allowIpDomain,
|
|
21
17
|
};
|
|
22
18
|
return (0, index_js_1.validator)('isEmail', (input, context, _this) => {
|
|
23
19
|
if (typeof input === 'string' &&
|
|
24
|
-
|
|
20
|
+
validator_1.default.isEmail(input, emailOptions)) {
|
|
25
21
|
if (options?.requireDisplayName) {
|
|
26
|
-
if (!
|
|
22
|
+
if (!validator_1.default.isEmail(input, {
|
|
27
23
|
...emailOptions,
|
|
28
|
-
// eslint-disable-next-line camelcase
|
|
29
24
|
require_display_name: true,
|
|
30
25
|
})) {
|
|
31
26
|
context.fail(_this, `Display name for the email is required. Etc. ( Name <me@tempuri.org> ) `, input);
|
|
@@ -33,36 +28,32 @@ function isEmail(options) {
|
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
30
|
else if (!options?.allowDisplayName &&
|
|
36
|
-
!
|
|
31
|
+
!validator_1.default.isEmail(input, {
|
|
37
32
|
...emailOptions,
|
|
38
|
-
// eslint-disable-next-line camelcase
|
|
39
33
|
allow_display_name: false,
|
|
40
34
|
})) {
|
|
41
35
|
context.fail(_this, `Display name in email is not allowed`, input);
|
|
42
36
|
return;
|
|
43
37
|
}
|
|
44
38
|
if (options?.hostBlacklist &&
|
|
45
|
-
!
|
|
39
|
+
!validator_1.default.isEmail(input, {
|
|
46
40
|
...emailOptions,
|
|
47
|
-
// eslint-disable-next-line camelcase
|
|
48
41
|
host_blacklist: options.hostBlacklist,
|
|
49
42
|
})) {
|
|
50
43
|
context.fail(_this, `Email "{{value}}" is in black-list`, input);
|
|
51
44
|
return;
|
|
52
45
|
}
|
|
53
46
|
if (options?.hostWhitelist &&
|
|
54
|
-
!
|
|
47
|
+
!validator_1.default.isEmail(input, {
|
|
55
48
|
...emailOptions,
|
|
56
|
-
// eslint-disable-next-line camelcase
|
|
57
49
|
host_whitelist: options.hostWhitelist,
|
|
58
50
|
})) {
|
|
59
51
|
context.fail(_this, `Email "{{value}}" is in not white-list`, input);
|
|
60
52
|
return;
|
|
61
53
|
}
|
|
62
54
|
if (options?.blacklistedChars &&
|
|
63
|
-
!
|
|
55
|
+
!validator_1.default.isEmail(input, {
|
|
64
56
|
...emailOptions,
|
|
65
|
-
// eslint-disable-next-line camelcase
|
|
66
57
|
blacklisted_chars: options.blacklistedChars,
|
|
67
58
|
})) {
|
|
68
59
|
context.fail(_this, `Black listed characters (${options.blacklistedChars}) found in name part`, input);
|
|
@@ -70,6 +61,6 @@ function isEmail(options) {
|
|
|
70
61
|
}
|
|
71
62
|
return input;
|
|
72
63
|
}
|
|
73
|
-
context.fail(_this, `
|
|
64
|
+
context.fail(_this, `Value must much required e-mail format`, input);
|
|
74
65
|
}, options);
|
|
75
66
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isETHAddress = isETHAddress;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is a ETH (Ethereum) address.
|
|
@@ -10,9 +10,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isETHAddress(options) {
|
|
12
12
|
return (0, index_js_1.validator)('isETHAddress', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' &&
|
|
13
|
+
if (typeof input === 'string' && validator_1.default.isEthereumAddress(input)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `Value
|
|
16
|
+
context.fail(_this, `Value must be valid ETH (Ethereum) address`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isFQDN = isFQDN;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is an FQDN
|
|
@@ -10,13 +10,12 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isFQDN(options) {
|
|
12
12
|
const opts = {
|
|
13
|
-
// eslint-disable-next-line camelcase
|
|
14
13
|
allow_wildcard: options?.allowWildcard,
|
|
15
14
|
};
|
|
16
15
|
return (0, index_js_1.validator)('isFQDN', (input, context, _this) => {
|
|
17
|
-
if (typeof input === 'string' &&
|
|
16
|
+
if (typeof input === 'string' && validator_1.default.isFQDN(input, opts)) {
|
|
18
17
|
return input;
|
|
19
18
|
}
|
|
20
|
-
context.fail(_this, `
|
|
19
|
+
context.fail(_this, `Value must be valid FQDN`, input);
|
|
21
20
|
}, options);
|
|
22
21
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isHash = isHash;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value a hash of type algorithm
|
|
@@ -10,9 +10,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isHash(algorithm, options) {
|
|
12
12
|
return (0, index_js_1.validator)('isHash', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' &&
|
|
13
|
+
if (typeof input === 'string' && validator_1.default.isHash(input, algorithm)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `Value
|
|
16
|
+
context.fail(_this, `Value must be a valid ${algorithm} hash`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isHexColor = isHexColor;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is a Hex Color
|
|
@@ -10,9 +10,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isHexColor(options) {
|
|
12
12
|
return (0, index_js_1.validator)('isHexColor', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' &&
|
|
13
|
+
if (typeof input === 'string' && validator_1.default.isHexColor(input)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `
|
|
16
|
+
context.fail(_this, `Value must be a valid Hex Color`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isHex = isHex;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Check if the string is a hexadecimal number.
|
|
@@ -10,9 +10,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isHex(options) {
|
|
12
12
|
return (0, index_js_1.validator)('isHex', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' &&
|
|
13
|
+
if (typeof input === 'string' && validator_1.default.isHexadecimal(input)) {
|
|
14
14
|
return input;
|
|
15
15
|
}
|
|
16
|
-
context.fail(_this, `
|
|
16
|
+
context.fail(_this, `Value must be an hexadecimal string`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isIBAN = isIBAN;
|
|
4
4
|
exports.isSWIFT = isSWIFT;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
-
const
|
|
6
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
7
7
|
const index_js_1 = require("../../core/index.js");
|
|
8
8
|
/**
|
|
9
9
|
* Validates if value is an IBAN (International Bank Account Number)
|
|
@@ -11,9 +11,9 @@ const index_js_1 = require("../../core/index.js");
|
|
|
11
11
|
*/
|
|
12
12
|
function isIBAN(options) {
|
|
13
13
|
return (0, index_js_1.validator)('isIBAN', (input, context, _this) => {
|
|
14
|
-
if (typeof input === 'string' &&
|
|
14
|
+
if (typeof input === 'string' && validator_1.default.isIBAN(input))
|
|
15
15
|
return input;
|
|
16
|
-
context.fail(_this, `
|
|
16
|
+
context.fail(_this, `Value must be a valid IBAN (International Bank Account Number)`, input);
|
|
17
17
|
}, options);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -22,8 +22,8 @@ function isIBAN(options) {
|
|
|
22
22
|
*/
|
|
23
23
|
function isSWIFT(options) {
|
|
24
24
|
return (0, index_js_1.validator)('isSWIFT', (input, context, _this) => {
|
|
25
|
-
if (typeof input === 'string' &&
|
|
25
|
+
if (typeof input === 'string' && validator_1.default.isBIC(input))
|
|
26
26
|
return input;
|
|
27
|
-
context.fail(_this, `
|
|
27
|
+
context.fail(_this, `Value must be a valid a BIC (Bank Identification Code) or SWIFT code`, input);
|
|
28
28
|
}, options);
|
|
29
29
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isIP = isIP;
|
|
4
4
|
exports.isIPRange = isIPRange;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
-
const
|
|
6
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
7
7
|
const index_js_1 = require("../../core/index.js");
|
|
8
8
|
/**
|
|
9
9
|
* Validates if value is an IP
|
|
@@ -13,10 +13,10 @@ function isIP(version, options) {
|
|
|
13
13
|
return (0, index_js_1.validator)('isIP', (input, context, _this) => {
|
|
14
14
|
if (input != null &&
|
|
15
15
|
typeof input === 'string' &&
|
|
16
|
-
|
|
16
|
+
validator_1.default.isIP(input, version)) {
|
|
17
17
|
return input;
|
|
18
18
|
}
|
|
19
|
-
context.fail(_this, `
|
|
19
|
+
context.fail(_this, `Value must be a valid IP${version ? ' v' + version : ''}`, input);
|
|
20
20
|
}, options);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
@@ -27,9 +27,9 @@ function isIPRange(version, options) {
|
|
|
27
27
|
return (0, index_js_1.validator)('isIPRange', (input, context, _this) => {
|
|
28
28
|
if (input != null &&
|
|
29
29
|
typeof input === 'string' &&
|
|
30
|
-
|
|
30
|
+
validator_1.default.isIPRange(input, version)) {
|
|
31
31
|
return input;
|
|
32
32
|
}
|
|
33
|
-
context.fail(_this, `
|
|
33
|
+
context.fail(_this, `Value must be a valid IP${version ? ' v' + version : ''} range`, input);
|
|
34
34
|
}, options);
|
|
35
35
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isISSN = isISSN;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is an ISSN
|
|
@@ -10,13 +10,12 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isISSN(options) {
|
|
12
12
|
const opts = {
|
|
13
|
-
// eslint-disable-next-line camelcase
|
|
14
13
|
case_sensitive: options?.caseSensitive,
|
|
15
14
|
};
|
|
16
15
|
return (0, index_js_1.validator)('isISSN', (input, context, _this) => {
|
|
17
|
-
if (typeof input === 'string' &&
|
|
16
|
+
if (typeof input === 'string' && validator_1.default.isISSN(input, opts)) {
|
|
18
17
|
return input;
|
|
19
18
|
}
|
|
20
|
-
context.fail(_this, `
|
|
19
|
+
context.fail(_this, `Value must be a valid ISSN`, input);
|
|
21
20
|
}, options);
|
|
22
21
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isJWT = isJWT;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value a valid JWT token
|
|
@@ -10,8 +10,8 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isJWT(options) {
|
|
12
12
|
return (0, index_js_1.validator)('isJWT', (input, context, _this) => {
|
|
13
|
-
if (typeof input === 'string' &&
|
|
13
|
+
if (typeof input === 'string' && validator_1.default.isJWT(input))
|
|
14
14
|
return input;
|
|
15
|
-
context.fail(_this, `Value
|
|
15
|
+
context.fail(_this, `Value must be valid JWT token`, input);
|
|
16
16
|
}, options);
|
|
17
17
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isLowercase = isLowercase;
|
|
4
4
|
exports.isUppercase = isUppercase;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
-
const
|
|
6
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
7
7
|
const index_js_1 = require("../../core/index.js");
|
|
8
8
|
/**
|
|
9
9
|
* Validates if value a Lowercase string
|
|
@@ -11,10 +11,10 @@ const index_js_1 = require("../../core/index.js");
|
|
|
11
11
|
*/
|
|
12
12
|
function isLowercase(options) {
|
|
13
13
|
return (0, index_js_1.validator)('isLowercase', (input, context, _this) => {
|
|
14
|
-
if (typeof input === 'string' &&
|
|
14
|
+
if (typeof input === 'string' && validator_1.default.isLowercase(input)) {
|
|
15
15
|
return input;
|
|
16
16
|
}
|
|
17
|
-
context.fail(_this, `
|
|
17
|
+
context.fail(_this, `Value must be a lowercase string`, input);
|
|
18
18
|
}, options);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -23,9 +23,9 @@ function isLowercase(options) {
|
|
|
23
23
|
*/
|
|
24
24
|
function isUppercase(options) {
|
|
25
25
|
return (0, index_js_1.validator)('isUppercase', (input, context, _this) => {
|
|
26
|
-
if (typeof input === 'string' &&
|
|
26
|
+
if (typeof input === 'string' && validator_1.default.isUppercase(input)) {
|
|
27
27
|
return input;
|
|
28
28
|
}
|
|
29
|
-
context.fail(_this, `
|
|
29
|
+
context.fail(_this, `Value must be an uppercase string`, input);
|
|
30
30
|
}, options);
|
|
31
31
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isMACAddress = isMACAddress;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is an MACAddress
|
|
@@ -10,16 +10,15 @@ const index_js_1 = require("../../core/index.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function isMACAddress(options) {
|
|
12
12
|
const opts = {
|
|
13
|
-
// eslint-disable-next-line camelcase
|
|
14
13
|
no_separators: options?.noSeparators,
|
|
15
14
|
eui: options?.eui,
|
|
16
15
|
};
|
|
17
16
|
return (0, index_js_1.validator)('isMACAddress', (input, context, _this) => {
|
|
18
17
|
if (input != null &&
|
|
19
18
|
typeof input === 'string' &&
|
|
20
|
-
|
|
19
|
+
validator_1.default.isMACAddress(input, opts)) {
|
|
21
20
|
return input;
|
|
22
21
|
}
|
|
23
|
-
context.fail(_this, `
|
|
22
|
+
context.fail(_this, `Value must be a valid MAC address`, input);
|
|
24
23
|
}, options);
|
|
25
24
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isMobilePhone = isMobilePhone;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const validator_1 = tslib_1.__importDefault(require("@browsery/validator"));
|
|
6
6
|
const index_js_1 = require("../../core/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates if value is a valid Email
|
|
@@ -14,9 +14,9 @@ function isMobilePhone(options) {
|
|
|
14
14
|
};
|
|
15
15
|
return (0, index_js_1.validator)('isMobilePhone', (input, context, _this) => {
|
|
16
16
|
if (typeof input === 'string' &&
|
|
17
|
-
|
|
17
|
+
validator_1.default.isMobilePhone(input, options?.locale, opts)) {
|
|
18
18
|
return input;
|
|
19
19
|
}
|
|
20
|
-
context.fail(_this, `
|
|
20
|
+
context.fail(_this, `Value must be a valid a Mobile Phone Number`, input);
|
|
21
21
|
}, options);
|
|
22
22
|
}
|