@sinclair/typebox 0.25.12 → 0.25.13

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.
@@ -108,7 +108,7 @@ exports.TypeCompilerUnknownTypeError = TypeCompilerUnknownTypeError;
108
108
  var TypeCompiler;
109
109
  (function (TypeCompiler) {
110
110
  function IsNumber(value) {
111
- return typeof value === 'number';
111
+ return typeof value === 'number' && !globalThis.isNaN(value);
112
112
  }
113
113
  // -------------------------------------------------------------------
114
114
  // Types
@@ -174,7 +174,7 @@ var TypeCompiler;
174
174
  yield `(${value} === null)`;
175
175
  }
176
176
  function* Number(schema, value) {
177
- yield `(typeof ${value} === 'number')`;
177
+ yield `(typeof ${value} === 'number' && !isNaN(${value}))`;
178
178
  if (IsNumber(schema.multipleOf))
179
179
  yield `(${value} % ${schema.multipleOf} === 0)`;
180
180
  if (IsNumber(schema.exclusiveMinimum))
package/errors/errors.js CHANGED
@@ -101,7 +101,7 @@ exports.ValueErrorsUnknownTypeError = ValueErrorsUnknownTypeError;
101
101
  var ValueErrors;
102
102
  (function (ValueErrors) {
103
103
  function IsNumber(value) {
104
- return typeof value === 'number';
104
+ return typeof value === 'number' && !isNaN(value);
105
105
  }
106
106
  function* Any(schema, references, path, value) { }
107
107
  function* Array(schema, references, path, value) {
@@ -161,7 +161,7 @@ var ValueErrors;
161
161
  }
162
162
  }
163
163
  function* Integer(schema, references, path, value) {
164
- if (!(typeof value === 'number')) {
164
+ if (!(typeof value === 'number' && globalThis.Number.isInteger(value))) {
165
165
  return yield { type: ValueErrorType.Number, schema, path, value, message: `Expected number` };
166
166
  }
167
167
  if (!globalThis.Number.isInteger(value)) {
@@ -198,7 +198,7 @@ var ValueErrors;
198
198
  }
199
199
  }
200
200
  function* Number(schema, references, path, value) {
201
- if (!(typeof value === 'number')) {
201
+ if (!(typeof value === 'number' && !isNaN(value))) {
202
202
  return yield { type: ValueErrorType.Number, schema, path, value, message: `Expected number` };
203
203
  }
204
204
  if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
package/guard/guard.js CHANGED
@@ -70,7 +70,7 @@ var TypeGuard;
70
70
  return typeof value === 'string';
71
71
  }
72
72
  function IsNumber(value) {
73
- return typeof value === 'number';
73
+ return typeof value === 'number' && !isNaN(value);
74
74
  }
75
75
  function IsBoolean(value) {
76
76
  return typeof value === 'boolean';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.25.12",
3
+ "version": "0.25.13",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -73,8 +73,8 @@ License MIT
73
73
  - [Overview](#overview)
74
74
  - [Example](#Example)
75
75
  - [Types](#types)
76
- - [Standard Types](#types-standard)
77
- - [Extended Types](#types-extended)
76
+ - [Standard](#types-standard)
77
+ - [Extended](#types-extended)
78
78
  - [Modifiers](#types-modifiers)
79
79
  - [Options](#types-options)
80
80
  - [Reference](#types-reference)
@@ -189,7 +189,7 @@ TypeBox provides a set of functions that allow you to compose JSON Schema simila
189
189
 
190
190
  <a name='types-standard'></a>
191
191
 
192
- ### Standard Types
192
+ ### Standard
193
193
 
194
194
  The following table lists the Standard TypeBox types.
195
195
 
@@ -396,7 +396,7 @@ The following table lists the Standard TypeBox types.
396
396
 
397
397
  <a name='types-extended'></a>
398
398
 
399
- ### Extended Types
399
+ ### Extended
400
400
 
401
401
  TypeBox provides a set of extended types that can be used to express schematics for core JavaScript constructs and primitives. Extended types are not valid JSON Schema and will not validate using typical validation. These types however can be used to frame JSON schema and describe callable RPC interfaces that may receive JSON validated data.
402
402
 
@@ -1205,29 +1205,29 @@ This benchmark measures compilation performance for varying types. You can revie
1205
1205
  ┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
1206
1206
  │ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
1207
1207
  ├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
1208
- │ Number │ 2000 │ ' 415 ms' │ ' 14 ms' │ ' 29.64 x' │
1209
- │ String │ 2000 │ ' 335 ms' │ ' 12 ms' │ ' 27.92 x' │
1210
- │ Boolean │ 2000 │ ' 295 ms' │ ' 13 ms' │ ' 22.69 x' │
1211
- │ Null │ 2000 │ ' 255 ms' │ ' 8 ms' │ ' 31.88 x' │
1212
- │ RegEx │ 2000 │ ' 482 ms' │ ' 17 ms' │ ' 28.35 x' │
1213
- │ ObjectA │ 2000 │ ' 2700 ms' │ ' 55 ms' │ ' 49.09 x' │
1214
- │ ObjectB │ 2000 │ ' 2871 ms' │ ' 36 ms' │ ' 79.75 x' │
1215
- │ Tuple │ 2000 │ ' 1229 ms' │ ' 22 ms' │ ' 55.86 x' │
1216
- │ Union │ 2000 │ ' 1216 ms' │ ' 26 ms' │ ' 46.77 x' │
1217
- │ Vector4 │ 2000 │ ' 1575 ms' │ ' 25 ms' │ ' 63.00 x' │
1218
- │ Matrix4 │ 2000 │ ' 908 ms' │ ' 13 ms' │ ' 69.85 x' │
1219
- │ Literal_String │ 2000 │ ' 353 ms' │ ' 9 ms' │ ' 39.22 x' │
1220
- │ Literal_Number │ 2000 │ ' 371 ms' │ ' 7 ms' │ ' 53.00 x' │
1221
- │ Literal_Boolean │ 2000 │ ' 361 ms' │ ' 8 ms' │ ' 45.13 x' │
1222
- │ Array_Number │ 2000 │ ' 694 ms' │ ' 7 ms' │ ' 99.14 x' │
1223
- │ Array_String │ 2000 │ ' 778 ms' │ ' 8 ms' │ ' 97.25 x' │
1224
- │ Array_Boolean │ 2000 │ ' 735 ms' │ ' 7 ms' │ ' 105.00 x' │
1225
- │ Array_ObjectA │ 2000 │ ' 3732 ms' │ ' 44 ms' │ ' 84.82 x' │
1226
- │ Array_ObjectB │ 2000 │ ' 3624 ms' │ ' 40 ms' │ ' 90.60 x' │
1227
- │ Array_Tuple │ 2000 │ ' 2101 ms' │ ' 15 ms' │ ' 140.07 x' │
1228
- │ Array_Union │ 2000 │ ' 1480 ms' │ ' 25 ms' │ ' 59.20 x' │
1229
- │ Array_Vector4 │ 2000 │ ' 2175 ms' │ ' 18 ms' │ ' 120.83 x' │
1230
- │ Array_Matrix4 │ 2000 │ ' 1516 ms' │ ' 13 ms' │ ' 116.62 x' │
1208
+ │ Number │ 2000 │ ' 437 ms' │ ' 15 ms' │ ' 29.13 x' │
1209
+ │ String │ 2000 │ ' 332 ms' │ ' 13 ms' │ ' 25.54 x' │
1210
+ │ Boolean │ 2000 │ ' 293 ms' │ ' 12 ms' │ ' 24.42 x' │
1211
+ │ Null │ 2000 │ ' 259 ms' │ ' 9 ms' │ ' 28.78 x' │
1212
+ │ RegEx │ 2000 │ ' 505 ms' │ ' 21 ms' │ ' 24.05 x' │
1213
+ │ ObjectA │ 2000 │ ' 2726 ms' │ ' 53 ms' │ ' 51.43 x' │
1214
+ │ ObjectB │ 2000 │ ' 2835 ms' │ ' 37 ms' │ ' 76.62 x' │
1215
+ │ Tuple │ 2000 │ ' 1239 ms' │ ' 24 ms' │ ' 51.63 x' │
1216
+ │ Union │ 2000 │ ' 1244 ms' │ ' 34 ms' │ ' 36.59 x' │
1217
+ │ Vector4 │ 2000 │ ' 1521 ms' │ ' 21 ms' │ ' 72.43 x' │
1218
+ │ Matrix4 │ 2000 │ ' 836 ms' │ ' 10 ms' │ ' 83.60 x' │
1219
+ │ Literal_String │ 2000 │ ' 333 ms' │ ' 9 ms' │ ' 37.00 x' │
1220
+ │ Literal_Number │ 2000 │ ' 357 ms' │ ' 9 ms' │ ' 39.67 x' │
1221
+ │ Literal_Boolean │ 2000 │ ' 352 ms' │ ' 6 ms' │ ' 58.67 x' │
1222
+ │ Array_Number │ 2000 │ ' 685 ms' │ ' 12 ms' │ ' 57.08 x' │
1223
+ │ Array_String │ 2000 │ ' 720 ms' │ ' 12 ms' │ ' 60.00 x' │
1224
+ │ Array_Boolean │ 2000 │ ' 709 ms' │ ' 8 ms' │ ' 88.63 x' │
1225
+ │ Array_ObjectA │ 2000 │ ' 3590 ms' │ ' 40 ms' │ ' 89.75 x' │
1226
+ │ Array_ObjectB │ 2000 │ ' 3610 ms' │ ' 51 ms' │ ' 70.78 x' │
1227
+ │ Array_Tuple │ 2000 │ ' 2124 ms' │ ' 19 ms' │ ' 111.79 x' │
1228
+ │ Array_Union │ 2000 │ ' 1533 ms' │ ' 21 ms' │ ' 73.00 x' │
1229
+ │ Array_Vector4 │ 2000 │ ' 2278 ms' │ ' 19 ms' │ ' 119.89 x' │
1230
+ │ Array_Matrix4 │ 2000 │ ' 1504 ms' │ ' 20 ms' │ ' 75.20 x' │
1231
1231
  └──────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
1232
1232
  ```
1233
1233
 
@@ -1241,31 +1241,31 @@ This benchmark measures validation performance for varying types. You can review
1241
1241
  ┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
1242
1242
  │ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
1243
1243
  ├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
1244
- │ Number │ 1000000 │ ' 28 ms' │ ' 6 ms' │ ' 5 ms' │ ' 1.20 x' │
1245
- │ String │ 1000000 │ ' 22 ms' │ ' 21 ms' │ ' 13 ms' │ ' 1.62 x' │
1246
- │ Boolean │ 1000000 │ ' 22 ms' │ ' 21 ms' │ ' 11 ms' │ ' 1.91 x' │
1247
- │ Null │ 1000000 │ ' 25 ms' │ ' 20 ms' │ ' 11 ms' │ ' 1.82 x' │
1248
- │ RegEx │ 1000000 │ ' 167 ms' │ ' 48 ms' │ ' 38 ms' │ ' 1.26 x' │
1249
- │ ObjectA │ 1000000 │ ' 591 ms' │ ' 36 ms' │ ' 22 ms' │ ' 1.64 x' │
1250
- │ ObjectB │ 1000000 │ ' 1168 ms' │ ' 61 ms' │ ' 37 ms' │ ' 1.65 x' │
1251
- │ Tuple │ 1000000 │ ' 127 ms' │ ' 24 ms' │ ' 14 ms' │ ' 1.71 x' │
1252
- │ Union │ 1000000 │ ' 340 ms' │ ' 26 ms' │ ' 16 ms' │ ' 1.63 x' │
1253
- │ Recursive │ 1000000 │ ' 3174 ms' │ ' 432 ms' │ ' 100 ms' │ ' 4.32 x' │
1254
- │ Vector4 │ 1000000 │ ' 142 ms' │ ' 24 ms' │ ' 12 ms' │ ' 2.00 x' │
1255
- │ Matrix4 │ 1000000 │ ' 577 ms' │ ' 40 ms' │ ' 28 ms' │ ' 1.43 x' │
1256
- │ Literal_String │ 1000000 │ ' 47 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
1257
- │ Literal_Number │ 1000000 │ ' 47 ms' │ ' 19 ms' │ ' 9 ms' │ ' 2.11 x' │
1258
- │ Literal_Boolean │ 1000000 │ ' 45 ms' │ ' 19 ms' │ ' 11 ms' │ ' 1.73 x' │
1259
- │ Array_Number │ 1000000 │ ' 432 ms' │ ' 33 ms' │ ' 19 ms' │ ' 1.74 x' │
1260
- │ Array_String │ 1000000 │ ' 462 ms' │ ' 32 ms' │ ' 22 ms' │ ' 1.45 x' │
1261
- │ Array_Boolean │ 1000000 │ ' 455 ms' │ ' 32 ms' │ ' 26 ms' │ ' 1.23 x' │
1262
- │ Array_ObjectA │ 1000000 │ ' 14595 ms' │ ' 2306 ms' │ ' 1496 ms' │ ' 1.54 x' │
1263
- │ Array_ObjectB │ 1000000 │ ' 17310 ms' │ ' 2625 ms' │ ' 2105 ms' │ ' 1.25 x' │
1264
- │ Array_Tuple │ 1000000 │ ' 1794 ms' │ ' 97 ms' │ ' 66 ms' │ ' 1.47 x' │
1265
- │ Array_Union │ 1000000 │ ' 5085 ms' │ ' 246 ms' │ ' 91 ms' │ ' 2.70 x' │
1266
- │ Array_Recursive │ 1000000 │ ' 59747 ms' │ ' 7866 ms' │ ' 1136 ms' │ ' 6.92 x' │
1267
- │ Array_Vector4 │ 1000000 │ ' 2375 ms' │ ' 99 ms' │ ' 48 ms' │ ' 2.06 x' │
1268
- │ Array_Matrix4 │ 1000000 │ ' 13115 ms' │ ' 385 ms' │ ' 246 ms' │ ' 1.57 x' │
1244
+ │ Number │ 1000000 │ ' 29 ms' │ ' 6 ms' │ ' 6 ms' │ ' 1.00 x' │
1245
+ │ String │ 1000000 │ ' 24 ms' │ ' 19 ms' │ ' 11 ms' │ ' 1.73 x' │
1246
+ │ Boolean │ 1000000 │ ' 22 ms' │ ' 20 ms' │ ' 11 ms' │ ' 1.82 x' │
1247
+ │ Null │ 1000000 │ ' 27 ms' │ ' 23 ms' │ ' 11 ms' │ ' 2.09 x' │
1248
+ │ RegEx │ 1000000 │ ' 160 ms' │ ' 52 ms' │ ' 40 ms' │ ' 1.30 x' │
1249
+ │ ObjectA │ 1000000 │ ' 577 ms' │ ' 37 ms' │ ' 26 ms' │ ' 1.42 x' │
1250
+ │ ObjectB │ 1000000 │ ' 990 ms' │ ' 50 ms' │ ' 37 ms' │ ' 1.35 x' │
1251
+ │ Tuple │ 1000000 │ ' 124 ms' │ ' 22 ms' │ ' 17 ms' │ ' 1.29 x' │
1252
+ │ Union │ 1000000 │ ' 318 ms' │ ' 24 ms' │ ' 16 ms' │ ' 1.50 x' │
1253
+ │ Recursive │ 1000000 │ ' 3102 ms' │ ' 408 ms' │ ' 102 ms' │ ' 4.00 x' │
1254
+ │ Vector4 │ 1000000 │ ' 150 ms' │ ' 23 ms' │ ' 13 ms' │ ' 1.77 x' │
1255
+ │ Matrix4 │ 1000000 │ ' 579 ms' │ ' 43 ms' │ ' 27 ms' │ ' 1.59 x' │
1256
+ │ Literal_String │ 1000000 │ ' 50 ms' │ ' 22 ms' │ ' 10 ms' │ ' 2.20 x' │
1257
+ │ Literal_Number │ 1000000 │ ' 47 ms' │ ' 21 ms' │ ' 11 ms' │ ' 1.91 x' │
1258
+ │ Literal_Boolean │ 1000000 │ ' 48 ms' │ ' 20 ms' │ ' 10 ms' │ ' 2.00 x' │
1259
+ │ Array_Number │ 1000000 │ ' 429 ms' │ ' 32 ms' │ ' 20 ms' │ ' 1.60 x' │
1260
+ │ Array_String │ 1000000 │ ' 474 ms' │ ' 33 ms' │ ' 25 ms' │ ' 1.32 x' │
1261
+ │ Array_Boolean │ 1000000 │ ' 447 ms' │ ' 35 ms' │ ' 31 ms' │ ' 1.13 x' │
1262
+ │ Array_ObjectA │ 1000000 │ ' 14098 ms' │ ' 2352 ms' │ ' 2015 ms' │ ' 1.17 x' │
1263
+ │ Array_ObjectB │ 1000000 │ ' 16216 ms' │ ' 2628 ms' │ ' 2511 ms' │ ' 1.05 x' │
1264
+ │ Array_Tuple │ 1000000 │ ' 1749 ms' │ ' 95 ms' │ ' 75 ms' │ ' 1.27 x' │
1265
+ │ Array_Union │ 1000000 │ ' 4712 ms' │ ' 233 ms' │ ' 84 ms' │ ' 2.77 x' │
1266
+ │ Array_Recursive │ 1000000 │ ' 56118 ms' │ ' 7192 ms' │ ' 1180 ms' │ ' 6.09 x' │
1267
+ │ Array_Vector4 │ 1000000 │ ' 2284 ms' │ ' 99 ms' │ ' 50 ms' │ ' 1.98 x' │
1268
+ │ Array_Matrix4 │ 1000000 │ ' 12640 ms' │ ' 412 ms' │ ' 272 ms' │ ' 1.51 x' │
1269
1269
  └──────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
1270
1270
  ```
1271
1271
 
package/value/cast.js CHANGED
@@ -137,7 +137,7 @@ var ValueCast;
137
137
  return typeof value === 'bigint';
138
138
  }
139
139
  function IsNumber(value) {
140
- return typeof value === 'number';
140
+ return typeof value === 'number' && !isNaN(value);
141
141
  }
142
142
  function IsStringNumeric(value) {
143
143
  return IsString(value) && !isNaN(value) && !isNaN(parseFloat(value));
package/value/check.js CHANGED
@@ -42,7 +42,7 @@ exports.ValueCheckUnknownTypeError = ValueCheckUnknownTypeError;
42
42
  var ValueCheck;
43
43
  (function (ValueCheck) {
44
44
  function IsNumber(value) {
45
- return typeof value === 'number';
45
+ return typeof value === 'number' && !isNaN(value);
46
46
  }
47
47
  function Any(schema, references, value) {
48
48
  return true;
@@ -99,7 +99,7 @@ var ValueCheck;
99
99
  return typeof value === 'function';
100
100
  }
101
101
  function Integer(schema, references, value) {
102
- if (!(typeof value === 'number')) {
102
+ if (!(typeof value === 'number' && globalThis.Number.isInteger(value))) {
103
103
  return false;
104
104
  }
105
105
  if (!globalThis.Number.isInteger(value)) {
@@ -132,7 +132,7 @@ var ValueCheck;
132
132
  return value === null;
133
133
  }
134
134
  function Number(schema, references, value) {
135
- if (!(typeof value === 'number')) {
135
+ if (!(typeof value === 'number' && !isNaN(value))) {
136
136
  return false;
137
137
  }
138
138
  if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {