valgen 5.13.2 → 5.13.4
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
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# v5.13.4
|
|
2
|
+
[2025-03-26]
|
|
3
|
+
|
|
4
|
+
### Fixes
|
|
5
|
+
|
|
6
|
+
* fix: isNotEmpty do not work for number and boolean types ([`e5175d8`](https://github.com/panates/valgen/commit/e5175d82f532a0a8370754fa6739a13221401788))
|
|
7
|
+
|
|
8
|
+
# v5.13.3
|
|
9
|
+
[2025-03-17]
|
|
10
|
+
|
|
11
|
+
### Fixes
|
|
12
|
+
|
|
13
|
+
* fix: isEmpty and isNotEmpty rules adds error issue twice ([`d74b9af`](https://github.com/panates/valgen/commit/d74b9afed10e5d93a97298879c68de8937d55321))
|
|
14
|
+
|
|
1
15
|
# v5.13.2
|
|
2
16
|
[2025-03-15]
|
|
3
17
|
|
|
@@ -12,39 +12,41 @@ function isEmpty(options) {
|
|
|
12
12
|
if (input == null)
|
|
13
13
|
return input;
|
|
14
14
|
if (typeof input === 'string') {
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (input)
|
|
16
|
+
context.fail(_this, `Value must be an empty string`, input);
|
|
17
|
+
return input;
|
|
18
18
|
}
|
|
19
19
|
else if (Array.isArray(input)) {
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (input.length)
|
|
21
|
+
context.fail(_this, `Value must be an empty array`, input);
|
|
22
|
+
return input;
|
|
23
23
|
}
|
|
24
24
|
else if (input instanceof Set) {
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (input.size)
|
|
26
|
+
context.fail(_this, `Value must be an empty Set`, input);
|
|
27
|
+
return input;
|
|
28
28
|
}
|
|
29
29
|
else if (input instanceof Map) {
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
if (input.size)
|
|
31
|
+
context.fail(_this, `Value must be an empty Map`, input);
|
|
32
|
+
return input;
|
|
33
33
|
}
|
|
34
34
|
else if (Buffer.isBuffer(input)) {
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
if (input.length)
|
|
36
|
+
context.fail(_this, `Value must be an empty Buffer`, input);
|
|
37
|
+
return input;
|
|
38
38
|
}
|
|
39
39
|
else if (input instanceof ArrayBuffer) {
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
if (input.byteLength)
|
|
41
|
+
context.fail(_this, `Value must be an empty ArrayBuffer`, input);
|
|
42
|
+
return input;
|
|
43
43
|
}
|
|
44
44
|
else if (typeof input === 'object') {
|
|
45
|
-
if (input instanceof Date
|
|
45
|
+
if (input instanceof Date)
|
|
46
46
|
return input;
|
|
47
|
-
|
|
47
|
+
if (Object.keys(input).length)
|
|
48
|
+
context.fail(_this, `Value must be an empty Object`, input);
|
|
49
|
+
return input;
|
|
48
50
|
}
|
|
49
51
|
context.fail(_this, `Value must be empty`, input);
|
|
50
52
|
}, options);
|
|
@@ -57,41 +59,52 @@ function isNotEmpty(options) {
|
|
|
57
59
|
return (0, index_js_1.validator)('isNotEmpty', (input, context, _this) => {
|
|
58
60
|
if (input != null) {
|
|
59
61
|
if (typeof input === 'string') {
|
|
60
|
-
if (input)
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
if (!input)
|
|
63
|
+
context.fail(_this, `Value must not be empty`, input);
|
|
64
|
+
return input;
|
|
63
65
|
}
|
|
64
|
-
else if (
|
|
65
|
-
if (input
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
else if (typeof input === 'number') {
|
|
67
|
+
if (Number.isNaN(input))
|
|
68
|
+
context.fail(_this, `Value must not be NaN`, input);
|
|
69
|
+
return input;
|
|
68
70
|
}
|
|
69
|
-
else if (input
|
|
70
|
-
if (input
|
|
71
|
+
else if (typeof input === 'object') {
|
|
72
|
+
if (Array.isArray(input)) {
|
|
73
|
+
if (!input.length)
|
|
74
|
+
context.fail(_this, `Array must not be empty`, input);
|
|
71
75
|
return input;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
}
|
|
77
|
+
else if (input instanceof Set) {
|
|
78
|
+
if (!input.size)
|
|
79
|
+
context.fail(_this, `Set must not be empty`, input);
|
|
76
80
|
return input;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
}
|
|
82
|
+
else if (input instanceof Map) {
|
|
83
|
+
if (!input.size)
|
|
84
|
+
context.fail(_this, `Map must not be empty`, input);
|
|
81
85
|
return input;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
}
|
|
87
|
+
else if (Buffer.isBuffer(input)) {
|
|
88
|
+
if (!input.length)
|
|
89
|
+
context.fail(_this, `Buffer must not be empty`, input);
|
|
86
90
|
return input;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
}
|
|
92
|
+
else if (input instanceof ArrayBuffer) {
|
|
93
|
+
if (!input.byteLength)
|
|
94
|
+
context.fail(_this, `ArrayBuffer must not be empty`, input);
|
|
95
|
+
return input;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
if (input instanceof Date)
|
|
99
|
+
return input;
|
|
100
|
+
if (!Object.keys(input).length)
|
|
101
|
+
context.fail(_this, `Object must not be empty`, input);
|
|
91
102
|
return input;
|
|
92
|
-
|
|
103
|
+
}
|
|
93
104
|
}
|
|
105
|
+
return input;
|
|
94
106
|
}
|
|
95
107
|
context.fail(_this, `Value must not be empty`, input);
|
|
108
|
+
return input;
|
|
96
109
|
}, options);
|
|
97
110
|
}
|
|
@@ -8,39 +8,41 @@ export function isEmpty(options) {
|
|
|
8
8
|
if (input == null)
|
|
9
9
|
return input;
|
|
10
10
|
if (typeof input === 'string') {
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (input)
|
|
12
|
+
context.fail(_this, `Value must be an empty string`, input);
|
|
13
|
+
return input;
|
|
14
14
|
}
|
|
15
15
|
else if (Array.isArray(input)) {
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (input.length)
|
|
17
|
+
context.fail(_this, `Value must be an empty array`, input);
|
|
18
|
+
return input;
|
|
19
19
|
}
|
|
20
20
|
else if (input instanceof Set) {
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
if (input.size)
|
|
22
|
+
context.fail(_this, `Value must be an empty Set`, input);
|
|
23
|
+
return input;
|
|
24
24
|
}
|
|
25
25
|
else if (input instanceof Map) {
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (input.size)
|
|
27
|
+
context.fail(_this, `Value must be an empty Map`, input);
|
|
28
|
+
return input;
|
|
29
29
|
}
|
|
30
30
|
else if (Buffer.isBuffer(input)) {
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
if (input.length)
|
|
32
|
+
context.fail(_this, `Value must be an empty Buffer`, input);
|
|
33
|
+
return input;
|
|
34
34
|
}
|
|
35
35
|
else if (input instanceof ArrayBuffer) {
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if (input.byteLength)
|
|
37
|
+
context.fail(_this, `Value must be an empty ArrayBuffer`, input);
|
|
38
|
+
return input;
|
|
39
39
|
}
|
|
40
40
|
else if (typeof input === 'object') {
|
|
41
|
-
if (input instanceof Date
|
|
41
|
+
if (input instanceof Date)
|
|
42
42
|
return input;
|
|
43
|
-
|
|
43
|
+
if (Object.keys(input).length)
|
|
44
|
+
context.fail(_this, `Value must be an empty Object`, input);
|
|
45
|
+
return input;
|
|
44
46
|
}
|
|
45
47
|
context.fail(_this, `Value must be empty`, input);
|
|
46
48
|
}, options);
|
|
@@ -53,41 +55,52 @@ export function isNotEmpty(options) {
|
|
|
53
55
|
return validator('isNotEmpty', (input, context, _this) => {
|
|
54
56
|
if (input != null) {
|
|
55
57
|
if (typeof input === 'string') {
|
|
56
|
-
if (input)
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
if (!input)
|
|
59
|
+
context.fail(_this, `Value must not be empty`, input);
|
|
60
|
+
return input;
|
|
59
61
|
}
|
|
60
|
-
else if (
|
|
61
|
-
if (input
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
else if (typeof input === 'number') {
|
|
63
|
+
if (Number.isNaN(input))
|
|
64
|
+
context.fail(_this, `Value must not be NaN`, input);
|
|
65
|
+
return input;
|
|
64
66
|
}
|
|
65
|
-
else if (input
|
|
66
|
-
if (input
|
|
67
|
+
else if (typeof input === 'object') {
|
|
68
|
+
if (Array.isArray(input)) {
|
|
69
|
+
if (!input.length)
|
|
70
|
+
context.fail(_this, `Array must not be empty`, input);
|
|
67
71
|
return input;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
}
|
|
73
|
+
else if (input instanceof Set) {
|
|
74
|
+
if (!input.size)
|
|
75
|
+
context.fail(_this, `Set must not be empty`, input);
|
|
72
76
|
return input;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
}
|
|
78
|
+
else if (input instanceof Map) {
|
|
79
|
+
if (!input.size)
|
|
80
|
+
context.fail(_this, `Map must not be empty`, input);
|
|
77
81
|
return input;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
}
|
|
83
|
+
else if (Buffer.isBuffer(input)) {
|
|
84
|
+
if (!input.length)
|
|
85
|
+
context.fail(_this, `Buffer must not be empty`, input);
|
|
82
86
|
return input;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
}
|
|
88
|
+
else if (input instanceof ArrayBuffer) {
|
|
89
|
+
if (!input.byteLength)
|
|
90
|
+
context.fail(_this, `ArrayBuffer must not be empty`, input);
|
|
91
|
+
return input;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
if (input instanceof Date)
|
|
95
|
+
return input;
|
|
96
|
+
if (!Object.keys(input).length)
|
|
97
|
+
context.fail(_this, `Object must not be empty`, input);
|
|
87
98
|
return input;
|
|
88
|
-
|
|
99
|
+
}
|
|
89
100
|
}
|
|
101
|
+
return input;
|
|
90
102
|
}
|
|
91
103
|
context.fail(_this, `Value must not be empty`, input);
|
|
104
|
+
return input;
|
|
92
105
|
}, options);
|
|
93
106
|
}
|
package/package.json
CHANGED
package/types/index.d.cts
CHANGED
|
@@ -8,8 +8,8 @@ declare const isBigint: import("./core/validator.js").Validator<bigint, unknown,
|
|
|
8
8
|
declare const isBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, import("./core/types.js").ExecutionOptions>;
|
|
9
9
|
declare const isDate: import("./core/validator.js").Validator<Date, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
10
10
|
declare const isDateString: import("./core/validator.js").Validator<string, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
11
|
-
declare const isEmpty: import("./core/validator.js").Validator<
|
|
12
|
-
declare const isNotEmpty: import("./core/validator.js").Validator<
|
|
11
|
+
declare const isEmpty: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
|
|
12
|
+
declare const isNotEmpty: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
|
|
13
13
|
declare const isInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
14
14
|
declare const isNull: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
|
|
15
15
|
declare const isNotNull: import("./core/validator.js").Validator<unknown, unknown, import("./core/types.js").ExecutionOptions>;
|
package/types/index.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ declare const isBigint: import("./core/validator.js").Validator<bigint, unknown,
|
|
|
8
8
|
declare const isBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, import("./core/types.js").ExecutionOptions>;
|
|
9
9
|
declare const isDate: import("./core/validator.js").Validator<Date, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
10
10
|
declare const isDateString: import("./core/validator.js").Validator<string, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
11
|
-
declare const isEmpty: import("./core/validator.js").Validator<
|
|
12
|
-
declare const isNotEmpty: import("./core/validator.js").Validator<
|
|
11
|
+
declare const isEmpty: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
|
|
12
|
+
declare const isNotEmpty: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
|
|
13
13
|
declare const isInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
14
14
|
declare const isNull: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
|
|
15
15
|
declare const isNotNull: import("./core/validator.js").Validator<unknown, unknown, import("./core/types.js").ExecutionOptions>;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { type ValidationOptions } from '../../core/index.js';
|
|
2
|
-
type IsEmptyInput = string | any[] | object | Set<any> | Map<any, any>;
|
|
3
2
|
/**
|
|
4
3
|
* Checks if value is an empty. Value should be string, array, set, map or object
|
|
5
4
|
* @validator isEmpty
|
|
6
5
|
*/
|
|
7
|
-
export declare function isEmpty(options?: ValidationOptions): import("../../core/validator.js").Validator<
|
|
6
|
+
export declare function isEmpty(options?: ValidationOptions): import("../../core/validator.js").Validator<any, any, import("../../core/types.js").ExecutionOptions>;
|
|
8
7
|
/**
|
|
9
8
|
* Checks if value is a not empty. Value should be string, array, set, map or object
|
|
10
9
|
* @validator isNotEmpty
|
|
11
10
|
*/
|
|
12
|
-
export declare function isNotEmpty(options?: ValidationOptions): import("../../core/validator.js").Validator<
|
|
13
|
-
export {};
|
|
11
|
+
export declare function isNotEmpty(options?: ValidationOptions): import("../../core/validator.js").Validator<any, any, import("../../core/types.js").ExecutionOptions>;
|