valgen 5.4.0 → 5.5.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 +17 -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 +4 -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 +4 -11
- 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 +2 -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 +2 -8
- 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 +2 -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-tuple.d.ts +36 -4
- package/typings/rules/type-rules/is-undefined.d.ts +6 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { validator } from '../../core/index.js';
|
|
1
|
+
import { validator, } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Makes sub-rule optional
|
|
4
4
|
* @validator optional
|
|
5
5
|
*/
|
|
6
6
|
export function optional(nested, options) {
|
|
7
|
-
return validator('optional',
|
|
7
|
+
return validator('optional', (input, context) => {
|
|
8
8
|
if (input == null)
|
|
9
9
|
return input;
|
|
10
10
|
return nested(input, context);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validator } from '../../core/index.js';
|
|
1
|
+
import { validator, } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
3
|
*
|
|
4
4
|
* @validator pipe
|
|
@@ -6,11 +6,11 @@ import { validator } from '../../core/index.js';
|
|
|
6
6
|
export function pipe(rules, options) {
|
|
7
7
|
const l = rules.length;
|
|
8
8
|
const returnIndex = options?.returnIndex;
|
|
9
|
-
return validator('pipe',
|
|
9
|
+
return validator('pipe', (input, context) => {
|
|
10
10
|
let i;
|
|
11
11
|
let c;
|
|
12
12
|
let v = input;
|
|
13
|
-
let returnValue;
|
|
13
|
+
let returnValue = input;
|
|
14
14
|
for (i = 0; i < l; i++) {
|
|
15
15
|
c = rules[i];
|
|
16
16
|
v = c(v, context);
|
|
@@ -27,7 +27,7 @@ export function pipe(rules, options) {
|
|
|
27
27
|
* @validator allOf
|
|
28
28
|
*/
|
|
29
29
|
export function allOf(rules) {
|
|
30
|
-
return validator('allOf',
|
|
30
|
+
return validator('allOf', (input, context) => {
|
|
31
31
|
let i;
|
|
32
32
|
let c;
|
|
33
33
|
const l = rules.length;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { validator } from '../../core/index.js';
|
|
1
|
+
import { validator, } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Makes sub-rule required
|
|
4
4
|
* @validator required
|
|
5
5
|
*/
|
|
6
6
|
export function required(nested, options) {
|
|
7
|
-
return validator('required',
|
|
7
|
+
return validator('required', (input, context, _this) => {
|
|
8
8
|
if (input == null) {
|
|
9
9
|
context.fail(_this, `{{label}} is required`, input);
|
|
10
10
|
return;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valgen",
|
|
3
3
|
"description": "Fast runtime type validator, converter and io (encoding/decoding) library",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.5.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"url": "https://github.com/panates/valgen.git"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@types/validator": "^13.
|
|
15
|
+
"@types/validator": "^13.12.0",
|
|
16
16
|
"date-fns": "^3.6.0",
|
|
17
17
|
"ts-gems": "^3.4.0",
|
|
18
18
|
"validator": "^13.12.0"
|
package/typings/core/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './context.js';
|
|
2
1
|
export * from './constants.js';
|
|
2
|
+
export * from './context.js';
|
|
3
3
|
export * from './types.js';
|
|
4
|
+
export * from './utilities.js';
|
|
4
5
|
export * from './validation-error.js';
|
|
5
6
|
export * from './validator.js';
|
|
6
|
-
export
|
|
7
|
-
export { Nullish, Type, Maybe } from 'ts-gems';
|
|
7
|
+
export { Maybe, Nullish, Type } from 'ts-gems';
|
package/typings/core/types.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface ErrorIssue {
|
|
|
11
11
|
label?: string;
|
|
12
12
|
[key: string]: any;
|
|
13
13
|
}
|
|
14
|
-
export type OnFailFunction = (issue: ErrorIssue, context: Context
|
|
14
|
+
export type OnFailFunction = (issue: ErrorIssue, context: Context) => string | Omit<ErrorIssue, 'id' | 'input'>;
|
|
15
15
|
export interface ValidationOptions {
|
|
16
16
|
onFail?: OnFailFunction;
|
|
17
17
|
coerce?: boolean;
|
package/typings/index.d.ts
CHANGED
|
@@ -53,8 +53,9 @@ declare const isHex: import("./core/validator.js").Validator<string, string, imp
|
|
|
53
53
|
declare const toArray: import("./core/validator.js").Validator<any[], any, import("./core/types.js").ExecutionOptions>;
|
|
54
54
|
declare const toBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, import("./core/types.js").ExecutionOptions>;
|
|
55
55
|
declare const toDate: import("./core/validator.js").Validator<Date, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
56
|
+
declare const toBigint: import("./core/validator.js").Validator<bigint, unknown, import("./core/types.js").ExecutionOptions>;
|
|
56
57
|
declare const toDateString: import("./core/validator.js").Validator<string, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
57
58
|
declare const toInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
58
59
|
declare const toNumber: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
59
60
|
declare const toString: import("./core/validator.js").Validator<string, unknown, import("./core/types.js").ExecutionOptions>;
|
|
60
|
-
export {
|
|
61
|
+
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, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, vg, };
|
package/typings/rules/index.d.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
export * from './type-rules/is-any.js';
|
|
2
|
-
export * from './type-rules/is-array.js';
|
|
3
|
-
export * from './type-rules/is-bigint.js';
|
|
4
|
-
export * from './type-rules/is-boolean.js';
|
|
5
|
-
export * from './type-rules/is-date.js';
|
|
6
|
-
export * from './type-rules/is-enum.js';
|
|
7
|
-
export * from './type-rules/is-integer.js';
|
|
8
|
-
export * from './type-rules/is-null.js';
|
|
9
|
-
export * from './type-rules/is-number.js';
|
|
10
|
-
export * from './type-rules/is-object.js';
|
|
11
|
-
export * from './type-rules/is-record.js';
|
|
12
|
-
export * from './type-rules/is-string.js';
|
|
13
|
-
export * from './type-rules/is-tuple.js';
|
|
14
1
|
export * from './format-rules/is-alpha.js';
|
|
15
2
|
export * from './format-rules/is-ascii.js';
|
|
16
3
|
export * from './format-rules/is-base64.js';
|
|
@@ -41,6 +28,20 @@ export * from './format-rules/matches.js';
|
|
|
41
28
|
export * from './logical-rules/is-defined.js';
|
|
42
29
|
export * from './logical-rules/is-empty.js';
|
|
43
30
|
export * from './logical-rules/range.js';
|
|
31
|
+
export * from './type-rules/is-any.js';
|
|
32
|
+
export * from './type-rules/is-array.js';
|
|
33
|
+
export * from './type-rules/is-bigint.js';
|
|
34
|
+
export * from './type-rules/is-boolean.js';
|
|
35
|
+
export * from './type-rules/is-date.js';
|
|
36
|
+
export * from './type-rules/is-enum.js';
|
|
37
|
+
export * from './type-rules/is-integer.js';
|
|
38
|
+
export * from './type-rules/is-null.js';
|
|
39
|
+
export * from './type-rules/is-number.js';
|
|
40
|
+
export * from './type-rules/is-object.js';
|
|
41
|
+
export * from './type-rules/is-record.js';
|
|
42
|
+
export * from './type-rules/is-string.js';
|
|
43
|
+
export * from './type-rules/is-tuple.js';
|
|
44
|
+
export * from './type-rules/is-undefined.js';
|
|
44
45
|
export * from './utility-rules/exists.js';
|
|
45
46
|
export * from './utility-rules/get-length.js';
|
|
46
47
|
export * from './utility-rules/optional.js';
|
|
@@ -4,8 +4,3 @@ import { ValidationOptions } from '../../core/index.js';
|
|
|
4
4
|
* @validator isDefined
|
|
5
5
|
*/
|
|
6
6
|
export declare function isDefined(options?: ValidationOptions): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
7
|
-
/**
|
|
8
|
-
* Validates if value is "undefined"
|
|
9
|
-
* @validator isUndefined
|
|
10
|
-
*/
|
|
11
|
-
export declare function isUndefined(options?: ValidationOptions): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
@@ -7,9 +7,25 @@ import { ValidationOptions, Validator } from '../../core/index.js';
|
|
|
7
7
|
export declare function isTuple<T1, I1>(items: [Validator<T1, I1>], options?: ValidationOptions): Validator<[T1], [I1]>;
|
|
8
8
|
export declare function isTuple<T1, I1, T2, I2>(items: [Validator<T1, I1>, Validator<T2, I2>], options?: ValidationOptions): Validator<[T1, T2], [I1, I2]>;
|
|
9
9
|
export declare function isTuple<T1, I1, T2, I2, T3, I3>(items: [Validator<T1, I1>, Validator<T2, I2>, Validator<T3, I3>], options?: ValidationOptions): Validator<[T1, T2, T3], [I1, I2, I3]>;
|
|
10
|
-
export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4>(items: [
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4>(items: [
|
|
11
|
+
Validator<T1, I1>,
|
|
12
|
+
Validator<T2, I2>,
|
|
13
|
+
Validator<T3, I3>,
|
|
14
|
+
Validator<T4, I4>
|
|
15
|
+
], options?: ValidationOptions): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
|
|
16
|
+
export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4>(items: [
|
|
17
|
+
Validator<T1, I1>,
|
|
18
|
+
Validator<T2, I2>,
|
|
19
|
+
Validator<T3, I3>,
|
|
20
|
+
Validator<T4, I4>
|
|
21
|
+
], options?: ValidationOptions): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
|
|
22
|
+
export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5>(items: [
|
|
23
|
+
Validator<T1, I1>,
|
|
24
|
+
Validator<T2, I2>,
|
|
25
|
+
Validator<T3, I3>,
|
|
26
|
+
Validator<T4, I4>,
|
|
27
|
+
Validator<T5, I5>
|
|
28
|
+
], options?: ValidationOptions): Validator<[T1, T2, T3, T4, T5], [I1, I2, I3, I4, I5]>;
|
|
13
29
|
export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5, T6, I6>(items: [
|
|
14
30
|
Validator<T1, I1>,
|
|
15
31
|
Validator<T2, I2>,
|
|
@@ -18,4 +34,20 @@ export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5, T6, I6>(
|
|
|
18
34
|
Validator<T5, I5>,
|
|
19
35
|
Validator<T6, I6>,
|
|
20
36
|
...Validator[]
|
|
21
|
-
], options?: ValidationOptions): Validator<[
|
|
37
|
+
], options?: ValidationOptions): Validator<[
|
|
38
|
+
T1,
|
|
39
|
+
T2,
|
|
40
|
+
T3,
|
|
41
|
+
T4,
|
|
42
|
+
T5,
|
|
43
|
+
T6,
|
|
44
|
+
...any[]
|
|
45
|
+
], [
|
|
46
|
+
I1,
|
|
47
|
+
I2,
|
|
48
|
+
I3,
|
|
49
|
+
I4,
|
|
50
|
+
I5,
|
|
51
|
+
I5,
|
|
52
|
+
...any[]
|
|
53
|
+
]>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ValidationOptions } from '../../core/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates if value is "undefined"
|
|
4
|
+
* @validator isUndefined
|
|
5
|
+
*/
|
|
6
|
+
export declare function isUndefined(options?: ValidationOptions): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;
|