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 (!input)
16
- return input;
17
- context.fail(_this, `Value must be an empty string`, input);
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 (!input.length)
21
- return input;
22
- context.fail(_this, `Value must be an empty array`, input);
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 (!input.size)
26
- return input;
27
- context.fail(_this, `Value must be an empty Set`, input);
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 (!input.size)
31
- return input;
32
- context.fail(_this, `Value must be an empty Map`, input);
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 (!input.length)
36
- return input;
37
- context.fail(_this, `Value must be an empty Buffer`, input);
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 (!input.byteLength)
41
- return input;
42
- context.fail(_this, `Value must be an empty ArrayBuffer`, input);
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 || !Object.keys(input).length)
45
+ if (input instanceof Date)
46
46
  return input;
47
- context.fail(_this, `Value must be an empty Object`, input);
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
- return input;
62
- context.fail(_this, `Value must not be empty`, input);
62
+ if (!input)
63
+ context.fail(_this, `Value must not be empty`, input);
64
+ return input;
63
65
  }
64
- else if (Array.isArray(input)) {
65
- if (input.length)
66
- return input;
67
- context.fail(_this, `Array must not be empty`, input);
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 instanceof Set) {
70
- if (input.size)
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
- context.fail(_this, `Set must not be empty`, input);
73
- }
74
- else if (input instanceof Map) {
75
- if (input.size)
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
- context.fail(_this, `Map must not be empty`, input);
78
- }
79
- else if (Buffer.isBuffer(input)) {
80
- if (input.length)
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
- context.fail(_this, `Buffer must not be empty`, input);
83
- }
84
- else if (input instanceof ArrayBuffer) {
85
- if (input.byteLength)
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
- context.fail(_this, `ArrayBuffer must not be empty`, input);
88
- }
89
- else if (typeof input === 'object') {
90
- if (input instanceof Date || Object.keys(input).length)
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
- context.fail(_this, `Object must not be empty`, input);
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 (!input)
12
- return input;
13
- context.fail(_this, `Value must be an empty string`, input);
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 (!input.length)
17
- return input;
18
- context.fail(_this, `Value must be an empty array`, input);
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 (!input.size)
22
- return input;
23
- context.fail(_this, `Value must be an empty Set`, input);
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 (!input.size)
27
- return input;
28
- context.fail(_this, `Value must be an empty Map`, input);
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 (!input.length)
32
- return input;
33
- context.fail(_this, `Value must be an empty Buffer`, input);
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 (!input.byteLength)
37
- return input;
38
- context.fail(_this, `Value must be an empty ArrayBuffer`, input);
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 || !Object.keys(input).length)
41
+ if (input instanceof Date)
42
42
  return input;
43
- context.fail(_this, `Value must be an empty Object`, input);
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
- return input;
58
- context.fail(_this, `Value must not be empty`, input);
58
+ if (!input)
59
+ context.fail(_this, `Value must not be empty`, input);
60
+ return input;
59
61
  }
60
- else if (Array.isArray(input)) {
61
- if (input.length)
62
- return input;
63
- context.fail(_this, `Array must not be empty`, input);
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 instanceof Set) {
66
- if (input.size)
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
- context.fail(_this, `Set must not be empty`, input);
69
- }
70
- else if (input instanceof Map) {
71
- if (input.size)
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
- context.fail(_this, `Map must not be empty`, input);
74
- }
75
- else if (Buffer.isBuffer(input)) {
76
- if (input.length)
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
- context.fail(_this, `Buffer must not be empty`, input);
79
- }
80
- else if (input instanceof ArrayBuffer) {
81
- if (input.byteLength)
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
- context.fail(_this, `ArrayBuffer must not be empty`, input);
84
- }
85
- else if (typeof input === 'object') {
86
- if (input instanceof Date || Object.keys(input).length)
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
- context.fail(_this, `Object must not be empty`, input);
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
@@ -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.13.2",
4
+ "version": "5.13.4",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
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<string | object | any[] | Set<any> | Map<any, any>, string | object | any[] | Set<any> | Map<any, any>, import("./core/types.js").ExecutionOptions>;
12
- declare const isNotEmpty: import("./core/validator.js").Validator<string | object | any[] | Set<any> | Map<any, any>, string | object | any[] | Set<any> | Map<any, any>, import("./core/types.js").ExecutionOptions>;
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<string | object | any[] | Set<any> | Map<any, any>, string | object | any[] | Set<any> | Map<any, any>, import("./core/types.js").ExecutionOptions>;
12
- declare const isNotEmpty: import("./core/validator.js").Validator<string | object | any[] | Set<any> | Map<any, any>, string | object | any[] | Set<any> | Map<any, any>, import("./core/types.js").ExecutionOptions>;
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<IsEmptyInput, IsEmptyInput, import("../../core/types.js").ExecutionOptions>;
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<IsEmptyInput, IsEmptyInput, import("../../core/types.js").ExecutionOptions>;
13
- export {};
11
+ export declare function isNotEmpty(options?: ValidationOptions): import("../../core/validator.js").Validator<any, any, import("../../core/types.js").ExecutionOptions>;