typebox 1.3.19 → 1.3.21

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.
@@ -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, callback) => { let result = false; for(let index = 0; index < value.length; index++) if (callback(value[index], index)) result = true; return result })(${value}, (${params[0]}, ${params[1]}) => ${expression})`;
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)`;
@@ -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
- for (let index = offset; index < value.length; index++) {
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
- for (let index = offset; index < value.length; index++) {
153
- if (!callback(value[index], index))
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
- for (let index = 0; index < value.length; index++) {
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
- for (let index = 0; index < value.length; index++) {
170
- if (callback(value[index], index))
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 */
@@ -7,7 +7,19 @@ import { UnicodeRegExp } from './_regexp.mjs';
7
7
  import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
8
8
  import { BuildSchemaPushStack, CheckSchemaPushStack, ErrorSchemaPushStack } from './schema.mjs';
9
9
  // ------------------------------------------------------------------
10
- // Common: GetPropertiesPattern
10
+ // Optimization: IsAdditionalPropertiesIgnored
11
+ //
12
+ // We can ignore additionalProperties if the schema is true-like and
13
+ // we are not in an unevaluated context, noting that additional
14
+ // properties are considered tracked, evaluated keys.
15
+ // ------------------------------------------------------------------
16
+ function IsAdditionalPropertiesIgnored(context, additionalProperties) {
17
+ return !context.UseUnevaluated() &&
18
+ (G.IsEqual(additionalProperties, true) ||
19
+ (G.IsObject(additionalProperties) && G.IsEqual(G.Keys(additionalProperties).length, 0)));
20
+ }
21
+ // ------------------------------------------------------------------
22
+ // Optimization: GetPropertiesPattern
11
23
  //
12
24
  // Constructs a regular expression that matches all property keys
13
25
  // and pattern properties defined in a schema. This approach unifies
@@ -71,6 +83,8 @@ export function BuildAdditionalPropertiesStandard(stack, context, schema, value)
71
83
  // Build
72
84
  // ------------------------------------------------------------------
73
85
  export function BuildAdditionalProperties(stack, context, schema, value) {
86
+ if (IsAdditionalPropertiesIgnored(context, schema.additionalProperties))
87
+ return E.Constant(true);
74
88
  return CanAdditionalPropertiesFast(context, schema, value)
75
89
  ? BuildAdditionalPropertiesFast(context, schema, value)
76
90
  : BuildAdditionalPropertiesStandard(stack, context, schema, value);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
4
- "version": "1.3.19",
4
+ "version": "1.3.21",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"