@sinclair/typebox 0.32.0-dev-27 → 0.32.0-dev-28

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.
Files changed (64) hide show
  1. package/build/import/compiler/compiler.mjs +7 -0
  2. package/build/import/errors/errors.d.mts +16 -15
  3. package/build/import/errors/errors.mjs +24 -15
  4. package/build/import/errors/function.mjs +2 -0
  5. package/build/import/type/clone/value.mjs +6 -2
  6. package/build/import/type/extends/extends-check.mjs +137 -125
  7. package/build/import/type/guard/type.d.mts +3 -0
  8. package/build/import/type/guard/type.mjs +10 -0
  9. package/build/import/type/guard/value.d.mts +2 -0
  10. package/build/import/type/guard/value.mjs +4 -0
  11. package/build/import/type/record/record.d.mts +3 -1
  12. package/build/import/type/record/record.mjs +10 -5
  13. package/build/import/type/regexp/regexp.d.mts +11 -4
  14. package/build/import/type/regexp/regexp.mjs +3 -3
  15. package/build/import/type/schema/anyschema.d.mts +2 -1
  16. package/build/import/type/type/javascript.d.mts +2 -2
  17. package/build/import/type/type/javascript.mjs +1 -1
  18. package/build/import/value/cast/cast.d.mts +2 -15
  19. package/build/import/value/cast/cast.mjs +5 -28
  20. package/build/import/value/check/check.mjs +6 -1
  21. package/build/import/value/convert/convert.d.mts +0 -5
  22. package/build/import/value/convert/convert.mjs +0 -12
  23. package/build/import/value/create/create.d.mts +2 -23
  24. package/build/import/value/create/create.mjs +30 -53
  25. package/build/import/value/default/default.mjs +0 -2
  26. package/build/import/value/delta/delta.d.mts +4 -4
  27. package/build/import/value/delta/delta.mjs +12 -12
  28. package/build/import/value/index.d.mts +7 -7
  29. package/build/import/value/index.mjs +6 -6
  30. package/build/import/value/mutate/mutate.d.mts +2 -5
  31. package/build/import/value/mutate/mutate.mjs +5 -10
  32. package/build/require/compiler/compiler.js +7 -0
  33. package/build/require/errors/errors.d.ts +16 -15
  34. package/build/require/errors/errors.js +24 -15
  35. package/build/require/errors/function.js +2 -0
  36. package/build/require/type/clone/value.js +6 -2
  37. package/build/require/type/extends/extends-check.js +137 -125
  38. package/build/require/type/guard/type.d.ts +3 -0
  39. package/build/require/type/guard/type.js +12 -1
  40. package/build/require/type/guard/value.d.ts +2 -0
  41. package/build/require/type/guard/value.js +6 -1
  42. package/build/require/type/record/record.d.ts +3 -1
  43. package/build/require/type/record/record.js +9 -4
  44. package/build/require/type/regexp/regexp.d.ts +11 -4
  45. package/build/require/type/regexp/regexp.js +3 -3
  46. package/build/require/type/schema/anyschema.d.ts +2 -1
  47. package/build/require/type/type/javascript.d.ts +2 -2
  48. package/build/require/type/type/javascript.js +1 -1
  49. package/build/require/value/cast/cast.d.ts +2 -15
  50. package/build/require/value/cast/cast.js +7 -29
  51. package/build/require/value/check/check.js +6 -1
  52. package/build/require/value/convert/convert.d.ts +0 -5
  53. package/build/require/value/convert/convert.js +31 -43
  54. package/build/require/value/create/create.d.ts +2 -23
  55. package/build/require/value/create/create.js +32 -54
  56. package/build/require/value/default/default.js +0 -2
  57. package/build/require/value/delta/delta.d.ts +4 -4
  58. package/build/require/value/delta/delta.js +14 -14
  59. package/build/require/value/index.d.ts +7 -7
  60. package/build/require/value/index.js +8 -19
  61. package/build/require/value/mutate/mutate.d.ts +2 -5
  62. package/build/require/value/mutate/mutate.js +7 -13
  63. package/package.json +1 -1
  64. package/readme.md +8 -7
@@ -43,23 +43,23 @@ function IsStructuralRight(right) {
43
43
  }
44
44
  // prettier-ignore
45
45
  function StructuralRight(left, right) {
46
- return (TypeGuard.IsNever(right) ? TNeverRight(left, right) :
47
- TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
48
- TypeGuard.IsUnion(right) ? TUnionRight(left, right) :
49
- TypeGuard.IsUnknown(right) ? TUnknownRight(left, right) :
50
- TypeGuard.IsAny(right) ? TAnyRight(left, right) :
46
+ return (TypeGuard.IsNever(right) ? FromNeverRight(left, right) :
47
+ TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
48
+ TypeGuard.IsUnion(right) ? FromUnionRight(left, right) :
49
+ TypeGuard.IsUnknown(right) ? FromUnknownRight(left, right) :
50
+ TypeGuard.IsAny(right) ? FromAnyRight(left, right) :
51
51
  Throw('StructuralRight'));
52
52
  }
53
53
  // ------------------------------------------------------------------
54
54
  // Any
55
55
  // ------------------------------------------------------------------
56
56
  // prettier-ignore
57
- function TAnyRight(left, right) {
57
+ function FromAnyRight(left, right) {
58
58
  return ExtendsResult.True;
59
59
  }
60
60
  // prettier-ignore
61
- function TAny(left, right) {
62
- return (TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
61
+ function FromAny(left, right) {
62
+ return (TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
63
63
  (TypeGuard.IsUnion(right) && right.anyOf.some((schema) => TypeGuard.IsAny(schema) || TypeGuard.IsUnknown(schema))) ? ExtendsResult.True :
64
64
  TypeGuard.IsUnion(right) ? ExtendsResult.Union :
65
65
  TypeGuard.IsUnknown(right) ? ExtendsResult.True :
@@ -70,14 +70,14 @@ function TAny(left, right) {
70
70
  // Array
71
71
  // ------------------------------------------------------------------
72
72
  // prettier-ignore
73
- function TArrayRight(left, right) {
73
+ function FromArrayRight(left, right) {
74
74
  return (TypeGuard.IsUnknown(left) ? ExtendsResult.False :
75
75
  TypeGuard.IsAny(left) ? ExtendsResult.Union :
76
76
  TypeGuard.IsNever(left) ? ExtendsResult.True :
77
77
  ExtendsResult.False);
78
78
  }
79
79
  // prettier-ignore
80
- function TArray(left, right) {
80
+ function FromArray(left, right) {
81
81
  return (TypeGuard.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
82
82
  IsStructuralRight(right) ? StructuralRight(left, right) :
83
83
  !TypeGuard.IsArray(right) ? ExtendsResult.False :
@@ -87,7 +87,7 @@ function TArray(left, right) {
87
87
  // AsyncIterator
88
88
  // ------------------------------------------------------------------
89
89
  // prettier-ignore
90
- function TAsyncIterator(left, right) {
90
+ function FromAsyncIterator(left, right) {
91
91
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
92
92
  !TypeGuard.IsAsyncIterator(right) ? ExtendsResult.False :
93
93
  IntoBooleanResult(Visit(left.items, right.items)));
@@ -96,10 +96,10 @@ function TAsyncIterator(left, right) {
96
96
  // BigInt
97
97
  // ------------------------------------------------------------------
98
98
  // prettier-ignore
99
- function TBigInt(left, right) {
99
+ function FromBigInt(left, right) {
100
100
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
101
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
102
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
101
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
102
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
103
103
  TypeGuard.IsBigInt(right) ? ExtendsResult.True :
104
104
  ExtendsResult.False);
105
105
  }
@@ -107,16 +107,16 @@ function TBigInt(left, right) {
107
107
  // Boolean
108
108
  // ------------------------------------------------------------------
109
109
  // prettier-ignore
110
- function TBooleanRight(left, right) {
110
+ function FromBooleanRight(left, right) {
111
111
  return (TypeGuard.IsLiteralBoolean(left) ? ExtendsResult.True :
112
112
  TypeGuard.IsBoolean(left) ? ExtendsResult.True :
113
113
  ExtendsResult.False);
114
114
  }
115
115
  // prettier-ignore
116
- function TBoolean(left, right) {
116
+ function FromBoolean(left, right) {
117
117
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
118
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
119
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
118
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
119
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
120
120
  TypeGuard.IsBoolean(right) ? ExtendsResult.True :
121
121
  ExtendsResult.False);
122
122
  }
@@ -124,9 +124,9 @@ function TBoolean(left, right) {
124
124
  // Constructor
125
125
  // ------------------------------------------------------------------
126
126
  // prettier-ignore
127
- function TConstructor(left, right) {
127
+ function FromConstructor(left, right) {
128
128
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
129
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
129
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
130
130
  !TypeGuard.IsConstructor(right) ? ExtendsResult.False :
131
131
  left.parameters.length > right.parameters.length ? ExtendsResult.False :
132
132
  (!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
@@ -136,10 +136,10 @@ function TConstructor(left, right) {
136
136
  // Date
137
137
  // ------------------------------------------------------------------
138
138
  // prettier-ignore
139
- function TDate(left, right) {
139
+ function FromDate(left, right) {
140
140
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
141
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
142
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
141
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
142
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
143
143
  TypeGuard.IsDate(right) ? ExtendsResult.True :
144
144
  ExtendsResult.False);
145
145
  }
@@ -147,9 +147,9 @@ function TDate(left, right) {
147
147
  // Function
148
148
  // ------------------------------------------------------------------
149
149
  // prettier-ignore
150
- function TFunction(left, right) {
150
+ function FromFunction(left, right) {
151
151
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
152
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
152
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
153
153
  !TypeGuard.IsFunction(right) ? ExtendsResult.False :
154
154
  left.parameters.length > right.parameters.length ? ExtendsResult.False :
155
155
  (!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
@@ -159,30 +159,30 @@ function TFunction(left, right) {
159
159
  // Integer
160
160
  // ------------------------------------------------------------------
161
161
  // prettier-ignore
162
- function TIntegerRight(left, right) {
162
+ function FromIntegerRight(left, right) {
163
163
  return (TypeGuard.IsLiteral(left) && ValueGuard.IsNumber(left.const) ? ExtendsResult.True :
164
164
  TypeGuard.IsNumber(left) || TypeGuard.IsInteger(left) ? ExtendsResult.True :
165
165
  ExtendsResult.False);
166
166
  }
167
167
  // prettier-ignore
168
- function TInteger(left, right) {
168
+ function FromInteger(left, right) {
169
169
  return (TypeGuard.IsInteger(right) || TypeGuard.IsNumber(right) ? ExtendsResult.True :
170
170
  IsStructuralRight(right) ? StructuralRight(left, right) :
171
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
172
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
171
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
172
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
173
173
  ExtendsResult.False);
174
174
  }
175
175
  // ------------------------------------------------------------------
176
176
  // Intersect
177
177
  // ------------------------------------------------------------------
178
178
  // prettier-ignore
179
- function TIntersectRight(left, right) {
179
+ function FromIntersectRight(left, right) {
180
180
  return right.allOf.every((schema) => Visit(left, schema) === ExtendsResult.True)
181
181
  ? ExtendsResult.True
182
182
  : ExtendsResult.False;
183
183
  }
184
184
  // prettier-ignore
185
- function TIntersect(left, right) {
185
+ function FromIntersect(left, right) {
186
186
  return left.allOf.some((schema) => Visit(schema, right) === ExtendsResult.True)
187
187
  ? ExtendsResult.True
188
188
  : ExtendsResult.False;
@@ -191,7 +191,7 @@ function TIntersect(left, right) {
191
191
  // Iterator
192
192
  // ------------------------------------------------------------------
193
193
  // prettier-ignore
194
- function TIterator(left, right) {
194
+ function FromIterator(left, right) {
195
195
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
196
196
  !TypeGuard.IsIterator(right) ? ExtendsResult.False :
197
197
  IntoBooleanResult(Visit(left.items, right.items)));
@@ -200,26 +200,26 @@ function TIterator(left, right) {
200
200
  // Literal
201
201
  // ------------------------------------------------------------------
202
202
  // prettier-ignore
203
- function TLiteral(left, right) {
203
+ function FromLiteral(left, right) {
204
204
  return (TypeGuard.IsLiteral(right) && right.const === left.const ? ExtendsResult.True :
205
205
  IsStructuralRight(right) ? StructuralRight(left, right) :
206
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
207
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
208
- TypeGuard.IsString(right) ? TStringRight(left, right) :
209
- TypeGuard.IsNumber(right) ? TNumberRight(left, right) :
210
- TypeGuard.IsInteger(right) ? TIntegerRight(left, right) :
211
- TypeGuard.IsBoolean(right) ? TBooleanRight(left, right) :
206
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
207
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
208
+ TypeGuard.IsString(right) ? FromStringRight(left, right) :
209
+ TypeGuard.IsNumber(right) ? FromNumberRight(left, right) :
210
+ TypeGuard.IsInteger(right) ? FromIntegerRight(left, right) :
211
+ TypeGuard.IsBoolean(right) ? FromBooleanRight(left, right) :
212
212
  ExtendsResult.False);
213
213
  }
214
214
  // ------------------------------------------------------------------
215
215
  // Never
216
216
  // ------------------------------------------------------------------
217
217
  // prettier-ignore
218
- function TNeverRight(left, right) {
218
+ function FromNeverRight(left, right) {
219
219
  return ExtendsResult.False;
220
220
  }
221
221
  // prettier-ignore
222
- function TNever(left, right) {
222
+ function FromNever(left, right) {
223
223
  return ExtendsResult.True;
224
224
  }
225
225
  // ------------------------------------------------------------------
@@ -237,7 +237,7 @@ function UnwrapTNot(schema) {
237
237
  return depth % 2 === 0 ? current : Unknown();
238
238
  }
239
239
  // prettier-ignore
240
- function TNot(left, right) {
240
+ function FromNot(left, right) {
241
241
  // TypeScript has no concept of negated types, and attempts to correctly check the negated
242
242
  // type at runtime would put TypeBox at odds with TypeScripts ability to statically infer
243
243
  // the type. Instead we unwrap to either unknown or T and continue evaluating.
@@ -250,10 +250,10 @@ function TNot(left, right) {
250
250
  // Null
251
251
  // ------------------------------------------------------------------
252
252
  // prettier-ignore
253
- function TNull(left, right) {
253
+ function FromNull(left, right) {
254
254
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
255
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
256
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
255
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
256
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
257
257
  TypeGuard.IsNull(right) ? ExtendsResult.True :
258
258
  ExtendsResult.False);
259
259
  }
@@ -261,16 +261,16 @@ function TNull(left, right) {
261
261
  // Number
262
262
  // ------------------------------------------------------------------
263
263
  // prettier-ignore
264
- function TNumberRight(left, right) {
264
+ function FromNumberRight(left, right) {
265
265
  return (TypeGuard.IsLiteralNumber(left) ? ExtendsResult.True :
266
266
  TypeGuard.IsNumber(left) || TypeGuard.IsInteger(left) ? ExtendsResult.True :
267
267
  ExtendsResult.False);
268
268
  }
269
269
  // prettier-ignore
270
- function TNumber(left, right) {
270
+ function FromNumber(left, right) {
271
271
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
272
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
273
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
272
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
273
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
274
274
  TypeGuard.IsInteger(right) || TypeGuard.IsNumber(right) ? ExtendsResult.True :
275
275
  ExtendsResult.False);
276
276
  }
@@ -340,7 +340,7 @@ function Property(left, right) {
340
340
  ExtendsResult.True);
341
341
  }
342
342
  // prettier-ignore
343
- function TObjectRight(left, right) {
343
+ function FromObjectRight(left, right) {
344
344
  return (TypeGuard.IsUnknown(left) ? ExtendsResult.False :
345
345
  TypeGuard.IsAny(left) ? ExtendsResult.Union : (TypeGuard.IsNever(left) ||
346
346
  (TypeGuard.IsLiteralString(left) && IsObjectStringLike(right)) ||
@@ -368,9 +368,9 @@ function TObjectRight(left, right) {
368
368
  ExtendsResult.False);
369
369
  }
370
370
  // prettier-ignore
371
- function TObject(left, right) {
371
+ function FromObject(left, right) {
372
372
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
373
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
373
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
374
374
  !TypeGuard.IsObject(right) ? ExtendsResult.False :
375
375
  (() => {
376
376
  for (const key of Object.getOwnPropertyNames(right.properties)) {
@@ -391,7 +391,7 @@ function TObject(left, right) {
391
391
  // Promise
392
392
  // ------------------------------------------------------------------
393
393
  // prettier-ignore
394
- function TPromise(left, right) {
394
+ function FromPromise(left, right) {
395
395
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
396
396
  TypeGuard.IsObject(right) && IsObjectPromiseLike(right) ? ExtendsResult.True :
397
397
  !TypeGuard.IsPromise(right) ? ExtendsResult.False :
@@ -413,7 +413,7 @@ function RecordValue(schema) {
413
413
  Throw('Unable to get record value schema'));
414
414
  }
415
415
  // prettier-ignore
416
- function TRecordRight(left, right) {
416
+ function FromRecordRight(left, right) {
417
417
  const [Key, Value] = [RecordKey(right), RecordValue(right)];
418
418
  return ((TypeGuard.IsLiteralString(left) && TypeGuard.IsNumber(Key) && IntoBooleanResult(Visit(left, Value)) === ExtendsResult.True) ? ExtendsResult.True :
419
419
  TypeGuard.IsUint8Array(left) && TypeGuard.IsNumber(Key) ? Visit(left, Value) :
@@ -430,26 +430,37 @@ function TRecordRight(left, right) {
430
430
  ExtendsResult.False);
431
431
  }
432
432
  // prettier-ignore
433
- function TRecord(left, right) {
433
+ function FromRecord(left, right) {
434
434
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
435
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
435
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
436
436
  !TypeGuard.IsRecord(right) ? ExtendsResult.False :
437
437
  Visit(RecordValue(left), RecordValue(right)));
438
438
  }
439
439
  // ------------------------------------------------------------------
440
+ // RegExp
441
+ // ------------------------------------------------------------------
442
+ // prettier-ignore
443
+ function FromRegExp(left, right) {
444
+ // Note: RegExp types evaluate as strings, not RegExp objects.
445
+ // Here we remap either into string and continue evaluating.
446
+ const L = TypeGuard.IsRegExp(left) ? String() : left;
447
+ const R = TypeGuard.IsRegExp(right) ? String() : right;
448
+ return Visit(L, R);
449
+ }
450
+ // ------------------------------------------------------------------
440
451
  // String
441
452
  // ------------------------------------------------------------------
442
453
  // prettier-ignore
443
- function TStringRight(left, right) {
454
+ function FromStringRight(left, right) {
444
455
  return (TypeGuard.IsLiteral(left) && ValueGuard.IsString(left.const) ? ExtendsResult.True :
445
456
  TypeGuard.IsString(left) ? ExtendsResult.True :
446
457
  ExtendsResult.False);
447
458
  }
448
459
  // prettier-ignore
449
- function TString(left, right) {
460
+ function FromString(left, right) {
450
461
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
451
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
452
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
462
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
463
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
453
464
  TypeGuard.IsString(right) ? ExtendsResult.True :
454
465
  ExtendsResult.False);
455
466
  }
@@ -457,10 +468,10 @@ function TString(left, right) {
457
468
  // Symbol
458
469
  // ------------------------------------------------------------------
459
470
  // prettier-ignore
460
- function TSymbol(left, right) {
471
+ function FromSymbol(left, right) {
461
472
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
462
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
463
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
473
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
474
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
464
475
  TypeGuard.IsSymbol(right) ? ExtendsResult.True :
465
476
  ExtendsResult.False);
466
477
  }
@@ -468,7 +479,7 @@ function TSymbol(left, right) {
468
479
  // TemplateLiteral
469
480
  // ------------------------------------------------------------------
470
481
  // prettier-ignore
471
- function TTemplateLiteral(left, right) {
482
+ function FromTemplateLiteral(left, right) {
472
483
  // TemplateLiteral types are resolved to either unions for finite expressions or string
473
484
  // for infinite expressions. Here we call to TemplateLiteralResolver to resolve for
474
485
  // either type and continue evaluating.
@@ -486,14 +497,14 @@ function IsArrayOfTuple(left, right) {
486
497
  left.items.every((schema) => Visit(schema, right.items) === ExtendsResult.True));
487
498
  }
488
499
  // prettier-ignore
489
- function TTupleRight(left, right) {
500
+ function FromTupleRight(left, right) {
490
501
  return (TypeGuard.IsNever(left) ? ExtendsResult.True :
491
502
  TypeGuard.IsUnknown(left) ? ExtendsResult.False :
492
503
  TypeGuard.IsAny(left) ? ExtendsResult.Union :
493
504
  ExtendsResult.False);
494
505
  }
495
506
  // prettier-ignore
496
- function TTuple(left, right) {
507
+ function FromTuple(left, right) {
497
508
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
498
509
  TypeGuard.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
499
510
  TypeGuard.IsArray(right) && IsArrayOfTuple(left, right) ? ExtendsResult.True :
@@ -507,10 +518,10 @@ function TTuple(left, right) {
507
518
  // Uint8Array
508
519
  // ------------------------------------------------------------------
509
520
  // prettier-ignore
510
- function TUint8Array(left, right) {
521
+ function FromUint8Array(left, right) {
511
522
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
512
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
513
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
523
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
524
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
514
525
  TypeGuard.IsUint8Array(right) ? ExtendsResult.True :
515
526
  ExtendsResult.False);
516
527
  }
@@ -518,11 +529,11 @@ function TUint8Array(left, right) {
518
529
  // Undefined
519
530
  // ------------------------------------------------------------------
520
531
  // prettier-ignore
521
- function TUndefined(left, right) {
532
+ function FromUndefined(left, right) {
522
533
  return (IsStructuralRight(right) ? StructuralRight(left, right) :
523
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
524
- TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
525
- TypeGuard.IsVoid(right) ? VoidRight(left, right) :
534
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
535
+ TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
536
+ TypeGuard.IsVoid(right) ? FromVoidRight(left, right) :
526
537
  TypeGuard.IsUndefined(right) ? ExtendsResult.True :
527
538
  ExtendsResult.False);
528
539
  }
@@ -530,13 +541,13 @@ function TUndefined(left, right) {
530
541
  // Union
531
542
  // ------------------------------------------------------------------
532
543
  // prettier-ignore
533
- function TUnionRight(left, right) {
544
+ function FromUnionRight(left, right) {
534
545
  return right.anyOf.some((schema) => Visit(left, schema) === ExtendsResult.True)
535
546
  ? ExtendsResult.True
536
547
  : ExtendsResult.False;
537
548
  }
538
549
  // prettier-ignore
539
- function TUnion(left, right) {
550
+ function FromUnion(left, right) {
540
551
  return left.anyOf.every((schema) => Visit(schema, right) === ExtendsResult.True)
541
552
  ? ExtendsResult.True
542
553
  : ExtendsResult.False;
@@ -545,22 +556,22 @@ function TUnion(left, right) {
545
556
  // Unknown
546
557
  // ------------------------------------------------------------------
547
558
  // prettier-ignore
548
- function TUnknownRight(left, right) {
559
+ function FromUnknownRight(left, right) {
549
560
  return ExtendsResult.True;
550
561
  }
551
562
  // prettier-ignore
552
- function TUnknown(left, right) {
553
- return (TypeGuard.IsNever(right) ? TNeverRight(left, right) :
554
- TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
555
- TypeGuard.IsUnion(right) ? TUnionRight(left, right) :
556
- TypeGuard.IsAny(right) ? TAnyRight(left, right) :
557
- TypeGuard.IsString(right) ? TStringRight(left, right) :
558
- TypeGuard.IsNumber(right) ? TNumberRight(left, right) :
559
- TypeGuard.IsInteger(right) ? TIntegerRight(left, right) :
560
- TypeGuard.IsBoolean(right) ? TBooleanRight(left, right) :
561
- TypeGuard.IsArray(right) ? TArrayRight(left, right) :
562
- TypeGuard.IsTuple(right) ? TTupleRight(left, right) :
563
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
563
+ function FromUnknown(left, right) {
564
+ return (TypeGuard.IsNever(right) ? FromNeverRight(left, right) :
565
+ TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
566
+ TypeGuard.IsUnion(right) ? FromUnionRight(left, right) :
567
+ TypeGuard.IsAny(right) ? FromAnyRight(left, right) :
568
+ TypeGuard.IsString(right) ? FromStringRight(left, right) :
569
+ TypeGuard.IsNumber(right) ? FromNumberRight(left, right) :
570
+ TypeGuard.IsInteger(right) ? FromIntegerRight(left, right) :
571
+ TypeGuard.IsBoolean(right) ? FromBooleanRight(left, right) :
572
+ TypeGuard.IsArray(right) ? FromArrayRight(left, right) :
573
+ TypeGuard.IsTuple(right) ? FromTupleRight(left, right) :
574
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
564
575
  TypeGuard.IsUnknown(right) ? ExtendsResult.True :
565
576
  ExtendsResult.False);
566
577
  }
@@ -568,18 +579,18 @@ function TUnknown(left, right) {
568
579
  // Void
569
580
  // ------------------------------------------------------------------
570
581
  // prettier-ignore
571
- function VoidRight(left, right) {
582
+ function FromVoidRight(left, right) {
572
583
  return (TypeGuard.IsUndefined(left) ? ExtendsResult.True :
573
584
  TypeGuard.IsUndefined(left) ? ExtendsResult.True :
574
585
  ExtendsResult.False);
575
586
  }
576
587
  // prettier-ignore
577
- function TVoid(left, right) {
578
- return (TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
579
- TypeGuard.IsUnion(right) ? TUnionRight(left, right) :
580
- TypeGuard.IsUnknown(right) ? TUnknownRight(left, right) :
581
- TypeGuard.IsAny(right) ? TAnyRight(left, right) :
582
- TypeGuard.IsObject(right) ? TObjectRight(left, right) :
588
+ function FromVoid(left, right) {
589
+ return (TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
590
+ TypeGuard.IsUnion(right) ? FromUnionRight(left, right) :
591
+ TypeGuard.IsUnknown(right) ? FromUnknownRight(left, right) :
592
+ TypeGuard.IsAny(right) ? FromAnyRight(left, right) :
593
+ TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
583
594
  TypeGuard.IsVoid(right) ? ExtendsResult.True :
584
595
  ExtendsResult.False);
585
596
  }
@@ -587,36 +598,37 @@ function TVoid(left, right) {
587
598
  function Visit(left, right) {
588
599
  return (
589
600
  // resolvable
590
- (TypeGuard.IsTemplateLiteral(left) || TypeGuard.IsTemplateLiteral(right)) ? TTemplateLiteral(left, right) :
591
- (TypeGuard.IsNot(left) || TypeGuard.IsNot(right)) ? TNot(left, right) :
592
- // standard
593
- TypeGuard.IsAny(left) ? TAny(left, right) :
594
- TypeGuard.IsArray(left) ? TArray(left, right) :
595
- TypeGuard.IsBigInt(left) ? TBigInt(left, right) :
596
- TypeGuard.IsBoolean(left) ? TBoolean(left, right) :
597
- TypeGuard.IsAsyncIterator(left) ? TAsyncIterator(left, right) :
598
- TypeGuard.IsConstructor(left) ? TConstructor(left, right) :
599
- TypeGuard.IsDate(left) ? TDate(left, right) :
600
- TypeGuard.IsFunction(left) ? TFunction(left, right) :
601
- TypeGuard.IsInteger(left) ? TInteger(left, right) :
602
- TypeGuard.IsIntersect(left) ? TIntersect(left, right) :
603
- TypeGuard.IsIterator(left) ? TIterator(left, right) :
604
- TypeGuard.IsLiteral(left) ? TLiteral(left, right) :
605
- TypeGuard.IsNever(left) ? TNever(left, right) :
606
- TypeGuard.IsNull(left) ? TNull(left, right) :
607
- TypeGuard.IsNumber(left) ? TNumber(left, right) :
608
- TypeGuard.IsObject(left) ? TObject(left, right) :
609
- TypeGuard.IsRecord(left) ? TRecord(left, right) :
610
- TypeGuard.IsString(left) ? TString(left, right) :
611
- TypeGuard.IsSymbol(left) ? TSymbol(left, right) :
612
- TypeGuard.IsTuple(left) ? TTuple(left, right) :
613
- TypeGuard.IsPromise(left) ? TPromise(left, right) :
614
- TypeGuard.IsUint8Array(left) ? TUint8Array(left, right) :
615
- TypeGuard.IsUndefined(left) ? TUndefined(left, right) :
616
- TypeGuard.IsUnion(left) ? TUnion(left, right) :
617
- TypeGuard.IsUnknown(left) ? TUnknown(left, right) :
618
- TypeGuard.IsVoid(left) ? TVoid(left, right) :
619
- Throw(`Unknown left type operand '${left[Kind]}'`));
601
+ (TypeGuard.IsTemplateLiteral(left) || TypeGuard.IsTemplateLiteral(right)) ? FromTemplateLiteral(left, right) :
602
+ (TypeGuard.IsRegExp(left) || TypeGuard.IsRegExp(right)) ? FromRegExp(left, right) :
603
+ (TypeGuard.IsNot(left) || TypeGuard.IsNot(right)) ? FromNot(left, right) :
604
+ // standard
605
+ TypeGuard.IsAny(left) ? FromAny(left, right) :
606
+ TypeGuard.IsArray(left) ? FromArray(left, right) :
607
+ TypeGuard.IsBigInt(left) ? FromBigInt(left, right) :
608
+ TypeGuard.IsBoolean(left) ? FromBoolean(left, right) :
609
+ TypeGuard.IsAsyncIterator(left) ? FromAsyncIterator(left, right) :
610
+ TypeGuard.IsConstructor(left) ? FromConstructor(left, right) :
611
+ TypeGuard.IsDate(left) ? FromDate(left, right) :
612
+ TypeGuard.IsFunction(left) ? FromFunction(left, right) :
613
+ TypeGuard.IsInteger(left) ? FromInteger(left, right) :
614
+ TypeGuard.IsIntersect(left) ? FromIntersect(left, right) :
615
+ TypeGuard.IsIterator(left) ? FromIterator(left, right) :
616
+ TypeGuard.IsLiteral(left) ? FromLiteral(left, right) :
617
+ TypeGuard.IsNever(left) ? FromNever(left, right) :
618
+ TypeGuard.IsNull(left) ? FromNull(left, right) :
619
+ TypeGuard.IsNumber(left) ? FromNumber(left, right) :
620
+ TypeGuard.IsObject(left) ? FromObject(left, right) :
621
+ TypeGuard.IsRecord(left) ? FromRecord(left, right) :
622
+ TypeGuard.IsString(left) ? FromString(left, right) :
623
+ TypeGuard.IsSymbol(left) ? FromSymbol(left, right) :
624
+ TypeGuard.IsTuple(left) ? FromTuple(left, right) :
625
+ TypeGuard.IsPromise(left) ? FromPromise(left, right) :
626
+ TypeGuard.IsUint8Array(left) ? FromUint8Array(left, right) :
627
+ TypeGuard.IsUndefined(left) ? FromUndefined(left, right) :
628
+ TypeGuard.IsUnion(left) ? FromUnion(left, right) :
629
+ TypeGuard.IsUnknown(left) ? FromUnknown(left, right) :
630
+ TypeGuard.IsVoid(left) ? FromVoid(left, right) :
631
+ Throw(`Unknown left type operand '${left[Kind]}'`));
620
632
  }
621
633
  export function ExtendsCheck(left, right) {
622
634
  return Visit(left, right);
@@ -26,6 +26,7 @@ import type { TOptional } from '../optional/index.mjs';
26
26
  import type { TPromise } from '../promise/index.mjs';
27
27
  import type { TReadonly } from '../readonly/index.mjs';
28
28
  import type { TRef } from '../ref/index.mjs';
29
+ import type { TRegExp } from '../regexp/index.mjs';
29
30
  import type { TSchema } from '../schema/index.mjs';
30
31
  import type { TSymbol } from '../symbol/index.mjs';
31
32
  import type { TTuple } from '../tuple/index.mjs';
@@ -104,6 +105,8 @@ export declare function IsRecursive(value: unknown): value is {
104
105
  };
105
106
  /** Returns true if the given value is TRef */
106
107
  export declare function IsRef(value: unknown): value is TRef;
108
+ /** Returns true if the given value is TRegExp */
109
+ export declare function IsRegExp(value: unknown): value is TRegExp;
107
110
  /** Returns true if the given value is TString */
108
111
  export declare function IsString(value: unknown): value is TString;
109
112
  /** Returns true if the given value is TSymbol */
@@ -26,6 +26,7 @@ const KnownTypes = [
26
26
  'Promise',
27
27
  'Record',
28
28
  'Ref',
29
+ 'RegExp',
29
30
  'String',
30
31
  'Symbol',
31
32
  'TemplateLiteral',
@@ -324,6 +325,14 @@ export function IsRef(value) {
324
325
  IsOptionalString(value.$id) &&
325
326
  ValueGuard.IsString(value.$ref));
326
327
  }
328
+ /** Returns true if the given value is TRegExp */
329
+ export function IsRegExp(value) {
330
+ // prettier-ignore
331
+ return (IsKindOf(value, 'RegExp') &&
332
+ IsOptionalString(value.$id) &&
333
+ ValueGuard.IsString(value.source) &&
334
+ ValueGuard.IsString(value.flags));
335
+ }
327
336
  /** Returns true if the given value is TString */
328
337
  export function IsString(value) {
329
338
  // prettier-ignore
@@ -452,6 +461,7 @@ export function IsSchema(value) {
452
461
  IsPromise(value) ||
453
462
  IsRecord(value) ||
454
463
  IsRef(value) ||
464
+ IsRegExp(value) ||
455
465
  IsString(value) ||
456
466
  IsSymbol(value) ||
457
467
  IsTemplateLiteral(value) ||
@@ -18,6 +18,8 @@ export declare function IsNull(value: unknown): value is null;
18
18
  export declare function IsNumber(value: unknown): value is number;
19
19
  /** Returns true if this value is an object */
20
20
  export declare function IsObject(value: unknown): value is Record<PropertyKey, unknown>;
21
+ /** Returns true if this value is RegExp */
22
+ export declare function IsRegExp(value: unknown): value is RegExp;
21
23
  /** Returns true if this value is string */
22
24
  export declare function IsString(value: unknown): value is string;
23
25
  /** Returns true if this value is symbol */
@@ -38,6 +38,10 @@ export function IsNumber(value) {
38
38
  export function IsObject(value) {
39
39
  return typeof value === 'object' && value !== null;
40
40
  }
41
+ /** Returns true if this value is RegExp */
42
+ export function IsRegExp(value) {
43
+ return value instanceof globalThis.RegExp;
44
+ }
41
45
  /** Returns true if this value is string */
42
46
  export function IsString(value) {
43
47
  return typeof value === 'string';
@@ -5,6 +5,7 @@ import { type TObject, type TProperties, type TAdditionalProperties, type Object
5
5
  import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
6
6
  import { type TNever } from '../never/index.mjs';
7
7
  import { type TUnion } from '../union/index.mjs';
8
+ import { type TRegExp } from '../regexp/index.mjs';
8
9
  import { type TString } from '../string/index.mjs';
9
10
  import { type TInteger } from '../integer/index.mjs';
10
11
  import { type TNumber } from '../number/index.mjs';
@@ -30,6 +31,7 @@ type TFromUnionKey<K extends TSchema[], T extends TSchema, P extends TProperties
30
31
  type TFromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObject<{
31
32
  [_ in Assert<K, PropertyKey>]: T;
32
33
  }>>);
34
+ type TFromRegExpKey<_ extends TRegExp, T extends TSchema> = (Ensure<TRecord<TRegExp, T>>);
33
35
  type TFromStringKey<_ extends TString, T extends TSchema> = (Ensure<TRecord<TString, T>>);
34
36
  type TFromIntegerKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
35
37
  type TFromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
@@ -43,7 +45,7 @@ export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchem
43
45
  };
44
46
  additionalProperties: TAdditionalProperties;
45
47
  }
46
- export type TRecordOrObject<K extends TSchema, T extends TSchema> = K extends TTemplateLiteral ? TFromTemplateLiteralKey<K, T> : K extends TEnum<infer S> ? TFromEnumKey<S, T> : K extends TUnion<infer S> ? TFromUnionKey<S, T> : K extends TLiteral<infer S> ? TFromLiteralKey<S, T> : K extends TInteger ? TFromIntegerKey<K, T> : K extends TNumber ? TFromNumberKey<K, T> : K extends TString ? TFromStringKey<K, T> : TNever;
48
+ export type TRecordOrObject<K extends TSchema, T extends TSchema> = K extends TTemplateLiteral ? TFromTemplateLiteralKey<K, T> : K extends TEnum<infer S> ? TFromEnumKey<S, T> : K extends TUnion<infer S> ? TFromUnionKey<S, T> : K extends TLiteral<infer S> ? TFromLiteralKey<S, T> : K extends TInteger ? TFromIntegerKey<K, T> : K extends TNumber ? TFromNumberKey<K, T> : K extends TRegExp ? TFromRegExpKey<K, T> : K extends TString ? TFromStringKey<K, T> : TNever;
47
49
  /** `[Json]` Creates a Record type */
48
50
  export declare function Record<K extends TSchema, T extends TSchema>(K: K, T: T, options?: ObjectOptions): TRecordOrObject<K, T>;
49
51
  export {};