@sinclair/typebox 0.32.0-dev-18 → 0.32.0-dev-19
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/import/compiler/compiler.mjs +14 -8
- package/build/import/errors/errors.mjs +15 -11
- package/build/import/type/awaited/awaited.mjs +4 -4
- package/build/import/type/deref/deref.mjs +12 -12
- package/build/import/type/exclude/exclude.mjs +8 -5
- package/build/import/type/extends/extends-check.mjs +167 -167
- package/build/import/type/extends/extends.mjs +3 -3
- package/build/import/type/extract/extract.mjs +5 -5
- package/build/import/type/guard/type.d.mts +50 -50
- package/build/import/type/guard/type.mjs +136 -136
- package/build/import/type/indexed/indexed-property-keys.mjs +7 -7
- package/build/import/type/indexed/indexed.mjs +9 -9
- package/build/import/type/intersect/intersect-create.mjs +4 -4
- package/build/import/type/intersect/intersect-evaluated.mjs +1 -1
- package/build/import/type/intersect/intersect.mjs +2 -2
- package/build/import/type/intrinsic/intrinsic.mjs +5 -5
- package/build/import/type/keyof/keyof-property-keys.mjs +7 -7
- package/build/import/type/keyof/keyof.mjs +2 -2
- package/build/import/type/mapped/mapped.mjs +16 -16
- package/build/import/type/modifiers/modifiers.mjs +3 -3
- package/build/import/type/object/object.mjs +3 -3
- package/build/import/type/omit/omit.mjs +6 -6
- package/build/import/type/partial/partial.mjs +5 -5
- package/build/import/type/pick/pick.mjs +6 -6
- package/build/import/type/record/record.mjs +7 -7
- package/build/import/type/required/required.mjs +5 -5
- package/build/import/type/rest/rest.mjs +6 -2
- package/build/import/type/template-literal/pattern.mjs +9 -9
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/union/union-evaluated.mjs +2 -2
- package/build/import/value/check/check.mjs +18 -11
- package/build/import/value/clean/clean.mjs +9 -7
- package/build/import/value/clone/clone.mjs +7 -4
- package/build/import/value/convert/convert.mjs +6 -2
- package/build/import/value/default/default.mjs +12 -4
- package/build/import/value/transform/decode.mjs +12 -6
- package/build/import/value/transform/encode.mjs +12 -6
- package/build/import/value/transform/has.mjs +24 -18
- package/build/require/compiler/compiler.js +77 -71
- package/build/require/errors/errors.js +58 -54
- package/build/require/type/awaited/awaited.js +3 -3
- package/build/require/type/deref/deref.js +11 -11
- package/build/require/type/exclude/exclude.js +7 -4
- package/build/require/type/extends/extends-check.js +167 -167
- package/build/require/type/extends/extends.js +2 -2
- package/build/require/type/extract/extract.js +4 -4
- package/build/require/type/guard/type.d.ts +50 -50
- package/build/require/type/guard/type.js +184 -184
- package/build/require/type/indexed/indexed-property-keys.js +6 -6
- package/build/require/type/indexed/indexed.js +9 -9
- package/build/require/type/intersect/intersect-create.js +3 -3
- package/build/require/type/intersect/intersect-evaluated.js +2 -2
- package/build/require/type/intersect/intersect.js +1 -1
- package/build/require/type/intrinsic/intrinsic.js +4 -4
- package/build/require/type/keyof/keyof-property-keys.js +6 -6
- package/build/require/type/keyof/keyof.js +1 -1
- package/build/require/type/mapped/mapped.js +15 -15
- package/build/require/type/modifiers/modifiers.js +2 -2
- package/build/require/type/object/object.js +2 -2
- package/build/require/type/omit/omit.js +5 -5
- package/build/require/type/partial/partial.js +4 -4
- package/build/require/type/pick/pick.js +5 -5
- package/build/require/type/record/record.js +6 -6
- package/build/require/type/required/required.js +4 -4
- package/build/require/type/rest/rest.js +5 -1
- package/build/require/type/template-literal/pattern.js +8 -8
- package/build/require/type/transform/transform.js +1 -1
- package/build/require/type/union/union-evaluated.js +1 -1
- package/build/require/value/check/check.js +63 -56
- package/build/require/value/clean/clean.js +31 -29
- package/build/require/value/clone/clone.js +7 -4
- package/build/require/value/convert/convert.js +42 -38
- package/build/require/value/default/default.js +24 -16
- package/build/require/value/transform/decode.js +27 -21
- package/build/require/value/transform/encode.js +28 -22
- package/build/require/value/transform/has.js +29 -23
- package/package.json +1 -1
- package/readme.md +5 -5
|
@@ -57,7 +57,7 @@ function IsControlCharacterFree(value) {
|
|
|
57
57
|
return true;
|
|
58
58
|
}
|
|
59
59
|
function IsAdditionalProperties(value) {
|
|
60
|
-
return IsOptionalBoolean(value) ||
|
|
60
|
+
return IsOptionalBoolean(value) || IsSchema(value);
|
|
61
61
|
}
|
|
62
62
|
function IsOptionalBigInt(value) {
|
|
63
63
|
return ValueGuard.IsUndefined(value) || ValueGuard.IsBigInt(value);
|
|
@@ -78,34 +78,34 @@ function IsOptionalFormat(value) {
|
|
|
78
78
|
return ValueGuard.IsUndefined(value) || (ValueGuard.IsString(value) && IsControlCharacterFree(value));
|
|
79
79
|
}
|
|
80
80
|
function IsOptionalSchema(value) {
|
|
81
|
-
return ValueGuard.IsUndefined(value) ||
|
|
81
|
+
return ValueGuard.IsUndefined(value) || IsSchema(value);
|
|
82
82
|
}
|
|
83
83
|
// ------------------------------------------------------------------
|
|
84
84
|
// Modifiers
|
|
85
85
|
// ------------------------------------------------------------------
|
|
86
86
|
/** Returns true if this value has a Readonly symbol */
|
|
87
|
-
export function
|
|
87
|
+
export function IsReadonly(value) {
|
|
88
88
|
return ValueGuard.IsObject(value) && value[ReadonlyKind] === 'Readonly';
|
|
89
89
|
}
|
|
90
90
|
/** Returns true if this value has a Optional symbol */
|
|
91
|
-
export function
|
|
91
|
+
export function IsOptional(value) {
|
|
92
92
|
return ValueGuard.IsObject(value) && value[OptionalKind] === 'Optional';
|
|
93
93
|
}
|
|
94
94
|
// ------------------------------------------------------------------
|
|
95
95
|
// Types
|
|
96
96
|
// ------------------------------------------------------------------
|
|
97
97
|
/** Returns true if the given value is TAny */
|
|
98
|
-
export function
|
|
98
|
+
export function IsAny(value) {
|
|
99
99
|
// prettier-ignore
|
|
100
|
-
return (
|
|
100
|
+
return (IsKindOf(value, 'Any') &&
|
|
101
101
|
IsOptionalString(value.$id));
|
|
102
102
|
}
|
|
103
103
|
/** Returns true if the given value is TArray */
|
|
104
|
-
export function
|
|
105
|
-
return (
|
|
104
|
+
export function IsArray(value) {
|
|
105
|
+
return (IsKindOf(value, 'Array') &&
|
|
106
106
|
value.type === 'array' &&
|
|
107
107
|
IsOptionalString(value.$id) &&
|
|
108
|
-
|
|
108
|
+
IsSchema(value.items) &&
|
|
109
109
|
IsOptionalNumber(value.minItems) &&
|
|
110
110
|
IsOptionalNumber(value.maxItems) &&
|
|
111
111
|
IsOptionalBoolean(value.uniqueItems) &&
|
|
@@ -114,17 +114,17 @@ export function TArray(value) {
|
|
|
114
114
|
IsOptionalNumber(value.maxContains));
|
|
115
115
|
}
|
|
116
116
|
/** Returns true if the given value is TAsyncIterator */
|
|
117
|
-
export function
|
|
117
|
+
export function IsAsyncIterator(value) {
|
|
118
118
|
// prettier-ignore
|
|
119
|
-
return (
|
|
119
|
+
return (IsKindOf(value, 'AsyncIterator') &&
|
|
120
120
|
value.type === 'AsyncIterator' &&
|
|
121
121
|
IsOptionalString(value.$id) &&
|
|
122
|
-
|
|
122
|
+
IsSchema(value.items));
|
|
123
123
|
}
|
|
124
124
|
/** Returns true if the given value is TBigInt */
|
|
125
|
-
export function
|
|
125
|
+
export function IsBigInt(value) {
|
|
126
126
|
// prettier-ignore
|
|
127
|
-
return (
|
|
127
|
+
return (IsKindOf(value, 'BigInt') &&
|
|
128
128
|
value.type === 'bigint' &&
|
|
129
129
|
IsOptionalString(value.$id) &&
|
|
130
130
|
IsOptionalBigInt(value.exclusiveMaximum) &&
|
|
@@ -134,25 +134,25 @@ export function TBigInt(value) {
|
|
|
134
134
|
IsOptionalBigInt(value.multipleOf));
|
|
135
135
|
}
|
|
136
136
|
/** Returns true if the given value is TBoolean */
|
|
137
|
-
export function
|
|
137
|
+
export function IsBoolean(value) {
|
|
138
138
|
// prettier-ignore
|
|
139
|
-
return (
|
|
139
|
+
return (IsKindOf(value, 'Boolean') &&
|
|
140
140
|
value.type === 'boolean' &&
|
|
141
141
|
IsOptionalString(value.$id));
|
|
142
142
|
}
|
|
143
143
|
/** Returns true if the given value is TConstructor */
|
|
144
|
-
export function
|
|
144
|
+
export function IsConstructor(value) {
|
|
145
145
|
// prettier-ignore
|
|
146
|
-
return (
|
|
146
|
+
return (IsKindOf(value, 'Constructor') &&
|
|
147
147
|
value.type === 'Constructor' &&
|
|
148
148
|
IsOptionalString(value.$id) &&
|
|
149
149
|
ValueGuard.IsArray(value.parameters) &&
|
|
150
|
-
value.parameters.every(schema =>
|
|
151
|
-
|
|
150
|
+
value.parameters.every(schema => IsSchema(schema)) &&
|
|
151
|
+
IsSchema(value.returns));
|
|
152
152
|
}
|
|
153
153
|
/** Returns true if the given value is TDate */
|
|
154
|
-
export function
|
|
155
|
-
return (
|
|
154
|
+
export function IsDate(value) {
|
|
155
|
+
return (IsKindOf(value, 'Date') &&
|
|
156
156
|
value.type === 'Date' &&
|
|
157
157
|
IsOptionalString(value.$id) &&
|
|
158
158
|
IsOptionalNumber(value.exclusiveMaximumTimestamp) &&
|
|
@@ -162,18 +162,18 @@ export function TDate(value) {
|
|
|
162
162
|
IsOptionalNumber(value.multipleOfTimestamp));
|
|
163
163
|
}
|
|
164
164
|
/** Returns true if the given value is TFunction */
|
|
165
|
-
export function
|
|
165
|
+
export function IsFunction(value) {
|
|
166
166
|
// prettier-ignore
|
|
167
|
-
return (
|
|
167
|
+
return (IsKindOf(value, 'Function') &&
|
|
168
168
|
value.type === 'Function' &&
|
|
169
169
|
IsOptionalString(value.$id) &&
|
|
170
170
|
ValueGuard.IsArray(value.parameters) &&
|
|
171
|
-
value.parameters.every(schema =>
|
|
172
|
-
|
|
171
|
+
value.parameters.every(schema => IsSchema(schema)) &&
|
|
172
|
+
IsSchema(value.returns));
|
|
173
173
|
}
|
|
174
174
|
/** Returns true if the given value is TInteger */
|
|
175
|
-
export function
|
|
176
|
-
return (
|
|
175
|
+
export function IsInteger(value) {
|
|
176
|
+
return (IsKindOf(value, 'Integer') &&
|
|
177
177
|
value.type === 'integer' &&
|
|
178
178
|
IsOptionalString(value.$id) &&
|
|
179
179
|
IsOptionalNumber(value.exclusiveMaximum) &&
|
|
@@ -183,92 +183,92 @@ export function TInteger(value) {
|
|
|
183
183
|
IsOptionalNumber(value.multipleOf));
|
|
184
184
|
}
|
|
185
185
|
/** Returns true if the given schema is TProperties */
|
|
186
|
-
export function
|
|
186
|
+
export function IsProperties(value) {
|
|
187
187
|
// prettier-ignore
|
|
188
188
|
return (ValueGuard.IsObject(value) &&
|
|
189
|
-
Object.entries(value).every(([key, schema]) => IsControlCharacterFree(key) &&
|
|
189
|
+
Object.entries(value).every(([key, schema]) => IsControlCharacterFree(key) && IsSchema(schema)));
|
|
190
190
|
}
|
|
191
191
|
/** Returns true if the given value is TIntersect */
|
|
192
|
-
export function
|
|
192
|
+
export function IsIntersect(value) {
|
|
193
193
|
// prettier-ignore
|
|
194
|
-
return (
|
|
194
|
+
return (IsKindOf(value, 'Intersect') &&
|
|
195
195
|
(ValueGuard.IsString(value.type) && value.type !== 'object' ? false : true) &&
|
|
196
196
|
ValueGuard.IsArray(value.allOf) &&
|
|
197
|
-
value.allOf.every(schema =>
|
|
197
|
+
value.allOf.every(schema => IsSchema(schema) && !IsTransform(schema)) &&
|
|
198
198
|
IsOptionalString(value.type) &&
|
|
199
199
|
(IsOptionalBoolean(value.unevaluatedProperties) || IsOptionalSchema(value.unevaluatedProperties)) &&
|
|
200
200
|
IsOptionalString(value.$id));
|
|
201
201
|
}
|
|
202
202
|
/** Returns true if the given value is TIterator */
|
|
203
|
-
export function
|
|
203
|
+
export function IsIterator(value) {
|
|
204
204
|
// prettier-ignore
|
|
205
|
-
return (
|
|
205
|
+
return (IsKindOf(value, 'Iterator') &&
|
|
206
206
|
value.type === 'Iterator' &&
|
|
207
207
|
IsOptionalString(value.$id) &&
|
|
208
|
-
|
|
208
|
+
IsSchema(value.items));
|
|
209
209
|
}
|
|
210
210
|
/** Returns true if the given value is a TKind with the given name. */
|
|
211
|
-
export function
|
|
211
|
+
export function IsKindOf(value, kind) {
|
|
212
212
|
return ValueGuard.IsObject(value) && Kind in value && value[Kind] === kind;
|
|
213
213
|
}
|
|
214
214
|
/** Returns true if the given value is TLiteral<string> */
|
|
215
|
-
export function
|
|
216
|
-
return
|
|
215
|
+
export function IsLiteralString(value) {
|
|
216
|
+
return IsLiteral(value) && ValueGuard.IsString(value.const);
|
|
217
217
|
}
|
|
218
218
|
/** Returns true if the given value is TLiteral<number> */
|
|
219
|
-
export function
|
|
220
|
-
return
|
|
219
|
+
export function IsLiteralNumber(value) {
|
|
220
|
+
return IsLiteral(value) && ValueGuard.IsNumber(value.const);
|
|
221
221
|
}
|
|
222
222
|
/** Returns true if the given value is TLiteral<boolean> */
|
|
223
|
-
export function
|
|
224
|
-
return
|
|
223
|
+
export function IsLiteralBoolean(value) {
|
|
224
|
+
return IsLiteral(value) && ValueGuard.IsBoolean(value.const);
|
|
225
225
|
}
|
|
226
226
|
/** Returns true if the given value is TLiteral */
|
|
227
|
-
export function
|
|
227
|
+
export function IsLiteral(value) {
|
|
228
228
|
// prettier-ignore
|
|
229
|
-
return (
|
|
230
|
-
IsOptionalString(value.$id) &&
|
|
229
|
+
return (IsKindOf(value, 'Literal') &&
|
|
230
|
+
IsOptionalString(value.$id) && IsLiteralValue(value.const));
|
|
231
231
|
}
|
|
232
232
|
/** Returns true if the given value is a TLiteralValue */
|
|
233
|
-
export function
|
|
233
|
+
export function IsLiteralValue(value) {
|
|
234
234
|
return ValueGuard.IsBoolean(value) || ValueGuard.IsNumber(value) || ValueGuard.IsString(value);
|
|
235
235
|
}
|
|
236
236
|
/** Returns true if the given value is a TMappedKey */
|
|
237
|
-
export function
|
|
237
|
+
export function IsMappedKey(value) {
|
|
238
238
|
// prettier-ignore
|
|
239
|
-
return (
|
|
239
|
+
return (IsKindOf(value, 'MappedKey') &&
|
|
240
240
|
ValueGuard.IsArray(value.keys) &&
|
|
241
241
|
value.keys.every(key => ValueGuard.IsNumber(key) || ValueGuard.IsString(key)));
|
|
242
242
|
}
|
|
243
243
|
/** Returns true if the given value is TMappedResult */
|
|
244
|
-
export function
|
|
244
|
+
export function IsMappedResult(value) {
|
|
245
245
|
// prettier-ignore
|
|
246
|
-
return (
|
|
247
|
-
|
|
246
|
+
return (IsKindOf(value, 'MappedResult') &&
|
|
247
|
+
IsProperties(value.properties));
|
|
248
248
|
}
|
|
249
249
|
/** Returns true if the given value is TNever */
|
|
250
|
-
export function
|
|
250
|
+
export function IsNever(value) {
|
|
251
251
|
// prettier-ignore
|
|
252
|
-
return (
|
|
252
|
+
return (IsKindOf(value, 'Never') &&
|
|
253
253
|
ValueGuard.IsObject(value.not) &&
|
|
254
254
|
Object.getOwnPropertyNames(value.not).length === 0);
|
|
255
255
|
}
|
|
256
256
|
/** Returns true if the given value is TNot */
|
|
257
|
-
export function
|
|
257
|
+
export function IsNot(value) {
|
|
258
258
|
// prettier-ignore
|
|
259
|
-
return (
|
|
260
|
-
|
|
259
|
+
return (IsKindOf(value, 'Not') &&
|
|
260
|
+
IsSchema(value.not));
|
|
261
261
|
}
|
|
262
262
|
/** Returns true if the given value is TNull */
|
|
263
|
-
export function
|
|
263
|
+
export function IsNull(value) {
|
|
264
264
|
// prettier-ignore
|
|
265
|
-
return (
|
|
265
|
+
return (IsKindOf(value, 'Null') &&
|
|
266
266
|
value.type === 'null' &&
|
|
267
267
|
IsOptionalString(value.$id));
|
|
268
268
|
}
|
|
269
269
|
/** Returns true if the given value is TNumber */
|
|
270
|
-
export function
|
|
271
|
-
return (
|
|
270
|
+
export function IsNumber(value) {
|
|
271
|
+
return (IsKindOf(value, 'Number') &&
|
|
272
272
|
value.type === 'number' &&
|
|
273
273
|
IsOptionalString(value.$id) &&
|
|
274
274
|
IsOptionalNumber(value.exclusiveMaximum) &&
|
|
@@ -278,28 +278,28 @@ export function TNumber(value) {
|
|
|
278
278
|
IsOptionalNumber(value.multipleOf));
|
|
279
279
|
}
|
|
280
280
|
/** Returns true if the given value is TObject */
|
|
281
|
-
export function
|
|
281
|
+
export function IsObject(value) {
|
|
282
282
|
// prettier-ignore
|
|
283
|
-
return (
|
|
283
|
+
return (IsKindOf(value, 'Object') &&
|
|
284
284
|
value.type === 'object' &&
|
|
285
285
|
IsOptionalString(value.$id) &&
|
|
286
|
-
|
|
286
|
+
IsProperties(value.properties) &&
|
|
287
287
|
IsAdditionalProperties(value.additionalProperties) &&
|
|
288
288
|
IsOptionalNumber(value.minProperties) &&
|
|
289
289
|
IsOptionalNumber(value.maxProperties));
|
|
290
290
|
}
|
|
291
291
|
/** Returns true if the given value is TPromise */
|
|
292
|
-
export function
|
|
292
|
+
export function IsPromise(value) {
|
|
293
293
|
// prettier-ignore
|
|
294
|
-
return (
|
|
294
|
+
return (IsKindOf(value, 'Promise') &&
|
|
295
295
|
value.type === 'Promise' &&
|
|
296
296
|
IsOptionalString(value.$id) &&
|
|
297
|
-
|
|
297
|
+
IsSchema(value.item));
|
|
298
298
|
}
|
|
299
299
|
/** Returns true if the given value is TRecord */
|
|
300
|
-
export function
|
|
300
|
+
export function IsRecord(value) {
|
|
301
301
|
// prettier-ignore
|
|
302
|
-
return (
|
|
302
|
+
return (IsKindOf(value, 'Record') &&
|
|
303
303
|
value.type === 'object' &&
|
|
304
304
|
IsOptionalString(value.$id) &&
|
|
305
305
|
IsAdditionalProperties(value.additionalProperties) &&
|
|
@@ -309,24 +309,24 @@ export function TRecord(value) {
|
|
|
309
309
|
return (keys.length === 1 &&
|
|
310
310
|
IsPattern(keys[0]) &&
|
|
311
311
|
ValueGuard.IsObject(schema.patternProperties) &&
|
|
312
|
-
|
|
312
|
+
IsSchema(schema.patternProperties[keys[0]]));
|
|
313
313
|
})(value));
|
|
314
314
|
}
|
|
315
315
|
/** Returns true if this value is TRecursive */
|
|
316
|
-
export function
|
|
316
|
+
export function IsRecursive(value) {
|
|
317
317
|
return ValueGuard.IsObject(value) && Hint in value && value[Hint] === 'Recursive';
|
|
318
318
|
}
|
|
319
319
|
/** Returns true if the given value is TRef */
|
|
320
|
-
export function
|
|
320
|
+
export function IsRef(value) {
|
|
321
321
|
// prettier-ignore
|
|
322
|
-
return (
|
|
322
|
+
return (IsKindOf(value, 'Ref') &&
|
|
323
323
|
IsOptionalString(value.$id) &&
|
|
324
324
|
ValueGuard.IsString(value.$ref));
|
|
325
325
|
}
|
|
326
326
|
/** Returns true if the given value is TString */
|
|
327
|
-
export function
|
|
327
|
+
export function IsString(value) {
|
|
328
328
|
// prettier-ignore
|
|
329
|
-
return (
|
|
329
|
+
return (IsKindOf(value, 'String') &&
|
|
330
330
|
value.type === 'string' &&
|
|
331
331
|
IsOptionalString(value.$id) &&
|
|
332
332
|
IsOptionalNumber(value.minLength) &&
|
|
@@ -335,36 +335,36 @@ export function TString(value) {
|
|
|
335
335
|
IsOptionalFormat(value.format));
|
|
336
336
|
}
|
|
337
337
|
/** Returns true if the given value is TSymbol */
|
|
338
|
-
export function
|
|
338
|
+
export function IsSymbol(value) {
|
|
339
339
|
// prettier-ignore
|
|
340
|
-
return (
|
|
340
|
+
return (IsKindOf(value, 'Symbol') &&
|
|
341
341
|
value.type === 'symbol' &&
|
|
342
342
|
IsOptionalString(value.$id));
|
|
343
343
|
}
|
|
344
344
|
/** Returns true if the given value is TTemplateLiteral */
|
|
345
|
-
export function
|
|
345
|
+
export function IsTemplateLiteral(value) {
|
|
346
346
|
// prettier-ignore
|
|
347
|
-
return (
|
|
347
|
+
return (IsKindOf(value, 'TemplateLiteral') &&
|
|
348
348
|
value.type === 'string' &&
|
|
349
349
|
ValueGuard.IsString(value.pattern) &&
|
|
350
350
|
value.pattern[0] === '^' &&
|
|
351
351
|
value.pattern[value.pattern.length - 1] === '$');
|
|
352
352
|
}
|
|
353
353
|
/** Returns true if the given value is TThis */
|
|
354
|
-
export function
|
|
354
|
+
export function IsThis(value) {
|
|
355
355
|
// prettier-ignore
|
|
356
|
-
return (
|
|
356
|
+
return (IsKindOf(value, 'This') &&
|
|
357
357
|
IsOptionalString(value.$id) &&
|
|
358
358
|
ValueGuard.IsString(value.$ref));
|
|
359
359
|
}
|
|
360
360
|
/** Returns true of this value is TTransform */
|
|
361
|
-
export function
|
|
361
|
+
export function IsTransform(value) {
|
|
362
362
|
return ValueGuard.IsObject(value) && TransformKind in value;
|
|
363
363
|
}
|
|
364
364
|
/** Returns true if the given value is TTuple */
|
|
365
|
-
export function
|
|
365
|
+
export function IsTuple(value) {
|
|
366
366
|
// prettier-ignore
|
|
367
|
-
return (
|
|
367
|
+
return (IsKindOf(value, 'Tuple') &&
|
|
368
368
|
value.type === 'array' &&
|
|
369
369
|
IsOptionalString(value.$id) &&
|
|
370
370
|
ValueGuard.IsNumber(value.minItems) &&
|
|
@@ -374,93 +374,93 @@ export function TTuple(value) {
|
|
|
374
374
|
ValueGuard.IsUndefined(value.items) &&
|
|
375
375
|
ValueGuard.IsUndefined(value.additionalItems) &&
|
|
376
376
|
value.minItems === 0) || (ValueGuard.IsArray(value.items) &&
|
|
377
|
-
value.items.every(schema =>
|
|
377
|
+
value.items.every(schema => IsSchema(schema)))));
|
|
378
378
|
}
|
|
379
379
|
/** Returns true if the given value is TUndefined */
|
|
380
|
-
export function
|
|
380
|
+
export function IsUndefined(value) {
|
|
381
381
|
// prettier-ignore
|
|
382
|
-
return (
|
|
382
|
+
return (IsKindOf(value, 'Undefined') &&
|
|
383
383
|
value.type === 'undefined' &&
|
|
384
384
|
IsOptionalString(value.$id));
|
|
385
385
|
}
|
|
386
386
|
/** Returns true if the given value is TUnion<Literal<string | number>[]> */
|
|
387
|
-
export function
|
|
388
|
-
return
|
|
387
|
+
export function IsUnionLiteral(value) {
|
|
388
|
+
return IsUnion(value) && value.anyOf.every((schema) => IsLiteralString(schema) || IsLiteralNumber(schema));
|
|
389
389
|
}
|
|
390
390
|
/** Returns true if the given value is TUnion */
|
|
391
|
-
export function
|
|
391
|
+
export function IsUnion(value) {
|
|
392
392
|
// prettier-ignore
|
|
393
|
-
return (
|
|
393
|
+
return (IsKindOf(value, 'Union') &&
|
|
394
394
|
IsOptionalString(value.$id) &&
|
|
395
395
|
ValueGuard.IsObject(value) &&
|
|
396
396
|
ValueGuard.IsArray(value.anyOf) &&
|
|
397
|
-
value.anyOf.every(schema =>
|
|
397
|
+
value.anyOf.every(schema => IsSchema(schema)));
|
|
398
398
|
}
|
|
399
399
|
/** Returns true if the given value is TUint8Array */
|
|
400
|
-
export function
|
|
400
|
+
export function IsUint8Array(value) {
|
|
401
401
|
// prettier-ignore
|
|
402
|
-
return (
|
|
402
|
+
return (IsKindOf(value, 'Uint8Array') &&
|
|
403
403
|
value.type === 'Uint8Array' &&
|
|
404
404
|
IsOptionalString(value.$id) &&
|
|
405
405
|
IsOptionalNumber(value.minByteLength) &&
|
|
406
406
|
IsOptionalNumber(value.maxByteLength));
|
|
407
407
|
}
|
|
408
408
|
/** Returns true if the given value is TUnknown */
|
|
409
|
-
export function
|
|
409
|
+
export function IsUnknown(value) {
|
|
410
410
|
// prettier-ignore
|
|
411
|
-
return (
|
|
411
|
+
return (IsKindOf(value, 'Unknown') &&
|
|
412
412
|
IsOptionalString(value.$id));
|
|
413
413
|
}
|
|
414
414
|
/** Returns true if the given value is a raw TUnsafe */
|
|
415
|
-
export function
|
|
416
|
-
return
|
|
415
|
+
export function IsUnsafe(value) {
|
|
416
|
+
return IsKindOf(value, 'Unsafe');
|
|
417
417
|
}
|
|
418
418
|
/** Returns true if the given value is TVoid */
|
|
419
|
-
export function
|
|
419
|
+
export function IsVoid(value) {
|
|
420
420
|
// prettier-ignore
|
|
421
|
-
return (
|
|
421
|
+
return (IsKindOf(value, 'Void') &&
|
|
422
422
|
value.type === 'void' &&
|
|
423
423
|
IsOptionalString(value.$id));
|
|
424
424
|
}
|
|
425
425
|
/** Returns true if the given value is TKind */
|
|
426
|
-
export function
|
|
426
|
+
export function IsKind(value) {
|
|
427
427
|
return ValueGuard.IsObject(value) && Kind in value && ValueGuard.IsString(value[Kind]) && !KnownTypes.includes(value[Kind]);
|
|
428
428
|
}
|
|
429
429
|
/** Returns true if the given value is TSchema */
|
|
430
|
-
export function
|
|
430
|
+
export function IsSchema(value) {
|
|
431
431
|
// prettier-ignore
|
|
432
|
-
return (ValueGuard.IsObject(value)) && (
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
432
|
+
return (ValueGuard.IsObject(value)) && (IsAny(value) ||
|
|
433
|
+
IsArray(value) ||
|
|
434
|
+
IsBoolean(value) ||
|
|
435
|
+
IsBigInt(value) ||
|
|
436
|
+
IsAsyncIterator(value) ||
|
|
437
|
+
IsConstructor(value) ||
|
|
438
|
+
IsDate(value) ||
|
|
439
|
+
IsFunction(value) ||
|
|
440
|
+
IsInteger(value) ||
|
|
441
|
+
IsIntersect(value) ||
|
|
442
|
+
IsIterator(value) ||
|
|
443
|
+
IsLiteral(value) ||
|
|
444
|
+
IsMappedKey(value) ||
|
|
445
|
+
IsMappedResult(value) ||
|
|
446
|
+
IsNever(value) ||
|
|
447
|
+
IsNot(value) ||
|
|
448
|
+
IsNull(value) ||
|
|
449
|
+
IsNumber(value) ||
|
|
450
|
+
IsObject(value) ||
|
|
451
|
+
IsPromise(value) ||
|
|
452
|
+
IsRecord(value) ||
|
|
453
|
+
IsRef(value) ||
|
|
454
|
+
IsString(value) ||
|
|
455
|
+
IsSymbol(value) ||
|
|
456
|
+
IsTemplateLiteral(value) ||
|
|
457
|
+
IsThis(value) ||
|
|
458
|
+
IsTuple(value) ||
|
|
459
|
+
IsUndefined(value) ||
|
|
460
|
+
IsUnion(value) ||
|
|
461
|
+
IsUint8Array(value) ||
|
|
462
|
+
IsUnknown(value) ||
|
|
463
|
+
IsUnsafe(value) ||
|
|
464
|
+
IsVoid(value) ||
|
|
465
|
+
IsKind(value));
|
|
466
466
|
}
|
|
@@ -3,14 +3,14 @@ import { TemplateLiteralParseExact, IsTemplateLiteralFinite, TemplateLiteralToUn
|
|
|
3
3
|
// TypeGuard
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
// prettier-ignore
|
|
6
|
-
import {
|
|
6
|
+
import { IsTemplateLiteral, IsUnionLiteral, IsUnion, IsLiteral, IsNumber, IsInteger } from '../guard/type.mjs';
|
|
7
7
|
// prettier-ignore
|
|
8
8
|
function FromTemplateLiteral(T) {
|
|
9
9
|
const E = TemplateLiteralParseExact(T.pattern);
|
|
10
10
|
const F = IsTemplateLiteralFinite(E);
|
|
11
11
|
const S = TemplateLiteralToUnion(T);
|
|
12
12
|
return (F === true
|
|
13
|
-
?
|
|
13
|
+
? IsUnionLiteral(S)
|
|
14
14
|
? S.anyOf.map(S => S.const.toString())
|
|
15
15
|
: []
|
|
16
16
|
: []);
|
|
@@ -29,10 +29,10 @@ function FromLiteral(T) {
|
|
|
29
29
|
/** Returns a tuple of PropertyKeys derived from the given TSchema */
|
|
30
30
|
// prettier-ignore
|
|
31
31
|
export function IndexPropertyKeys(T) {
|
|
32
|
-
return [...new Set((
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
return [...new Set((IsTemplateLiteral(T) ? FromTemplateLiteral(T) :
|
|
33
|
+
IsUnion(T) ? FromUnion(T.anyOf) :
|
|
34
|
+
IsLiteral(T) ? FromLiteral(T.const) :
|
|
35
|
+
IsNumber(T) ? ['[number]'] :
|
|
36
|
+
IsInteger(T) ? ['[number]'] :
|
|
37
37
|
[]))];
|
|
38
38
|
}
|
|
@@ -8,7 +8,7 @@ import { IndexFromMappedKey } from './indexed-from-mapped-key.mjs';
|
|
|
8
8
|
// TypeGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// prettier-ignore
|
|
11
|
-
import {
|
|
11
|
+
import { IsArray, IsIntersect, IsObject, IsMappedKey, IsNever, IsSchema, IsTuple, IsUnion } from '../guard/type.mjs';
|
|
12
12
|
// prettier-ignore
|
|
13
13
|
function FromRest(T, K) {
|
|
14
14
|
const [L, ...R] = T;
|
|
@@ -20,7 +20,7 @@ function FromRest(T, K) {
|
|
|
20
20
|
function FromIntersectRest(T) {
|
|
21
21
|
const [L, ...R] = T;
|
|
22
22
|
return (T.length > 0
|
|
23
|
-
?
|
|
23
|
+
? IsNever(L)
|
|
24
24
|
? [...FromIntersectRest(R)]
|
|
25
25
|
: [L, ...FromIntersectRest(R)]
|
|
26
26
|
: []);
|
|
@@ -33,7 +33,7 @@ function FromIntersect(T, K) {
|
|
|
33
33
|
function FromUnionRest(T, S = T) {
|
|
34
34
|
const [L, ...R] = T;
|
|
35
35
|
return (T.length > 0
|
|
36
|
-
?
|
|
36
|
+
? IsNever(L)
|
|
37
37
|
? []
|
|
38
38
|
: FromUnionRest(R, S)
|
|
39
39
|
: S);
|
|
@@ -62,11 +62,11 @@ function FromProperty(T, K) {
|
|
|
62
62
|
}
|
|
63
63
|
// prettier-ignore
|
|
64
64
|
function FromKey(T, K) {
|
|
65
|
-
return (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
return (IsIntersect(T) ? FromIntersect(T.allOf, K) :
|
|
66
|
+
IsUnion(T) ? FromUnion(T.anyOf, K) :
|
|
67
|
+
IsTuple(T) ? FromTuple(T.items ?? [], K) :
|
|
68
|
+
IsArray(T) ? FromArray(T.items, K) :
|
|
69
|
+
IsObject(T) ? FromProperty(T.properties, K) :
|
|
70
70
|
Never());
|
|
71
71
|
}
|
|
72
72
|
// prettier-ignore
|
|
@@ -84,6 +84,6 @@ function FromSchema(T, K) {
|
|
|
84
84
|
export function Index(T, K, options = {}) {
|
|
85
85
|
// prettier-ignore
|
|
86
86
|
return (IsMappedKey(K) ? CloneType(IndexFromMappedKey(T, K, options)) :
|
|
87
|
-
|
|
87
|
+
IsSchema(K) ? CloneType(FromSchema(T, IndexPropertyKeys(K)), options) :
|
|
88
88
|
CloneType(FromSchema(T, K), options));
|
|
89
89
|
}
|
|
@@ -4,17 +4,17 @@ import { CloneType, CloneRest } from '../clone/type.mjs';
|
|
|
4
4
|
// TypeGuard
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
6
|
// prettier-ignore
|
|
7
|
-
import {
|
|
7
|
+
import { IsObject, IsSchema } from '../guard/type.mjs';
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
// IntersectCreate
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
11
|
// prettier-ignore
|
|
12
12
|
export function IntersectCreate(T, options) {
|
|
13
|
-
const allObjects = T.every((schema) =>
|
|
14
|
-
const clonedUnevaluatedProperties =
|
|
13
|
+
const allObjects = T.every((schema) => IsObject(schema));
|
|
14
|
+
const clonedUnevaluatedProperties = IsSchema(options.unevaluatedProperties)
|
|
15
15
|
? { unevaluatedProperties: CloneType(options.unevaluatedProperties) }
|
|
16
16
|
: {};
|
|
17
|
-
return ((options.unevaluatedProperties === false ||
|
|
17
|
+
return ((options.unevaluatedProperties === false || IsSchema(options.unevaluatedProperties) || allObjects
|
|
18
18
|
? { ...options, ...clonedUnevaluatedProperties, [Kind]: 'Intersect', type: 'object', allOf: CloneRest(T) }
|
|
19
19
|
: { ...options, ...clonedUnevaluatedProperties, [Kind]: 'Intersect', allOf: CloneRest(T) }));
|
|
20
20
|
}
|
|
@@ -8,7 +8,7 @@ import { IntersectCreate } from './intersect-create.mjs';
|
|
|
8
8
|
// TypeGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// prettier-ignore
|
|
11
|
-
import {
|
|
11
|
+
import { IsOptional as IsOptionalType, IsTransform as IsTransformType, } from '../guard/type.mjs';
|
|
12
12
|
// prettier-ignore
|
|
13
13
|
function IsIntersectOptional(T) {
|
|
14
14
|
const [L, ...R] = T;
|
|
@@ -5,14 +5,14 @@ import { IntersectCreate } from './intersect-create.mjs';
|
|
|
5
5
|
// TypeGuard
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
// prettier-ignore
|
|
8
|
-
import {
|
|
8
|
+
import { IsTransform, } from '../guard/type.mjs';
|
|
9
9
|
/** `[Json]` Creates an evaluated Intersect type */
|
|
10
10
|
export function Intersect(T, options = {}) {
|
|
11
11
|
if (T.length === 0)
|
|
12
12
|
return Never(options);
|
|
13
13
|
if (T.length === 1)
|
|
14
14
|
return CloneType(T[0], options);
|
|
15
|
-
if (T.some((schema) =>
|
|
15
|
+
if (T.some((schema) => IsTransform(schema)))
|
|
16
16
|
throw new Error('Cannot intersect transform types');
|
|
17
17
|
return IntersectCreate(T, options);
|
|
18
18
|
}
|