valgen 5.15.1 → 5.15.3
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 +13 -1
- package/cjs/rules/logical-rules/range.js +19 -0
- package/cjs/rules/utility-rules/required.js +3 -1
- package/esm/rules/logical-rules/range.js +19 -0
- package/esm/rules/utility-rules/required.js +3 -1
- package/package.json +1 -1
- package/types/rules/logical-rules/range.d.ts +8 -20
- package/types/rules/utility-rules/required.d.ts +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
|
|
3
|
-
### [v5.15.
|
|
3
|
+
### [v5.15.3](https://github.com/panates/valgen/compare/v5.15.2...v5.15.3) -
|
|
4
|
+
|
|
5
|
+
#### 🚀 New Features
|
|
6
|
+
|
|
7
|
+
- feat: Adde default value option to "required" rule @Eray Hanoğlu
|
|
8
|
+
|
|
9
|
+
### [v5.15.2](https://github.com/panates/valgen/compare/v5.15.1...v5.15.2) - 27 May 2025
|
|
10
|
+
|
|
11
|
+
#### 🛠 Refactoring and Updates
|
|
12
|
+
|
|
13
|
+
- refactor: Refactored isGte, isGt, isLte, isLt typing @Eray Hanoğlu
|
|
14
|
+
|
|
15
|
+
### [v5.15.1](https://github.com/panates/valgen/compare/v5.15.0...v5.15.1) - 27 May 2025
|
|
4
16
|
|
|
5
17
|
#### 🚀 New Features
|
|
6
18
|
|
|
@@ -40,6 +40,10 @@ function range(minValue, maxValue, options) {
|
|
|
40
40
|
context.fail(_this, `Value must be between ${minValue} and ${maxValue}`, input);
|
|
41
41
|
}, options);
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks if value is grater than "minValue"
|
|
45
|
+
* @validator iGt
|
|
46
|
+
*/
|
|
43
47
|
function isGt(minValue, options) {
|
|
44
48
|
return (0, index_js_1.validator)('isGt', (input, context, _this) => {
|
|
45
49
|
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
@@ -62,6 +66,11 @@ function isGt(minValue, options) {
|
|
|
62
66
|
context.fail(_this, `Value must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
63
67
|
}, options);
|
|
64
68
|
}
|
|
69
|
+
// *************************************************************
|
|
70
|
+
/**
|
|
71
|
+
* Checks if value is grater than or equal to minValue
|
|
72
|
+
* @validator isGte
|
|
73
|
+
*/
|
|
65
74
|
function isGte(minValue, options) {
|
|
66
75
|
return (0, index_js_1.validator)('isGte', (input, context, _this) => {
|
|
67
76
|
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
@@ -84,6 +93,11 @@ function isGte(minValue, options) {
|
|
|
84
93
|
context.fail(_this, `Value must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
85
94
|
}, options);
|
|
86
95
|
}
|
|
96
|
+
// *************************************************************
|
|
97
|
+
/**
|
|
98
|
+
* Checks if number value is lover than maxValue
|
|
99
|
+
* @validator isLt
|
|
100
|
+
*/
|
|
87
101
|
function isLt(maxValue, options) {
|
|
88
102
|
return (0, index_js_1.validator)('isLt', (input, context, _this) => {
|
|
89
103
|
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
@@ -106,6 +120,11 @@ function isLt(maxValue, options) {
|
|
|
106
120
|
context.fail(_this, `Value must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
|
|
107
121
|
}, options);
|
|
108
122
|
}
|
|
123
|
+
// *************************************************************
|
|
124
|
+
/**
|
|
125
|
+
* Checks if value is lover than or equal to maxValue
|
|
126
|
+
* @validator isLte
|
|
127
|
+
*/
|
|
109
128
|
function isLte(maxValue, options) {
|
|
110
129
|
return (0, index_js_1.validator)('isLte', (input, context, _this) => {
|
|
111
130
|
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.required = required;
|
|
4
4
|
const index_js_1 = require("../../core/index.js");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Check if value is not nullish before calling nested rule
|
|
7
7
|
* @validator required
|
|
8
8
|
*/
|
|
9
9
|
function required(nested, options) {
|
|
10
10
|
return (0, index_js_1.validator)('required', (input, context, _this) => {
|
|
11
|
+
if (input == null)
|
|
12
|
+
input = options?.default;
|
|
11
13
|
if (input == null) {
|
|
12
14
|
context.fail(_this, `Value required`, input);
|
|
13
15
|
return;
|
|
@@ -32,6 +32,10 @@ export function range(minValue, maxValue, options) {
|
|
|
32
32
|
context.fail(_this, `Value must be between ${minValue} and ${maxValue}`, input);
|
|
33
33
|
}, options);
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Checks if value is grater than "minValue"
|
|
37
|
+
* @validator iGt
|
|
38
|
+
*/
|
|
35
39
|
export function isGt(minValue, options) {
|
|
36
40
|
return validator('isGt', (input, context, _this) => {
|
|
37
41
|
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
@@ -54,6 +58,11 @@ export function isGt(minValue, options) {
|
|
|
54
58
|
context.fail(_this, `Value must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
55
59
|
}, options);
|
|
56
60
|
}
|
|
61
|
+
// *************************************************************
|
|
62
|
+
/**
|
|
63
|
+
* Checks if value is grater than or equal to minValue
|
|
64
|
+
* @validator isGte
|
|
65
|
+
*/
|
|
57
66
|
export function isGte(minValue, options) {
|
|
58
67
|
return validator('isGte', (input, context, _this) => {
|
|
59
68
|
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
@@ -76,6 +85,11 @@ export function isGte(minValue, options) {
|
|
|
76
85
|
context.fail(_this, `Value must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
77
86
|
}, options);
|
|
78
87
|
}
|
|
88
|
+
// *************************************************************
|
|
89
|
+
/**
|
|
90
|
+
* Checks if number value is lover than maxValue
|
|
91
|
+
* @validator isLt
|
|
92
|
+
*/
|
|
79
93
|
export function isLt(maxValue, options) {
|
|
80
94
|
return validator('isLt', (input, context, _this) => {
|
|
81
95
|
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
@@ -98,6 +112,11 @@ export function isLt(maxValue, options) {
|
|
|
98
112
|
context.fail(_this, `Value must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
|
|
99
113
|
}, options);
|
|
100
114
|
}
|
|
115
|
+
// *************************************************************
|
|
116
|
+
/**
|
|
117
|
+
* Checks if value is lover than or equal to maxValue
|
|
118
|
+
* @validator isLte
|
|
119
|
+
*/
|
|
101
120
|
export function isLte(maxValue, options) {
|
|
102
121
|
return validator('isLte', (input, context, _this) => {
|
|
103
122
|
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { validator, } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Check if value is not nullish before calling nested rule
|
|
4
4
|
* @validator required
|
|
5
5
|
*/
|
|
6
6
|
export function required(nested, options) {
|
|
7
7
|
return validator('required', (input, context, _this) => {
|
|
8
|
+
if (input == null)
|
|
9
|
+
input = options?.default;
|
|
8
10
|
if (input == null) {
|
|
9
11
|
context.fail(_this, `Value required`, input);
|
|
10
12
|
return;
|
package/package.json
CHANGED
|
@@ -9,42 +9,30 @@ export declare function range<T extends RangeInput>(minValue: T, maxValue: T, op
|
|
|
9
9
|
* Checks if value is grater than "minValue"
|
|
10
10
|
* @validator iGt
|
|
11
11
|
*/
|
|
12
|
-
export declare function isGt(minValue:
|
|
13
|
-
export declare function isGt(minValue: bigint, options?: ValidationOptions): Validator<bigint, bigint | number>;
|
|
14
|
-
export declare function isGt(minValue: Date, options?: ValidationOptions): Validator<Date, Date>;
|
|
15
|
-
export declare function isGt(minValue: string, options?: ValidationOptions & {
|
|
12
|
+
export declare function isGt<T extends RangeInput>(minValue: T, options?: ValidationOptions & {
|
|
16
13
|
caseInsensitive?: boolean;
|
|
17
|
-
}): Validator
|
|
14
|
+
}): Validator;
|
|
18
15
|
/**
|
|
19
16
|
* Checks if value is grater than or equal to minValue
|
|
20
17
|
* @validator isGte
|
|
21
18
|
*/
|
|
22
|
-
export declare function isGte(minValue:
|
|
23
|
-
export declare function isGte(minValue: bigint, options?: ValidationOptions): Validator<bigint, bigint | number>;
|
|
24
|
-
export declare function isGte(minValue: Date, options?: ValidationOptions): Validator<Date, Date>;
|
|
25
|
-
export declare function isGte(minValue: string, options?: ValidationOptions & {
|
|
19
|
+
export declare function isGte<T extends RangeInput>(minValue: T, options?: ValidationOptions & {
|
|
26
20
|
caseInsensitive?: boolean;
|
|
27
|
-
}): Validator<
|
|
21
|
+
}): Validator<T, T>;
|
|
28
22
|
/**
|
|
29
23
|
* Checks if number value is lover than maxValue
|
|
30
24
|
* @validator isLt
|
|
31
25
|
*/
|
|
32
|
-
export declare function isLt(maxValue:
|
|
33
|
-
export declare function isLt(maxValue: bigint, options?: ValidationOptions): Validator<bigint, bigint | number>;
|
|
34
|
-
export declare function isLt(maxValue: Date, options?: ValidationOptions): Validator<Date, Date>;
|
|
35
|
-
export declare function isLt(maxValue: string, options?: ValidationOptions & {
|
|
26
|
+
export declare function isLt<T extends RangeInput>(maxValue: T, options?: ValidationOptions & {
|
|
36
27
|
caseInsensitive?: boolean;
|
|
37
|
-
}): Validator
|
|
28
|
+
}): Validator;
|
|
38
29
|
/**
|
|
39
30
|
* Checks if value is lover than or equal to maxValue
|
|
40
31
|
* @validator isLte
|
|
41
32
|
*/
|
|
42
|
-
export declare function isLte(maxValue:
|
|
43
|
-
export declare function isLte(maxValue: bigint, options?: ValidationOptions): Validator<bigint, bigint | number>;
|
|
44
|
-
export declare function isLte(maxValue: Date, options?: ValidationOptions): Validator<Date, Date>;
|
|
45
|
-
export declare function isLte(maxValue: string, options?: ValidationOptions & {
|
|
33
|
+
export declare function isLte<T extends RangeInput>(maxValue: T, options?: ValidationOptions & {
|
|
46
34
|
caseInsensitive?: boolean;
|
|
47
|
-
}): Validator
|
|
35
|
+
}): Validator;
|
|
48
36
|
/**
|
|
49
37
|
* Checks the length is at least "minValue"
|
|
50
38
|
* @validator lengthMin
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Nullish } from 'ts-gems';
|
|
2
2
|
import { type ValidationOptions, type Validator } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Check if value is not nullish before calling nested rule
|
|
5
5
|
* @validator required
|
|
6
6
|
*/
|
|
7
|
-
export declare function required<T, I>(nested: Validator<T, I>, options?:
|
|
7
|
+
export declare function required<T, I>(nested: Validator<T, I>, options?: RequiredValidatorOptions): Validator<Nullish<T>, I, import("../../core/types.js").ExecutionOptions>;
|
|
8
|
+
export interface RequiredValidatorOptions extends ValidationOptions {
|
|
9
|
+
default?: any;
|
|
10
|
+
}
|