typebox 1.3.19 → 1.3.20
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/build/guard/emit.mjs +2 -4
- package/build/guard/guard.mjs +6 -18
- package/package.json +1 -1
package/build/guard/emit.mjs
CHANGED
|
@@ -106,15 +106,13 @@ export function IsMaxLength(value, length) {
|
|
|
106
106
|
// Array
|
|
107
107
|
// --------------------------------------------------------------------------
|
|
108
108
|
export function Every(value, offset, params, expression) {
|
|
109
|
-
return G.IsEqual(offset, '0')
|
|
110
|
-
? `${value}.every((${params[0]}, ${params[1]}) => ${expression})`
|
|
111
|
-
: `((value, callback) => { for(let index = ${offset}; index < value.length; index++) if (!callback(value[index], index)) return false; return true })(${value}, (${params[0]}, ${params[1]}) => ${expression})`;
|
|
109
|
+
return G.IsEqual(offset, '0') ? `${value}.every((${params[0]}, ${params[1]}) => (${expression}))` : `${value}.every((${params[0]}, ${params[1]}) => (${params[1]} < ${offset}) || (${expression}))`;
|
|
112
110
|
}
|
|
113
111
|
export function Some(value, params, expression) {
|
|
114
112
|
return `${value}.some((${params[0]}, ${params[1]}) => ${expression})`;
|
|
115
113
|
}
|
|
116
114
|
export function SomeAll(value, params, expression) {
|
|
117
|
-
return `((value
|
|
115
|
+
return `((value) => { let result = false; value.forEach((${params[0]}, ${params[1]}) => { if (${expression}) result = true }); return result })(${value})`;
|
|
118
116
|
}
|
|
119
117
|
export function Counted(value, params, expression) {
|
|
120
118
|
return `${value}.reduce((result, ${params[0]}, ${params[1]}) => (${expression}) ? ++result : result, 0)`;
|
package/build/guard/guard.mjs
CHANGED
|
@@ -140,36 +140,24 @@ export function IsMinLength(value, length) {
|
|
|
140
140
|
// --------------------------------------------------------------------------
|
|
141
141
|
/** Returns true if every element from offset satisfies the callback, short-circuiting on the first failure */
|
|
142
142
|
export function Every(value, offset, callback) {
|
|
143
|
-
|
|
144
|
-
if (!callback(value[index], index))
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
return true;
|
|
143
|
+
return value.every((item, index) => (index < offset) || callback(item, index));
|
|
148
144
|
}
|
|
149
145
|
/** Returns true if every element from offset satisfies the callback, using exhaustive enumeration */
|
|
150
146
|
export function EveryAll(value, offset, callback) {
|
|
151
147
|
let result = true;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
result = false;
|
|
155
|
-
}
|
|
148
|
+
value.forEach((item, index) => { if ((index >= offset) && !callback(item, index))
|
|
149
|
+
result = false; });
|
|
156
150
|
return result;
|
|
157
151
|
}
|
|
158
152
|
/** Returns true if some element satisfies the callback, short-circuiting on the first success */
|
|
159
153
|
export function Some(value, callback) {
|
|
160
|
-
|
|
161
|
-
if (callback(value[index], index))
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
return false;
|
|
154
|
+
return value.some((value, index) => callback(value, index));
|
|
165
155
|
}
|
|
166
156
|
/** Returns true if some element satisfies the callback, using exhaustive enumeration */
|
|
167
157
|
export function SomeAll(value, callback) {
|
|
168
158
|
let result = false;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
result = true;
|
|
172
|
-
}
|
|
159
|
+
value.forEach((item, index) => { if (callback(item, index))
|
|
160
|
+
result = true; });
|
|
173
161
|
return result;
|
|
174
162
|
}
|
|
175
163
|
/** Returns the count of elements that satisfy the callback */
|