valgen 6.0.3 → 6.2.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/constants.js +1 -1
- package/core/validation-error.js +1 -0
- package/index.d.ts +66 -63
- package/index.js +12 -1
- package/package.json +3 -2
- package/rules/format-rules/is-alpha.js +1 -1
- package/rules/format-rules/is-alphanumeric.js +1 -1
- package/rules/format-rules/is-ascii.js +1 -1
- package/rules/format-rules/is-base64.js +2 -2
- package/rules/format-rules/is-btc-address.js +1 -1
- package/rules/format-rules/is-credit-card.js +2 -2
- package/rules/format-rules/is-decimal.js +1 -1
- package/rules/format-rules/is-ean.js +1 -1
- package/rules/format-rules/is-email.js +2 -2
- package/rules/format-rules/is-eth-address.js +1 -1
- package/rules/format-rules/is-fqdn.js +2 -2
- package/rules/format-rules/is-hash.js +2 -2
- package/rules/format-rules/is-hex-color.js +1 -1
- package/rules/format-rules/is-hex.js +1 -1
- package/rules/format-rules/is-iban.js +1 -1
- package/rules/format-rules/is-ip.js +4 -3
- package/rules/format-rules/is-issn.js +2 -2
- package/rules/format-rules/is-jwt.js +1 -1
- package/rules/format-rules/is-lowercase.js +1 -1
- package/rules/format-rules/is-mac-address.js +3 -2
- package/rules/format-rules/is-mobile-phone.js +2 -2
- package/rules/format-rules/is-object-id.js +1 -1
- package/rules/format-rules/is-passport-number.js +1 -1
- package/rules/format-rules/is-port.js +2 -1
- package/rules/format-rules/is-swift.js +1 -1
- package/rules/format-rules/is-time.js +1 -1
- package/rules/format-rules/is-uppercase.js +1 -1
- package/rules/format-rules/is-url.js +2 -2
- package/rules/format-rules/is-uuid.js +2 -2
- package/rules/format-rules/is-vat-number.js +2 -2
- package/rules/format-rules/matches.js +1 -1
- package/rules/index.d.ts +3 -0
- package/rules/index.js +3 -0
- package/rules/logical-rules/is-defined.js +1 -1
- package/rules/logical-rules/is-empty.js +1 -1
- package/rules/logical-rules/is-equal.js +2 -2
- package/rules/logical-rules/is-gt.js +1 -1
- package/rules/logical-rules/is-gte.d.ts +1 -1
- package/rules/logical-rules/is-gte.js +1 -1
- package/rules/logical-rules/is-lt.js +1 -1
- package/rules/logical-rules/is-lte.js +1 -1
- package/rules/logical-rules/range.js +1 -1
- package/rules/type-rules/is-any.js +1 -1
- package/rules/type-rules/is-array.d.ts +1 -1
- package/rules/type-rules/is-array.js +2 -2
- package/rules/type-rules/is-bigint.js +1 -1
- package/rules/type-rules/is-boolean.js +1 -1
- package/rules/type-rules/is-date.js +3 -2
- package/rules/type-rules/is-enum.js +1 -1
- package/rules/type-rules/is-instanceof.d.ts +11 -0
- package/rules/type-rules/is-instanceof.js +17 -0
- package/rules/type-rules/is-integer.js +1 -1
- package/rules/type-rules/is-null.js +4 -4
- package/rules/type-rules/is-number.js +1 -1
- package/rules/type-rules/is-object.js +1 -1
- package/rules/type-rules/is-record.d.ts +1 -1
- package/rules/type-rules/is-record.js +2 -2
- package/rules/type-rules/is-string.js +1 -1
- package/rules/type-rules/is-tuple.js +1 -1
- package/rules/type-rules/is-undefined.js +1 -1
- package/rules/utility-rules/all-of.d.ts +1 -1
- package/rules/utility-rules/all-of.js +2 -2
- package/rules/utility-rules/exists.js +1 -1
- package/rules/utility-rules/fixed.d.ts +5 -0
- package/rules/utility-rules/fixed.js +10 -0
- package/rules/utility-rules/get-length.js +1 -1
- package/rules/utility-rules/nullable.d.ts +11 -0
- package/rules/utility-rules/nullable.js +12 -0
- package/rules/utility-rules/one-of.d.ts +1 -1
- package/rules/utility-rules/one-of.js +2 -2
- package/rules/utility-rules/optional.d.ts +2 -2
- package/rules/utility-rules/optional.js +2 -2
- package/rules/utility-rules/pipe.js +1 -1
- package/rules/utility-rules/required.js +1 -1
- package/rules/utility-rules/string-utils.d.ts +2 -2
- package/rules/utility-rules/string-utils.js +17 -15
package/constants.js
CHANGED
package/core/validation-error.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,70 +1,73 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Type } from 'ts-gems';
|
|
2
|
+
import { Context, type ExecutionOptions, type Validator } from './core/index.js';
|
|
2
3
|
import * as vg from './rules/index.js';
|
|
3
4
|
export * from './constants.js';
|
|
4
5
|
export * from './core/index.js';
|
|
5
|
-
|
|
6
|
-
declare const
|
|
7
|
-
declare const
|
|
8
|
-
declare const
|
|
9
|
-
declare const
|
|
10
|
-
declare const
|
|
11
|
-
declare const
|
|
12
|
-
declare const
|
|
13
|
-
declare const
|
|
14
|
-
declare const
|
|
15
|
-
declare const
|
|
16
|
-
declare const
|
|
17
|
-
declare const
|
|
18
|
-
declare const
|
|
19
|
-
declare const
|
|
20
|
-
declare const
|
|
21
|
-
declare const
|
|
22
|
-
declare const
|
|
23
|
-
declare const
|
|
24
|
-
declare const
|
|
25
|
-
declare const
|
|
26
|
-
declare const
|
|
27
|
-
declare const
|
|
28
|
-
declare const
|
|
29
|
-
declare const
|
|
30
|
-
declare const
|
|
31
|
-
declare const
|
|
32
|
-
declare const
|
|
33
|
-
declare const
|
|
34
|
-
declare const
|
|
35
|
-
declare const
|
|
36
|
-
declare const
|
|
37
|
-
declare const
|
|
38
|
-
declare const
|
|
39
|
-
declare const
|
|
40
|
-
declare const
|
|
6
|
+
export * from './core/types.js';
|
|
7
|
+
declare const isAlpha: Validator<string, string, ExecutionOptions>;
|
|
8
|
+
declare const isAlphanumeric: Validator<string, string, ExecutionOptions>;
|
|
9
|
+
declare const isAny: Validator<any, any, ExecutionOptions>;
|
|
10
|
+
declare const isArray: Validator<unknown[], unknown, ExecutionOptions>;
|
|
11
|
+
declare const isAscii: Validator<string, string, ExecutionOptions>;
|
|
12
|
+
declare const isBase64: Validator<string, string, ExecutionOptions>;
|
|
13
|
+
declare const isBigint: Validator<bigint, unknown, ExecutionOptions>;
|
|
14
|
+
declare const isBoolean: Validator<boolean | undefined, unknown, ExecutionOptions>;
|
|
15
|
+
declare const isBtcAddress: Validator<string, string, ExecutionOptions>;
|
|
16
|
+
declare const isCreditCard: Validator<string, string, ExecutionOptions>;
|
|
17
|
+
declare const isDate: Validator<Date, string | number | Date, ExecutionOptions>;
|
|
18
|
+
declare const isDateString: Validator<string, string | number | Date, ExecutionOptions>;
|
|
19
|
+
declare const isDecimal: Validator<string, string, ExecutionOptions>;
|
|
20
|
+
declare const isDefined: Validator<any, unknown, ExecutionOptions>;
|
|
21
|
+
declare const isEAN: Validator<string, string, ExecutionOptions>;
|
|
22
|
+
declare const isEmail: Validator<string, string, ExecutionOptions>;
|
|
23
|
+
declare const isEmpty: Validator<any, any, ExecutionOptions>;
|
|
24
|
+
declare const isETHAddress: Validator<string, string, ExecutionOptions>;
|
|
25
|
+
declare const isFQDN: Validator<string, string, ExecutionOptions>;
|
|
26
|
+
declare const isHex: Validator<string, string, ExecutionOptions>;
|
|
27
|
+
declare const isHexColor: Validator<string, string, ExecutionOptions>;
|
|
28
|
+
declare const isIBAN: Validator<string, string, ExecutionOptions>;
|
|
29
|
+
declare const isInteger: Validator<number, unknown, ExecutionOptions>;
|
|
30
|
+
declare const isInstanceOf: <T extends object>(clazz: Type<T>, input: any, options?: vg.isInstanceOf.Options) => any;
|
|
31
|
+
declare const isIP: Validator<string, string, ExecutionOptions>;
|
|
32
|
+
declare const isIPRange: Validator<string, string, ExecutionOptions>;
|
|
33
|
+
declare const isISSN: Validator<string, string, ExecutionOptions>;
|
|
34
|
+
declare const isJWT: Validator<string, string, ExecutionOptions>;
|
|
35
|
+
declare const isLowercase: Validator<string, string, ExecutionOptions>;
|
|
36
|
+
declare const isMACAddress: Validator<string, string, ExecutionOptions>;
|
|
37
|
+
declare const isMobilePhone: Validator<string, string, ExecutionOptions>;
|
|
38
|
+
declare const isNotEmpty: Validator<any, any, ExecutionOptions>;
|
|
39
|
+
declare const isNotNull: Validator<unknown, unknown, ExecutionOptions>;
|
|
40
|
+
declare const isNotNullish: Validator<unknown, unknown, ExecutionOptions>;
|
|
41
|
+
declare const isNull: Validator<null, unknown, ExecutionOptions>;
|
|
42
|
+
declare const isNullish: Validator<null, unknown, ExecutionOptions>;
|
|
43
|
+
declare const isNumber: Validator<number, unknown, ExecutionOptions>;
|
|
41
44
|
declare const isObject: vg.isObject.Validator<object, string | object>;
|
|
42
|
-
declare const isObjectId:
|
|
43
|
-
declare const isPort:
|
|
44
|
-
declare const isString:
|
|
45
|
-
declare const isSWIFT:
|
|
46
|
-
declare const isTime:
|
|
47
|
-
declare const isUndefined:
|
|
48
|
-
declare const isUppercase:
|
|
49
|
-
declare const isURL:
|
|
50
|
-
declare const isUUID:
|
|
51
|
-
declare const isUUID1:
|
|
52
|
-
declare const isUUID2:
|
|
53
|
-
declare const isUUID3:
|
|
54
|
-
declare const isUUID4:
|
|
55
|
-
declare const isUUID5:
|
|
56
|
-
declare const isUUID6:
|
|
57
|
-
declare const isUUID7:
|
|
58
|
-
declare const isUUID8:
|
|
59
|
-
declare const toArray:
|
|
60
|
-
declare const toBigint:
|
|
61
|
-
declare const toBoolean:
|
|
62
|
-
declare const toDate:
|
|
45
|
+
declare const isObjectId: Validator<string | Uint8Array<ArrayBufferLike> | vg.isObjectId.ObjectIdLike, unknown, ExecutionOptions>;
|
|
46
|
+
declare const isPort: Validator<number, string | number, ExecutionOptions>;
|
|
47
|
+
declare const isString: Validator<string, unknown, ExecutionOptions>;
|
|
48
|
+
declare const isSWIFT: Validator<string, string, ExecutionOptions>;
|
|
49
|
+
declare const isTime: Validator<string, string | Date, ExecutionOptions>;
|
|
50
|
+
declare const isUndefined: Validator<any, unknown, ExecutionOptions>;
|
|
51
|
+
declare const isUppercase: Validator<string, string, ExecutionOptions>;
|
|
52
|
+
declare const isURL: Validator<string, string, ExecutionOptions>;
|
|
53
|
+
declare const isUUID: Validator<string, string, ExecutionOptions>;
|
|
54
|
+
declare const isUUID1: Validator<string, string, ExecutionOptions>;
|
|
55
|
+
declare const isUUID2: Validator<string, string, ExecutionOptions>;
|
|
56
|
+
declare const isUUID3: Validator<string, string, ExecutionOptions>;
|
|
57
|
+
declare const isUUID4: Validator<string, string, ExecutionOptions>;
|
|
58
|
+
declare const isUUID5: Validator<string, string, ExecutionOptions>;
|
|
59
|
+
declare const isUUID6: Validator<string, string, ExecutionOptions>;
|
|
60
|
+
declare const isUUID7: Validator<string, string, ExecutionOptions>;
|
|
61
|
+
declare const isUUID8: Validator<string, string, ExecutionOptions>;
|
|
62
|
+
declare const toArray: Validator<any[], any, ExecutionOptions>;
|
|
63
|
+
declare const toBigint: Validator<bigint, unknown, ExecutionOptions>;
|
|
64
|
+
declare const toBoolean: Validator<boolean | undefined, unknown, ExecutionOptions>;
|
|
65
|
+
declare const toDate: Validator<Date, string | number | Date, ExecutionOptions>;
|
|
63
66
|
declare const toDateString: (input: Date | string | number, options?: ExecutionOptions & {
|
|
64
67
|
trim?: vg.isDateString.Precision;
|
|
65
68
|
}, ctx?: Context) => any;
|
|
66
|
-
declare const toInteger:
|
|
67
|
-
declare const toNumber:
|
|
68
|
-
declare const toString:
|
|
69
|
-
declare const toTime:
|
|
70
|
-
export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, isUUID6, isUUID7, isUUID8, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
|
|
69
|
+
declare const toInteger: Validator<number, unknown, ExecutionOptions>;
|
|
70
|
+
declare const toNumber: Validator<number, unknown, ExecutionOptions>;
|
|
71
|
+
declare const toString: Validator<string, unknown, ExecutionOptions>;
|
|
72
|
+
declare const toTime: Validator<string, string | Date, ExecutionOptions>;
|
|
73
|
+
export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInstanceOf, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, isUUID6, isUUID7, isUUID8, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
|
package/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { Context, } from './core/index.js';
|
|
1
2
|
import * as vg from './rules/index.js';
|
|
2
3
|
export * from './constants.js';
|
|
3
4
|
export * from './core/index.js';
|
|
5
|
+
export * from './core/types.js';
|
|
6
|
+
const isInstanceOfCache = new WeakMap();
|
|
4
7
|
const isAlpha = vg.isAlpha();
|
|
5
8
|
const isAlphanumeric = vg.isAlphanumeric();
|
|
6
9
|
const isAny = vg.isAny();
|
|
@@ -24,6 +27,14 @@ const isHex = vg.isHex();
|
|
|
24
27
|
const isHexColor = vg.isHexColor();
|
|
25
28
|
const isIBAN = vg.isIBAN();
|
|
26
29
|
const isInteger = vg.isInteger();
|
|
30
|
+
const isInstanceOf = (clazz, input, options) => {
|
|
31
|
+
let fn = isInstanceOfCache.get(clazz);
|
|
32
|
+
if (!fn) {
|
|
33
|
+
fn = vg.isInstanceOf(clazz);
|
|
34
|
+
isInstanceOfCache.set(clazz, fn);
|
|
35
|
+
}
|
|
36
|
+
return fn(input, options);
|
|
37
|
+
};
|
|
27
38
|
const isIP = vg.isIP();
|
|
28
39
|
const isIPRange = vg.isIPRange();
|
|
29
40
|
const isISSN = vg.isISSN();
|
|
@@ -77,4 +88,4 @@ const toInteger = vg.isInteger({ coerce: true });
|
|
|
77
88
|
const toNumber = vg.isNumber({ coerce: true });
|
|
78
89
|
const toString = vg.isString({ coerce: true });
|
|
79
90
|
const toTime = vg.isTime({ coerce: true });
|
|
80
|
-
export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, isUUID6, isUUID7, isUUID8, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
|
|
91
|
+
export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInstanceOf, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, isUUID6, isUUID7, isUUID8, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valgen",
|
|
3
3
|
"description": "Fast runtime type validator, converter and io (encoding/decoding) library",
|
|
4
|
-
"version": "6.0
|
|
4
|
+
"version": "6.2.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@browsery/validator": "^13.15.35",
|
|
9
|
+
"@jsopen/objects": "^2.2.1",
|
|
9
10
|
"date-fns": "^4.1.0",
|
|
10
11
|
"reflect-metadata": "^0.2.2",
|
|
11
|
-
"ts-gems": "^3.
|
|
12
|
+
"ts-gems": "^3.12.0",
|
|
12
13
|
"tslib": "^2.8.1"
|
|
13
14
|
},
|
|
14
15
|
"type": "module",
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isAlpha
|
|
6
6
|
*/
|
|
7
7
|
export function isAlpha(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isAlpha.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isAlpha(input))
|
|
10
10
|
return input;
|
|
11
11
|
context.fail(_this, `"Value must be an alpha string`, input);
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isAlphanumeric
|
|
6
6
|
*/
|
|
7
7
|
export function isAlphanumeric(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isAlphanumeric.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isAlphanumeric(input)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isAscii
|
|
6
6
|
*/
|
|
7
7
|
export function isAscii(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isAscii.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isAscii(input))
|
|
10
10
|
return input;
|
|
11
11
|
context.fail(_this, `Value must be an ascii string`, input);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is a "Base64" string.
|
|
5
5
|
* @validator isBase64
|
|
6
6
|
*/
|
|
7
7
|
export function isBase64(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isBase64.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isBase64(input, options)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isBtcAddress
|
|
6
6
|
*/
|
|
7
7
|
export function isBtcAddress(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isBtcAddress.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isBtcAddress(input)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is a credit card number
|
|
5
5
|
* @validator isCreditCard
|
|
6
6
|
*/
|
|
7
7
|
export function isCreditCard(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isCreditCard.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' &&
|
|
10
10
|
validatorJS.isCreditCard(input, options)) {
|
|
11
11
|
return input;
|
|
@@ -6,7 +6,7 @@ import { validator, } from '../../core/index.js';
|
|
|
6
6
|
* @validator isDecimal
|
|
7
7
|
*/
|
|
8
8
|
export function isDecimal(options) {
|
|
9
|
-
return validator(
|
|
9
|
+
return validator(isDecimal.name, (input, context, _this) => {
|
|
10
10
|
if (typeof input === 'string' && validatorJS.isDecimal(input)) {
|
|
11
11
|
return input;
|
|
12
12
|
}
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isEAN
|
|
6
6
|
*/
|
|
7
7
|
export function isEAN(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isEAN.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isEAN(input))
|
|
10
10
|
return input;
|
|
11
11
|
context.fail(_this, `Value must be a valid EAN (European Article Number)`, input);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is a valid Email
|
|
@@ -11,7 +11,7 @@ export function isEmail(options) {
|
|
|
11
11
|
ignore_max_length: true,
|
|
12
12
|
allow_ip_domain: options?.allowIpDomain,
|
|
13
13
|
};
|
|
14
|
-
return validator(
|
|
14
|
+
return validator(isEmail.name, (input, context, _this) => {
|
|
15
15
|
if (typeof input === 'string' &&
|
|
16
16
|
validatorJS.isEmail(input, emailOptions)) {
|
|
17
17
|
if (options?.requireDisplayName) {
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isETHAddress
|
|
6
6
|
*/
|
|
7
7
|
export function isETHAddress(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isETHAddress.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isEthereumAddress(input)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is an FQDN
|
|
@@ -8,7 +8,7 @@ export function isFQDN(options) {
|
|
|
8
8
|
const opts = {
|
|
9
9
|
allow_wildcard: options?.allowWildcard,
|
|
10
10
|
};
|
|
11
|
-
return validator(
|
|
11
|
+
return validator(isFQDN.name, (input, context, _this) => {
|
|
12
12
|
if (typeof input === 'string' && validatorJS.isFQDN(input, opts)) {
|
|
13
13
|
return input;
|
|
14
14
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value a hash of type algorithm
|
|
5
5
|
* @validator isHash
|
|
6
6
|
*/
|
|
7
7
|
export function isHash(algorithm, options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isHash.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isHash(input, algorithm)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isHexColor
|
|
6
6
|
*/
|
|
7
7
|
export function isHexColor(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isHexColor.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isHexColor(input)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isHex
|
|
6
6
|
*/
|
|
7
7
|
export function isHex(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isHex.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isHexadecimal(input)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isIBAN
|
|
6
6
|
*/
|
|
7
7
|
export function isIBAN(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isIBAN.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isIBAN(input))
|
|
10
10
|
return input;
|
|
11
11
|
context.fail(_this, `Value must be a valid IBAN (International Bank Account Number)`, input);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
|
+
import {} from 'ts-gems';
|
|
2
3
|
import { validator, } from '../../core/index.js';
|
|
3
4
|
/**
|
|
4
5
|
* Validates if value is an IP
|
|
5
6
|
* @validator isIP
|
|
6
7
|
*/
|
|
7
8
|
export function isIP(version, options) {
|
|
8
|
-
return validator(
|
|
9
|
+
return validator(isIP.name, (input, context, _this) => {
|
|
9
10
|
if (input != null &&
|
|
10
11
|
typeof input === 'string' &&
|
|
11
12
|
validatorJS.isIP(input, version)) {
|
|
@@ -19,7 +20,7 @@ export function isIP(version, options) {
|
|
|
19
20
|
* @validator isIPRange
|
|
20
21
|
*/
|
|
21
22
|
export function isIPRange(version, options) {
|
|
22
|
-
return validator(
|
|
23
|
+
return validator(isIPRange.name, (input, context, _this) => {
|
|
23
24
|
if (input != null &&
|
|
24
25
|
typeof input === 'string' &&
|
|
25
26
|
validatorJS.isIPRange(input, version)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is an ISSN
|
|
@@ -8,7 +8,7 @@ export function isISSN(options) {
|
|
|
8
8
|
const opts = {
|
|
9
9
|
case_sensitive: options?.caseSensitive,
|
|
10
10
|
};
|
|
11
|
-
return validator(
|
|
11
|
+
return validator(isISSN.name, (input, context, _this) => {
|
|
12
12
|
if (typeof input === 'string' && validatorJS.isISSN(input, opts)) {
|
|
13
13
|
return input;
|
|
14
14
|
}
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isJWT
|
|
6
6
|
*/
|
|
7
7
|
export function isJWT(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isJWT.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isJWT(input))
|
|
10
10
|
return input;
|
|
11
11
|
context.fail(_this, `Value must be valid JWT token`, input);
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isLowercase
|
|
6
6
|
*/
|
|
7
7
|
export function isLowercase(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isLowercase.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isLowercase(input)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
|
+
import {} from 'ts-gems';
|
|
2
3
|
import { validator, } from '../../core/index.js';
|
|
3
4
|
/**
|
|
4
5
|
* Validates if value is an MACAddress
|
|
@@ -9,7 +10,7 @@ export function isMACAddress(options) {
|
|
|
9
10
|
no_separators: options?.noSeparators,
|
|
10
11
|
eui: options?.eui,
|
|
11
12
|
};
|
|
12
|
-
return validator(
|
|
13
|
+
return validator(isMACAddress.name, (input, context, _this) => {
|
|
13
14
|
if (input != null &&
|
|
14
15
|
typeof input === 'string' &&
|
|
15
16
|
validatorJS.isMACAddress(input, opts)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is a valid Email
|
|
@@ -8,7 +8,7 @@ export function isMobilePhone(options) {
|
|
|
8
8
|
const opts = {
|
|
9
9
|
strictMode: options?.strictMode,
|
|
10
10
|
};
|
|
11
|
-
return validator(
|
|
11
|
+
return validator(isMobilePhone.name, (input, context, _this) => {
|
|
12
12
|
if (typeof input === 'string' &&
|
|
13
13
|
validatorJS.isMobilePhone(input, options?.locale, opts)) {
|
|
14
14
|
return input;
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isObjectId
|
|
6
6
|
*/
|
|
7
7
|
export function isObjectId(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isObjectId.name, (input, context, _this) => {
|
|
9
9
|
if (input != null &&
|
|
10
10
|
(_isObjectIdValue(input) ||
|
|
11
11
|
(typeof input === 'object' &&
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isPassportNumber
|
|
6
6
|
*/
|
|
7
7
|
export function isPassportNumber(countryCode, options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isPassportNumber.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' &&
|
|
10
10
|
validatorJS.isPassportNumber(input, countryCode)) {
|
|
11
11
|
return input;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import validatorJS from '@browsery/validator';
|
|
2
|
+
import {} from 'ts-gems';
|
|
2
3
|
import { validator, } from '../../core/index.js';
|
|
3
4
|
/**
|
|
4
5
|
* Validates if value is a port number
|
|
5
6
|
* @validator isPort
|
|
6
7
|
*/
|
|
7
8
|
export function isPort(options) {
|
|
8
|
-
return validator(
|
|
9
|
+
return validator(isPort.name, (input, context, _this) => {
|
|
9
10
|
if (typeof input === 'number')
|
|
10
11
|
input = String(input);
|
|
11
12
|
if (input != null &&
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isSWIFT
|
|
6
6
|
*/
|
|
7
7
|
export function isSWIFT(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isSWIFT.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isBIC(input))
|
|
10
10
|
return input;
|
|
11
11
|
context.fail(_this, `Value must be a valid a BIC (Bank Identification Code) or SWIFT code`, input);
|
|
@@ -5,7 +5,7 @@ const TIME_PATTERN = /^(\d{2}):?(\d{2})(?::?(\d{2})?(?:\.(\d{1,3}))?)?$/;
|
|
|
5
5
|
* @validator isTime
|
|
6
6
|
*/
|
|
7
7
|
export function isTime(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isTime.name, (input, context, _this) => {
|
|
9
9
|
if (input != null) {
|
|
10
10
|
const coerce = options?.coerce ?? context.coerce;
|
|
11
11
|
let str;
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
* @validator isUppercase
|
|
6
6
|
*/
|
|
7
7
|
export function isUppercase(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isUppercase.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isUppercase(input)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is an URL
|
|
5
5
|
* @validator isURL
|
|
6
6
|
*/
|
|
7
7
|
export function isURL(options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isURL.name, (input, context, _this) => {
|
|
9
9
|
if (input != null &&
|
|
10
10
|
typeof input === 'string' &&
|
|
11
11
|
validatorJS.isURL(input, options)) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is a "UUID".
|
|
5
5
|
* @validator isUUID
|
|
6
6
|
*/
|
|
7
7
|
export function isUUID(version, options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isUUID.name, (input, context, _this) => {
|
|
9
9
|
if (input != null &&
|
|
10
10
|
typeof input === 'string' &&
|
|
11
11
|
validatorJS.isUUID(input, version)) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import validatorJS from '@browsery/validator';
|
|
1
|
+
import validatorJS, {} from '@browsery/validator';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates if value is a VAT number
|
|
5
5
|
* @validator isVAT
|
|
6
6
|
*/
|
|
7
7
|
export function isVATNumber(countryCode, options) {
|
|
8
|
-
return validator(
|
|
8
|
+
return validator(isVATNumber.name, (input, context, _this) => {
|
|
9
9
|
if (typeof input === 'string' && validatorJS.isVAT(input, countryCode)) {
|
|
10
10
|
return input;
|
|
11
11
|
}
|
|
@@ -6,7 +6,7 @@ import { validator, } from '../../core/index.js';
|
|
|
6
6
|
export function matches(format, options) {
|
|
7
7
|
const regExp = format instanceof RegExp ? format : new RegExp(format);
|
|
8
8
|
const formatName = options?.formatName;
|
|
9
|
-
return validator(
|
|
9
|
+
return validator(matches.name, (input, context, _this) => {
|
|
10
10
|
if (input == null)
|
|
11
11
|
return;
|
|
12
12
|
if (typeof input === 'string' && regExp.test(input))
|