valgen 6.0.2 → 6.1.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 +65 -63
- package/index.js +11 -1
- package/package.json +3 -2
- package/rules/format-rules/is-base64.js +1 -1
- package/rules/format-rules/is-credit-card.js +1 -1
- package/rules/format-rules/is-email.js +1 -1
- package/rules/format-rules/is-fqdn.js +1 -1
- package/rules/format-rules/is-hash.js +1 -1
- package/rules/format-rules/is-ip.js +2 -1
- package/rules/format-rules/is-issn.js +1 -1
- package/rules/format-rules/is-mac-address.js +2 -1
- package/rules/format-rules/is-mobile-phone.js +1 -1
- package/rules/format-rules/is-passport-number.d.ts +1 -3
- package/rules/format-rules/is-port.js +1 -0
- package/rules/format-rules/is-url.js +1 -1
- package/rules/format-rules/is-uuid.js +1 -1
- package/rules/format-rules/is-vat-number.js +1 -1
- package/rules/index.d.ts +1 -0
- package/rules/index.js +1 -0
- package/rules/type-rules/is-array.d.ts +1 -1
- package/rules/type-rules/is-array.js +1 -1
- package/rules/type-rules/is-date.js +1 -0
- package/rules/type-rules/is-instanceof.d.ts +11 -0
- package/rules/type-rules/is-instanceof.js +17 -0
- package/rules/type-rules/is-record.d.ts +1 -1
- package/rules/type-rules/is-record.js +1 -1
- package/rules/utility-rules/all-of.d.ts +1 -1
- package/rules/utility-rules/all-of.js +1 -1
- package/rules/utility-rules/one-of.d.ts +1 -1
- package/rules/utility-rules/one-of.js +1 -1
package/constants.js
CHANGED
package/core/validation-error.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,70 +1,72 @@
|
|
|
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
|
-
declare const isAlpha:
|
|
6
|
-
declare const isAlphanumeric:
|
|
7
|
-
declare const isAny:
|
|
8
|
-
declare const isArray:
|
|
9
|
-
declare const isAscii:
|
|
10
|
-
declare const isBase64:
|
|
11
|
-
declare const isBigint:
|
|
12
|
-
declare const isBoolean:
|
|
13
|
-
declare const isBtcAddress:
|
|
14
|
-
declare const isCreditCard:
|
|
15
|
-
declare const isDate:
|
|
16
|
-
declare const isDateString:
|
|
17
|
-
declare const isDecimal:
|
|
18
|
-
declare const isDefined:
|
|
19
|
-
declare const isEAN:
|
|
20
|
-
declare const isEmail:
|
|
21
|
-
declare const isEmpty:
|
|
22
|
-
declare const isETHAddress:
|
|
23
|
-
declare const isFQDN:
|
|
24
|
-
declare const isHex:
|
|
25
|
-
declare const isHexColor:
|
|
26
|
-
declare const isIBAN:
|
|
27
|
-
declare const isInteger:
|
|
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
|
+
declare const isAlpha: Validator<string, string, ExecutionOptions>;
|
|
7
|
+
declare const isAlphanumeric: Validator<string, string, ExecutionOptions>;
|
|
8
|
+
declare const isAny: Validator<any, any, ExecutionOptions>;
|
|
9
|
+
declare const isArray: Validator<unknown[], unknown, ExecutionOptions>;
|
|
10
|
+
declare const isAscii: Validator<string, string, ExecutionOptions>;
|
|
11
|
+
declare const isBase64: Validator<string, string, ExecutionOptions>;
|
|
12
|
+
declare const isBigint: Validator<bigint, unknown, ExecutionOptions>;
|
|
13
|
+
declare const isBoolean: Validator<boolean | undefined, unknown, ExecutionOptions>;
|
|
14
|
+
declare const isBtcAddress: Validator<string, string, ExecutionOptions>;
|
|
15
|
+
declare const isCreditCard: Validator<string, string, ExecutionOptions>;
|
|
16
|
+
declare const isDate: Validator<Date, string | number | Date, ExecutionOptions>;
|
|
17
|
+
declare const isDateString: Validator<string, string | number | Date, ExecutionOptions>;
|
|
18
|
+
declare const isDecimal: Validator<string, string, ExecutionOptions>;
|
|
19
|
+
declare const isDefined: Validator<any, unknown, ExecutionOptions>;
|
|
20
|
+
declare const isEAN: Validator<string, string, ExecutionOptions>;
|
|
21
|
+
declare const isEmail: Validator<string, string, ExecutionOptions>;
|
|
22
|
+
declare const isEmpty: Validator<any, any, ExecutionOptions>;
|
|
23
|
+
declare const isETHAddress: Validator<string, string, ExecutionOptions>;
|
|
24
|
+
declare const isFQDN: Validator<string, string, ExecutionOptions>;
|
|
25
|
+
declare const isHex: Validator<string, string, ExecutionOptions>;
|
|
26
|
+
declare const isHexColor: Validator<string, string, ExecutionOptions>;
|
|
27
|
+
declare const isIBAN: Validator<string, string, ExecutionOptions>;
|
|
28
|
+
declare const isInteger: Validator<number, unknown, ExecutionOptions>;
|
|
29
|
+
declare const isInstanceOf: <T extends object>(clazz: Type<T>, input: any, options?: vg.isInstanceOf.Options) => any;
|
|
30
|
+
declare const isIP: Validator<string, string, ExecutionOptions>;
|
|
31
|
+
declare const isIPRange: Validator<string, string, ExecutionOptions>;
|
|
32
|
+
declare const isISSN: Validator<string, string, ExecutionOptions>;
|
|
33
|
+
declare const isJWT: Validator<string, string, ExecutionOptions>;
|
|
34
|
+
declare const isLowercase: Validator<string, string, ExecutionOptions>;
|
|
35
|
+
declare const isMACAddress: Validator<string, string, ExecutionOptions>;
|
|
36
|
+
declare const isMobilePhone: Validator<string, string, ExecutionOptions>;
|
|
37
|
+
declare const isNotEmpty: Validator<any, any, ExecutionOptions>;
|
|
38
|
+
declare const isNotNull: Validator<unknown, unknown, ExecutionOptions>;
|
|
39
|
+
declare const isNotNullish: Validator<unknown, unknown, ExecutionOptions>;
|
|
40
|
+
declare const isNull: Validator<null, unknown, ExecutionOptions>;
|
|
41
|
+
declare const isNullish: Validator<null, unknown, ExecutionOptions>;
|
|
42
|
+
declare const isNumber: Validator<number, unknown, ExecutionOptions>;
|
|
41
43
|
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:
|
|
44
|
+
declare const isObjectId: Validator<string | Uint8Array<ArrayBufferLike> | vg.isObjectId.ObjectIdLike, unknown, ExecutionOptions>;
|
|
45
|
+
declare const isPort: Validator<number, string | number, ExecutionOptions>;
|
|
46
|
+
declare const isString: Validator<string, unknown, ExecutionOptions>;
|
|
47
|
+
declare const isSWIFT: Validator<string, string, ExecutionOptions>;
|
|
48
|
+
declare const isTime: Validator<string, string | Date, ExecutionOptions>;
|
|
49
|
+
declare const isUndefined: Validator<any, unknown, ExecutionOptions>;
|
|
50
|
+
declare const isUppercase: Validator<string, string, ExecutionOptions>;
|
|
51
|
+
declare const isURL: Validator<string, string, ExecutionOptions>;
|
|
52
|
+
declare const isUUID: Validator<string, string, ExecutionOptions>;
|
|
53
|
+
declare const isUUID1: Validator<string, string, ExecutionOptions>;
|
|
54
|
+
declare const isUUID2: Validator<string, string, ExecutionOptions>;
|
|
55
|
+
declare const isUUID3: Validator<string, string, ExecutionOptions>;
|
|
56
|
+
declare const isUUID4: Validator<string, string, ExecutionOptions>;
|
|
57
|
+
declare const isUUID5: Validator<string, string, ExecutionOptions>;
|
|
58
|
+
declare const isUUID6: Validator<string, string, ExecutionOptions>;
|
|
59
|
+
declare const isUUID7: Validator<string, string, ExecutionOptions>;
|
|
60
|
+
declare const isUUID8: Validator<string, string, ExecutionOptions>;
|
|
61
|
+
declare const toArray: Validator<any[], any, ExecutionOptions>;
|
|
62
|
+
declare const toBigint: Validator<bigint, unknown, ExecutionOptions>;
|
|
63
|
+
declare const toBoolean: Validator<boolean | undefined, unknown, ExecutionOptions>;
|
|
64
|
+
declare const toDate: Validator<Date, string | number | Date, ExecutionOptions>;
|
|
63
65
|
declare const toDateString: (input: Date | string | number, options?: ExecutionOptions & {
|
|
64
66
|
trim?: vg.isDateString.Precision;
|
|
65
67
|
}, 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, };
|
|
68
|
+
declare const toInteger: Validator<number, unknown, ExecutionOptions>;
|
|
69
|
+
declare const toNumber: Validator<number, unknown, ExecutionOptions>;
|
|
70
|
+
declare const toString: Validator<string, unknown, ExecutionOptions>;
|
|
71
|
+
declare const toTime: Validator<string, string | Date, ExecutionOptions>;
|
|
72
|
+
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,8 @@
|
|
|
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
|
+
const isInstanceOfCache = new WeakMap();
|
|
4
6
|
const isAlpha = vg.isAlpha();
|
|
5
7
|
const isAlphanumeric = vg.isAlphanumeric();
|
|
6
8
|
const isAny = vg.isAny();
|
|
@@ -24,6 +26,14 @@ const isHex = vg.isHex();
|
|
|
24
26
|
const isHexColor = vg.isHexColor();
|
|
25
27
|
const isIBAN = vg.isIBAN();
|
|
26
28
|
const isInteger = vg.isInteger();
|
|
29
|
+
const isInstanceOf = (clazz, input, options) => {
|
|
30
|
+
let fn = isInstanceOfCache.get(clazz);
|
|
31
|
+
if (!fn) {
|
|
32
|
+
fn = vg.isInstanceOf(clazz);
|
|
33
|
+
isInstanceOfCache.set(clazz, fn);
|
|
34
|
+
}
|
|
35
|
+
return fn(input, options);
|
|
36
|
+
};
|
|
27
37
|
const isIP = vg.isIP();
|
|
28
38
|
const isIPRange = vg.isIPRange();
|
|
29
39
|
const isISSN = vg.isISSN();
|
|
@@ -77,4 +87,4 @@ const toInteger = vg.isInteger({ coerce: true });
|
|
|
77
87
|
const toNumber = vg.isNumber({ coerce: true });
|
|
78
88
|
const toString = vg.isString({ coerce: true });
|
|
79
89
|
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, };
|
|
90
|
+
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.1.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",
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { PostalCodeLocale } from '@browsery/validator';
|
|
2
1
|
import { type ValidationOptions } from '../../core/index.js';
|
|
3
2
|
/**
|
|
4
3
|
* Validates if value is a passport number
|
|
5
4
|
* @validator isPassportNumber
|
|
6
5
|
*/
|
|
7
|
-
export declare function isPassportNumber(countryCode:
|
|
6
|
+
export declare function isPassportNumber(countryCode: string, options?: isPassportNumber.Options): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
|
|
8
7
|
export declare namespace isPassportNumber {
|
|
9
8
|
interface Options extends ValidationOptions {
|
|
10
9
|
}
|
|
11
|
-
type CountryCode = PostalCodeLocale;
|
|
12
10
|
}
|
package/rules/index.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export * from './type-rules/is-bigint.js';
|
|
|
44
44
|
export * from './type-rules/is-boolean.js';
|
|
45
45
|
export * from './type-rules/is-date.js';
|
|
46
46
|
export * from './type-rules/is-enum.js';
|
|
47
|
+
export * from './type-rules/is-instanceof.js';
|
|
47
48
|
export * from './type-rules/is-integer.js';
|
|
48
49
|
export * from './type-rules/is-null.js';
|
|
49
50
|
export * from './type-rules/is-number.js';
|
package/rules/index.js
CHANGED
|
@@ -44,6 +44,7 @@ export * from './type-rules/is-bigint.js';
|
|
|
44
44
|
export * from './type-rules/is-boolean.js';
|
|
45
45
|
export * from './type-rules/is-date.js';
|
|
46
46
|
export * from './type-rules/is-enum.js';
|
|
47
|
+
export * from './type-rules/is-instanceof.js';
|
|
47
48
|
export * from './type-rules/is-integer.js';
|
|
48
49
|
export * from './type-rules/is-null.js';
|
|
49
50
|
export * from './type-rules/is-number.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ValidationOptions, Validator } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Validates if the value is "array" and applies validation for each item.
|
|
4
4
|
* Converts input value to array if the coerce option is set to 'true'.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Type } from 'ts-gems';
|
|
2
|
+
import { type ValidationOptions } from '../../core/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validates if the value instance of given class or classes
|
|
5
|
+
* @validator isUndefined
|
|
6
|
+
*/
|
|
7
|
+
export declare function isInstanceOf<T extends object>(clazz: Type<T>, options?: isInstanceOf.Options): import("../../core/validator.js").Validator<T, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
8
|
+
export declare namespace isInstanceOf {
|
|
9
|
+
interface Options extends ValidationOptions {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isPlainObject } from '@jsopen/objects';
|
|
2
|
+
import { validator, } from '../../core/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validates if the value instance of given class or classes
|
|
5
|
+
* @validator isUndefined
|
|
6
|
+
*/
|
|
7
|
+
export function isInstanceOf(clazz, options) {
|
|
8
|
+
return validator('isInstanceOf', (input, context, _this) => {
|
|
9
|
+
if ((options?.coerce ?? context.coerce) && isPlainObject(input)) {
|
|
10
|
+
Object.setPrototypeOf(input, clazz.prototype);
|
|
11
|
+
}
|
|
12
|
+
if (!(input instanceof clazz)) {
|
|
13
|
+
context.fail(_this, `Value must be an instance of "${clazz.name}"`, input);
|
|
14
|
+
}
|
|
15
|
+
return input;
|
|
16
|
+
}, options);
|
|
17
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ValidationOptions, Validator } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Validates the record object according to given "key" and "value" rules
|
|
4
4
|
* Converts properties according to rules if the coerce option is set to 'true'.
|