valgen 5.13.1 → 5.13.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 CHANGED
@@ -1,3 +1,17 @@
1
+ # v5.13.3
2
+ [2025-03-17]
3
+
4
+ ### Fixes
5
+
6
+ * fix: isEmpty and isNotEmpty rules adds error issue twice ([`d74b9af`](https://github.com/panates/valgen/commit/d74b9afed10e5d93a97298879c68de8937d55321))
7
+
8
+ # v5.13.2
9
+ [2025-03-15]
10
+
11
+ ### Fixes
12
+
13
+ * fix: Fixed ignoring pipe validators if context.errors has items. ([`0b02ca1`](https://github.com/panates/valgen/commit/0b02ca17762f9512542bc79ad044d1072805f857))
14
+
1
15
  # v5.13.1
2
16
  [2025-03-14]
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,44 @@ 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
66
  else if (Array.isArray(input)) {
65
- if (input.length)
66
- return input;
67
- context.fail(_this, `Array must not be empty`, input);
67
+ if (!input.length)
68
+ context.fail(_this, `Array must not be empty`, input);
69
+ return input;
68
70
  }
69
71
  else if (input instanceof Set) {
70
- if (input.size)
71
- return input;
72
- context.fail(_this, `Set must not be empty`, input);
72
+ if (!input.size)
73
+ context.fail(_this, `Set must not be empty`, input);
74
+ return input;
73
75
  }
74
76
  else if (input instanceof Map) {
75
- if (input.size)
76
- return input;
77
- context.fail(_this, `Map must not be empty`, input);
77
+ if (!input.size)
78
+ context.fail(_this, `Map must not be empty`, input);
79
+ return input;
78
80
  }
79
81
  else if (Buffer.isBuffer(input)) {
80
- if (input.length)
81
- return input;
82
- context.fail(_this, `Buffer must not be empty`, input);
82
+ if (!input.length)
83
+ context.fail(_this, `Buffer must not be empty`, input);
84
+ return input;
83
85
  }
84
86
  else if (input instanceof ArrayBuffer) {
85
- if (input.byteLength)
86
- return input;
87
- context.fail(_this, `ArrayBuffer must not be empty`, input);
87
+ if (!input.byteLength)
88
+ context.fail(_this, `ArrayBuffer must not be empty`, input);
89
+ return input;
88
90
  }
89
91
  else if (typeof input === 'object') {
90
- if (input instanceof Date || Object.keys(input).length)
92
+ if (input instanceof Date)
91
93
  return input;
92
- context.fail(_this, `Object must not be empty`, input);
94
+ if (!Object.keys(input).length)
95
+ context.fail(_this, `Object must not be empty`, input);
96
+ return input;
93
97
  }
94
98
  }
95
99
  context.fail(_this, `Value must not be empty`, input);
100
+ return input;
96
101
  }, options);
97
102
  }
@@ -15,12 +15,13 @@ function pipe(rules, options) {
15
15
  let c;
16
16
  let v = input;
17
17
  let returnValue = input;
18
+ const oldErrors = context.errors.length;
18
19
  for (i = 0; i < l; i++) {
19
20
  c = rules[i];
20
21
  v = c(v, context);
21
22
  if (returnIndex == null || i <= returnIndex)
22
23
  returnValue = v;
23
- if (context.errors.length)
24
+ if (context.errors.length > oldErrors)
24
25
  return;
25
26
  }
26
27
  return returnValue;
@@ -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,44 @@ 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
62
  else if (Array.isArray(input)) {
61
- if (input.length)
62
- return input;
63
- context.fail(_this, `Array must not be empty`, input);
63
+ if (!input.length)
64
+ context.fail(_this, `Array must not be empty`, input);
65
+ return input;
64
66
  }
65
67
  else if (input instanceof Set) {
66
- if (input.size)
67
- return input;
68
- context.fail(_this, `Set must not be empty`, input);
68
+ if (!input.size)
69
+ context.fail(_this, `Set must not be empty`, input);
70
+ return input;
69
71
  }
70
72
  else if (input instanceof Map) {
71
- if (input.size)
72
- return input;
73
- context.fail(_this, `Map must not be empty`, input);
73
+ if (!input.size)
74
+ context.fail(_this, `Map must not be empty`, input);
75
+ return input;
74
76
  }
75
77
  else if (Buffer.isBuffer(input)) {
76
- if (input.length)
77
- return input;
78
- context.fail(_this, `Buffer must not be empty`, input);
78
+ if (!input.length)
79
+ context.fail(_this, `Buffer must not be empty`, input);
80
+ return input;
79
81
  }
80
82
  else if (input instanceof ArrayBuffer) {
81
- if (input.byteLength)
82
- return input;
83
- context.fail(_this, `ArrayBuffer must not be empty`, input);
83
+ if (!input.byteLength)
84
+ context.fail(_this, `ArrayBuffer must not be empty`, input);
85
+ return input;
84
86
  }
85
87
  else if (typeof input === 'object') {
86
- if (input instanceof Date || Object.keys(input).length)
88
+ if (input instanceof Date)
87
89
  return input;
88
- context.fail(_this, `Object must not be empty`, input);
90
+ if (!Object.keys(input).length)
91
+ context.fail(_this, `Object must not be empty`, input);
92
+ return input;
89
93
  }
90
94
  }
91
95
  context.fail(_this, `Value must not be empty`, input);
96
+ return input;
92
97
  }, options);
93
98
  }
@@ -11,12 +11,13 @@ export function pipe(rules, options) {
11
11
  let c;
12
12
  let v = input;
13
13
  let returnValue = input;
14
+ const oldErrors = context.errors.length;
14
15
  for (i = 0; i < l; i++) {
15
16
  c = rules[i];
16
17
  v = c(v, context);
17
18
  if (returnIndex == null || i <= returnIndex)
18
19
  returnValue = v;
19
- if (context.errors.length)
20
+ if (context.errors.length > oldErrors)
20
21
  return;
21
22
  }
22
23
  return returnValue;
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.1",
4
+ "version": "5.13.3",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {