@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.IsSchema = exports.IsKind = exports.IsVoid = exports.IsUnsafe = exports.IsUnknown = exports.IsUint8Array = exports.IsUnion = exports.IsUnionLiteral = exports.IsUndefined = exports.IsTuple = exports.IsTransform = exports.IsThis = exports.IsTemplateLiteral = exports.IsSymbol = exports.IsString = exports.IsRef = exports.IsRecursive = exports.IsRecord = exports.IsPromise = exports.IsObject = exports.IsNumber = exports.IsNull = exports.IsNot = exports.IsNever = exports.IsMappedResult = exports.IsMappedKey = exports.IsLiteralValue = exports.IsLiteral = exports.IsLiteralBoolean = exports.IsLiteralNumber = exports.IsLiteralString = exports.IsKindOf = exports.IsIterator = exports.IsIntersect = exports.IsProperties = exports.IsInteger = exports.IsFunction = exports.IsDate = exports.IsConstructor = exports.IsBoolean = exports.IsBigInt = exports.IsAsyncIterator = exports.IsArray = exports.IsAny = exports.IsOptional = exports.IsReadonly = exports.TypeGuardUnknownTypeError = void 0;
|
|
5
5
|
const ValueGuard = require("./value");
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
7
|
class TypeGuardUnknownTypeError extends Error {
|
|
@@ -62,7 +62,7 @@ function IsControlCharacterFree(value) {
|
|
|
62
62
|
return true;
|
|
63
63
|
}
|
|
64
64
|
function IsAdditionalProperties(value) {
|
|
65
|
-
return IsOptionalBoolean(value) || (
|
|
65
|
+
return IsOptionalBoolean(value) || IsSchema(value);
|
|
66
66
|
}
|
|
67
67
|
function IsOptionalBigInt(value) {
|
|
68
68
|
return ValueGuard.IsUndefined(value) || ValueGuard.IsBigInt(value);
|
|
@@ -83,37 +83,37 @@ function IsOptionalFormat(value) {
|
|
|
83
83
|
return ValueGuard.IsUndefined(value) || (ValueGuard.IsString(value) && IsControlCharacterFree(value));
|
|
84
84
|
}
|
|
85
85
|
function IsOptionalSchema(value) {
|
|
86
|
-
return ValueGuard.IsUndefined(value) || (
|
|
86
|
+
return ValueGuard.IsUndefined(value) || IsSchema(value);
|
|
87
87
|
}
|
|
88
88
|
// ------------------------------------------------------------------
|
|
89
89
|
// Modifiers
|
|
90
90
|
// ------------------------------------------------------------------
|
|
91
91
|
/** Returns true if this value has a Readonly symbol */
|
|
92
|
-
function
|
|
92
|
+
function IsReadonly(value) {
|
|
93
93
|
return ValueGuard.IsObject(value) && value[index_1.ReadonlyKind] === 'Readonly';
|
|
94
94
|
}
|
|
95
|
-
exports.
|
|
95
|
+
exports.IsReadonly = IsReadonly;
|
|
96
96
|
/** Returns true if this value has a Optional symbol */
|
|
97
|
-
function
|
|
97
|
+
function IsOptional(value) {
|
|
98
98
|
return ValueGuard.IsObject(value) && value[index_1.OptionalKind] === 'Optional';
|
|
99
99
|
}
|
|
100
|
-
exports.
|
|
100
|
+
exports.IsOptional = IsOptional;
|
|
101
101
|
// ------------------------------------------------------------------
|
|
102
102
|
// Types
|
|
103
103
|
// ------------------------------------------------------------------
|
|
104
104
|
/** Returns true if the given value is TAny */
|
|
105
|
-
function
|
|
105
|
+
function IsAny(value) {
|
|
106
106
|
// prettier-ignore
|
|
107
|
-
return (
|
|
107
|
+
return (IsKindOf(value, 'Any') &&
|
|
108
108
|
IsOptionalString(value.$id));
|
|
109
109
|
}
|
|
110
|
-
exports.
|
|
110
|
+
exports.IsAny = IsAny;
|
|
111
111
|
/** Returns true if the given value is TArray */
|
|
112
|
-
function
|
|
113
|
-
return (
|
|
112
|
+
function IsArray(value) {
|
|
113
|
+
return (IsKindOf(value, 'Array') &&
|
|
114
114
|
value.type === 'array' &&
|
|
115
115
|
IsOptionalString(value.$id) &&
|
|
116
|
-
(
|
|
116
|
+
IsSchema(value.items) &&
|
|
117
117
|
IsOptionalNumber(value.minItems) &&
|
|
118
118
|
IsOptionalNumber(value.maxItems) &&
|
|
119
119
|
IsOptionalBoolean(value.uniqueItems) &&
|
|
@@ -121,20 +121,20 @@ function TArray(value) {
|
|
|
121
121
|
IsOptionalNumber(value.minContains) &&
|
|
122
122
|
IsOptionalNumber(value.maxContains));
|
|
123
123
|
}
|
|
124
|
-
exports.
|
|
124
|
+
exports.IsArray = IsArray;
|
|
125
125
|
/** Returns true if the given value is TAsyncIterator */
|
|
126
|
-
function
|
|
126
|
+
function IsAsyncIterator(value) {
|
|
127
127
|
// prettier-ignore
|
|
128
|
-
return (
|
|
128
|
+
return (IsKindOf(value, 'AsyncIterator') &&
|
|
129
129
|
value.type === 'AsyncIterator' &&
|
|
130
130
|
IsOptionalString(value.$id) &&
|
|
131
|
-
(
|
|
131
|
+
IsSchema(value.items));
|
|
132
132
|
}
|
|
133
|
-
exports.
|
|
133
|
+
exports.IsAsyncIterator = IsAsyncIterator;
|
|
134
134
|
/** Returns true if the given value is TBigInt */
|
|
135
|
-
function
|
|
135
|
+
function IsBigInt(value) {
|
|
136
136
|
// prettier-ignore
|
|
137
|
-
return (
|
|
137
|
+
return (IsKindOf(value, 'BigInt') &&
|
|
138
138
|
value.type === 'bigint' &&
|
|
139
139
|
IsOptionalString(value.$id) &&
|
|
140
140
|
IsOptionalBigInt(value.exclusiveMaximum) &&
|
|
@@ -143,29 +143,29 @@ function TBigInt(value) {
|
|
|
143
143
|
IsOptionalBigInt(value.minimum) &&
|
|
144
144
|
IsOptionalBigInt(value.multipleOf));
|
|
145
145
|
}
|
|
146
|
-
exports.
|
|
146
|
+
exports.IsBigInt = IsBigInt;
|
|
147
147
|
/** Returns true if the given value is TBoolean */
|
|
148
|
-
function
|
|
148
|
+
function IsBoolean(value) {
|
|
149
149
|
// prettier-ignore
|
|
150
|
-
return (
|
|
150
|
+
return (IsKindOf(value, 'Boolean') &&
|
|
151
151
|
value.type === 'boolean' &&
|
|
152
152
|
IsOptionalString(value.$id));
|
|
153
153
|
}
|
|
154
|
-
exports.
|
|
154
|
+
exports.IsBoolean = IsBoolean;
|
|
155
155
|
/** Returns true if the given value is TConstructor */
|
|
156
|
-
function
|
|
156
|
+
function IsConstructor(value) {
|
|
157
157
|
// prettier-ignore
|
|
158
|
-
return (
|
|
158
|
+
return (IsKindOf(value, 'Constructor') &&
|
|
159
159
|
value.type === 'Constructor' &&
|
|
160
160
|
IsOptionalString(value.$id) &&
|
|
161
161
|
ValueGuard.IsArray(value.parameters) &&
|
|
162
|
-
value.parameters.every(schema => (
|
|
163
|
-
(
|
|
162
|
+
value.parameters.every(schema => IsSchema(schema)) &&
|
|
163
|
+
IsSchema(value.returns));
|
|
164
164
|
}
|
|
165
|
-
exports.
|
|
165
|
+
exports.IsConstructor = IsConstructor;
|
|
166
166
|
/** Returns true if the given value is TDate */
|
|
167
|
-
function
|
|
168
|
-
return (
|
|
167
|
+
function IsDate(value) {
|
|
168
|
+
return (IsKindOf(value, 'Date') &&
|
|
169
169
|
value.type === 'Date' &&
|
|
170
170
|
IsOptionalString(value.$id) &&
|
|
171
171
|
IsOptionalNumber(value.exclusiveMaximumTimestamp) &&
|
|
@@ -174,21 +174,21 @@ function TDate(value) {
|
|
|
174
174
|
IsOptionalNumber(value.minimumTimestamp) &&
|
|
175
175
|
IsOptionalNumber(value.multipleOfTimestamp));
|
|
176
176
|
}
|
|
177
|
-
exports.
|
|
177
|
+
exports.IsDate = IsDate;
|
|
178
178
|
/** Returns true if the given value is TFunction */
|
|
179
|
-
function
|
|
179
|
+
function IsFunction(value) {
|
|
180
180
|
// prettier-ignore
|
|
181
|
-
return (
|
|
181
|
+
return (IsKindOf(value, 'Function') &&
|
|
182
182
|
value.type === 'Function' &&
|
|
183
183
|
IsOptionalString(value.$id) &&
|
|
184
184
|
ValueGuard.IsArray(value.parameters) &&
|
|
185
|
-
value.parameters.every(schema => (
|
|
186
|
-
(
|
|
185
|
+
value.parameters.every(schema => IsSchema(schema)) &&
|
|
186
|
+
IsSchema(value.returns));
|
|
187
187
|
}
|
|
188
|
-
exports.
|
|
188
|
+
exports.IsFunction = IsFunction;
|
|
189
189
|
/** Returns true if the given value is TInteger */
|
|
190
|
-
function
|
|
191
|
-
return (
|
|
190
|
+
function IsInteger(value) {
|
|
191
|
+
return (IsKindOf(value, 'Integer') &&
|
|
192
192
|
value.type === 'integer' &&
|
|
193
193
|
IsOptionalString(value.$id) &&
|
|
194
194
|
IsOptionalNumber(value.exclusiveMaximum) &&
|
|
@@ -197,108 +197,108 @@ function TInteger(value) {
|
|
|
197
197
|
IsOptionalNumber(value.minimum) &&
|
|
198
198
|
IsOptionalNumber(value.multipleOf));
|
|
199
199
|
}
|
|
200
|
-
exports.
|
|
200
|
+
exports.IsInteger = IsInteger;
|
|
201
201
|
/** Returns true if the given schema is TProperties */
|
|
202
|
-
function
|
|
202
|
+
function IsProperties(value) {
|
|
203
203
|
// prettier-ignore
|
|
204
204
|
return (ValueGuard.IsObject(value) &&
|
|
205
|
-
Object.entries(value).every(([key, schema]) => IsControlCharacterFree(key) && (
|
|
205
|
+
Object.entries(value).every(([key, schema]) => IsControlCharacterFree(key) && IsSchema(schema)));
|
|
206
206
|
}
|
|
207
|
-
exports.
|
|
207
|
+
exports.IsProperties = IsProperties;
|
|
208
208
|
/** Returns true if the given value is TIntersect */
|
|
209
|
-
function
|
|
209
|
+
function IsIntersect(value) {
|
|
210
210
|
// prettier-ignore
|
|
211
|
-
return (
|
|
211
|
+
return (IsKindOf(value, 'Intersect') &&
|
|
212
212
|
(ValueGuard.IsString(value.type) && value.type !== 'object' ? false : true) &&
|
|
213
213
|
ValueGuard.IsArray(value.allOf) &&
|
|
214
|
-
value.allOf.every(schema => (
|
|
214
|
+
value.allOf.every(schema => IsSchema(schema) && !IsTransform(schema)) &&
|
|
215
215
|
IsOptionalString(value.type) &&
|
|
216
216
|
(IsOptionalBoolean(value.unevaluatedProperties) || IsOptionalSchema(value.unevaluatedProperties)) &&
|
|
217
217
|
IsOptionalString(value.$id));
|
|
218
218
|
}
|
|
219
|
-
exports.
|
|
219
|
+
exports.IsIntersect = IsIntersect;
|
|
220
220
|
/** Returns true if the given value is TIterator */
|
|
221
|
-
function
|
|
221
|
+
function IsIterator(value) {
|
|
222
222
|
// prettier-ignore
|
|
223
|
-
return (
|
|
223
|
+
return (IsKindOf(value, 'Iterator') &&
|
|
224
224
|
value.type === 'Iterator' &&
|
|
225
225
|
IsOptionalString(value.$id) &&
|
|
226
|
-
(
|
|
226
|
+
IsSchema(value.items));
|
|
227
227
|
}
|
|
228
|
-
exports.
|
|
228
|
+
exports.IsIterator = IsIterator;
|
|
229
229
|
/** Returns true if the given value is a TKind with the given name. */
|
|
230
|
-
function
|
|
230
|
+
function IsKindOf(value, kind) {
|
|
231
231
|
return ValueGuard.IsObject(value) && index_1.Kind in value && value[index_1.Kind] === kind;
|
|
232
232
|
}
|
|
233
|
-
exports.
|
|
233
|
+
exports.IsKindOf = IsKindOf;
|
|
234
234
|
/** Returns true if the given value is TLiteral<string> */
|
|
235
|
-
function
|
|
236
|
-
return (
|
|
235
|
+
function IsLiteralString(value) {
|
|
236
|
+
return IsLiteral(value) && ValueGuard.IsString(value.const);
|
|
237
237
|
}
|
|
238
|
-
exports.
|
|
238
|
+
exports.IsLiteralString = IsLiteralString;
|
|
239
239
|
/** Returns true if the given value is TLiteral<number> */
|
|
240
|
-
function
|
|
241
|
-
return (
|
|
240
|
+
function IsLiteralNumber(value) {
|
|
241
|
+
return IsLiteral(value) && ValueGuard.IsNumber(value.const);
|
|
242
242
|
}
|
|
243
|
-
exports.
|
|
243
|
+
exports.IsLiteralNumber = IsLiteralNumber;
|
|
244
244
|
/** Returns true if the given value is TLiteral<boolean> */
|
|
245
|
-
function
|
|
246
|
-
return (
|
|
245
|
+
function IsLiteralBoolean(value) {
|
|
246
|
+
return IsLiteral(value) && ValueGuard.IsBoolean(value.const);
|
|
247
247
|
}
|
|
248
|
-
exports.
|
|
248
|
+
exports.IsLiteralBoolean = IsLiteralBoolean;
|
|
249
249
|
/** Returns true if the given value is TLiteral */
|
|
250
|
-
function
|
|
250
|
+
function IsLiteral(value) {
|
|
251
251
|
// prettier-ignore
|
|
252
|
-
return (
|
|
253
|
-
IsOptionalString(value.$id) && (
|
|
252
|
+
return (IsKindOf(value, 'Literal') &&
|
|
253
|
+
IsOptionalString(value.$id) && IsLiteralValue(value.const));
|
|
254
254
|
}
|
|
255
|
-
exports.
|
|
255
|
+
exports.IsLiteral = IsLiteral;
|
|
256
256
|
/** Returns true if the given value is a TLiteralValue */
|
|
257
|
-
function
|
|
257
|
+
function IsLiteralValue(value) {
|
|
258
258
|
return ValueGuard.IsBoolean(value) || ValueGuard.IsNumber(value) || ValueGuard.IsString(value);
|
|
259
259
|
}
|
|
260
|
-
exports.
|
|
260
|
+
exports.IsLiteralValue = IsLiteralValue;
|
|
261
261
|
/** Returns true if the given value is a TMappedKey */
|
|
262
|
-
function
|
|
262
|
+
function IsMappedKey(value) {
|
|
263
263
|
// prettier-ignore
|
|
264
|
-
return (
|
|
264
|
+
return (IsKindOf(value, 'MappedKey') &&
|
|
265
265
|
ValueGuard.IsArray(value.keys) &&
|
|
266
266
|
value.keys.every(key => ValueGuard.IsNumber(key) || ValueGuard.IsString(key)));
|
|
267
267
|
}
|
|
268
|
-
exports.
|
|
268
|
+
exports.IsMappedKey = IsMappedKey;
|
|
269
269
|
/** Returns true if the given value is TMappedResult */
|
|
270
|
-
function
|
|
270
|
+
function IsMappedResult(value) {
|
|
271
271
|
// prettier-ignore
|
|
272
|
-
return (
|
|
273
|
-
(
|
|
272
|
+
return (IsKindOf(value, 'MappedResult') &&
|
|
273
|
+
IsProperties(value.properties));
|
|
274
274
|
}
|
|
275
|
-
exports.
|
|
275
|
+
exports.IsMappedResult = IsMappedResult;
|
|
276
276
|
/** Returns true if the given value is TNever */
|
|
277
|
-
function
|
|
277
|
+
function IsNever(value) {
|
|
278
278
|
// prettier-ignore
|
|
279
|
-
return (
|
|
279
|
+
return (IsKindOf(value, 'Never') &&
|
|
280
280
|
ValueGuard.IsObject(value.not) &&
|
|
281
281
|
Object.getOwnPropertyNames(value.not).length === 0);
|
|
282
282
|
}
|
|
283
|
-
exports.
|
|
283
|
+
exports.IsNever = IsNever;
|
|
284
284
|
/** Returns true if the given value is TNot */
|
|
285
|
-
function
|
|
285
|
+
function IsNot(value) {
|
|
286
286
|
// prettier-ignore
|
|
287
|
-
return (
|
|
288
|
-
(
|
|
287
|
+
return (IsKindOf(value, 'Not') &&
|
|
288
|
+
IsSchema(value.not));
|
|
289
289
|
}
|
|
290
|
-
exports.
|
|
290
|
+
exports.IsNot = IsNot;
|
|
291
291
|
/** Returns true if the given value is TNull */
|
|
292
|
-
function
|
|
292
|
+
function IsNull(value) {
|
|
293
293
|
// prettier-ignore
|
|
294
|
-
return (
|
|
294
|
+
return (IsKindOf(value, 'Null') &&
|
|
295
295
|
value.type === 'null' &&
|
|
296
296
|
IsOptionalString(value.$id));
|
|
297
297
|
}
|
|
298
|
-
exports.
|
|
298
|
+
exports.IsNull = IsNull;
|
|
299
299
|
/** Returns true if the given value is TNumber */
|
|
300
|
-
function
|
|
301
|
-
return (
|
|
300
|
+
function IsNumber(value) {
|
|
301
|
+
return (IsKindOf(value, 'Number') &&
|
|
302
302
|
value.type === 'number' &&
|
|
303
303
|
IsOptionalString(value.$id) &&
|
|
304
304
|
IsOptionalNumber(value.exclusiveMaximum) &&
|
|
@@ -307,32 +307,32 @@ function TNumber(value) {
|
|
|
307
307
|
IsOptionalNumber(value.minimum) &&
|
|
308
308
|
IsOptionalNumber(value.multipleOf));
|
|
309
309
|
}
|
|
310
|
-
exports.
|
|
310
|
+
exports.IsNumber = IsNumber;
|
|
311
311
|
/** Returns true if the given value is TObject */
|
|
312
|
-
function
|
|
312
|
+
function IsObject(value) {
|
|
313
313
|
// prettier-ignore
|
|
314
|
-
return (
|
|
314
|
+
return (IsKindOf(value, 'Object') &&
|
|
315
315
|
value.type === 'object' &&
|
|
316
316
|
IsOptionalString(value.$id) &&
|
|
317
|
-
(
|
|
317
|
+
IsProperties(value.properties) &&
|
|
318
318
|
IsAdditionalProperties(value.additionalProperties) &&
|
|
319
319
|
IsOptionalNumber(value.minProperties) &&
|
|
320
320
|
IsOptionalNumber(value.maxProperties));
|
|
321
321
|
}
|
|
322
|
-
exports.
|
|
322
|
+
exports.IsObject = IsObject;
|
|
323
323
|
/** Returns true if the given value is TPromise */
|
|
324
|
-
function
|
|
324
|
+
function IsPromise(value) {
|
|
325
325
|
// prettier-ignore
|
|
326
|
-
return (
|
|
326
|
+
return (IsKindOf(value, 'Promise') &&
|
|
327
327
|
value.type === 'Promise' &&
|
|
328
328
|
IsOptionalString(value.$id) &&
|
|
329
|
-
(
|
|
329
|
+
IsSchema(value.item));
|
|
330
330
|
}
|
|
331
|
-
exports.
|
|
331
|
+
exports.IsPromise = IsPromise;
|
|
332
332
|
/** Returns true if the given value is TRecord */
|
|
333
|
-
function
|
|
333
|
+
function IsRecord(value) {
|
|
334
334
|
// prettier-ignore
|
|
335
|
-
return (
|
|
335
|
+
return (IsKindOf(value, 'Record') &&
|
|
336
336
|
value.type === 'object' &&
|
|
337
337
|
IsOptionalString(value.$id) &&
|
|
338
338
|
IsAdditionalProperties(value.additionalProperties) &&
|
|
@@ -342,27 +342,27 @@ function TRecord(value) {
|
|
|
342
342
|
return (keys.length === 1 &&
|
|
343
343
|
IsPattern(keys[0]) &&
|
|
344
344
|
ValueGuard.IsObject(schema.patternProperties) &&
|
|
345
|
-
(
|
|
345
|
+
IsSchema(schema.patternProperties[keys[0]]));
|
|
346
346
|
})(value));
|
|
347
347
|
}
|
|
348
|
-
exports.
|
|
348
|
+
exports.IsRecord = IsRecord;
|
|
349
349
|
/** Returns true if this value is TRecursive */
|
|
350
|
-
function
|
|
350
|
+
function IsRecursive(value) {
|
|
351
351
|
return ValueGuard.IsObject(value) && index_1.Hint in value && value[index_1.Hint] === 'Recursive';
|
|
352
352
|
}
|
|
353
|
-
exports.
|
|
353
|
+
exports.IsRecursive = IsRecursive;
|
|
354
354
|
/** Returns true if the given value is TRef */
|
|
355
|
-
function
|
|
355
|
+
function IsRef(value) {
|
|
356
356
|
// prettier-ignore
|
|
357
|
-
return (
|
|
357
|
+
return (IsKindOf(value, 'Ref') &&
|
|
358
358
|
IsOptionalString(value.$id) &&
|
|
359
359
|
ValueGuard.IsString(value.$ref));
|
|
360
360
|
}
|
|
361
|
-
exports.
|
|
361
|
+
exports.IsRef = IsRef;
|
|
362
362
|
/** Returns true if the given value is TString */
|
|
363
|
-
function
|
|
363
|
+
function IsString(value) {
|
|
364
364
|
// prettier-ignore
|
|
365
|
-
return (
|
|
365
|
+
return (IsKindOf(value, 'String') &&
|
|
366
366
|
value.type === 'string' &&
|
|
367
367
|
IsOptionalString(value.$id) &&
|
|
368
368
|
IsOptionalNumber(value.minLength) &&
|
|
@@ -370,42 +370,42 @@ function TString(value) {
|
|
|
370
370
|
IsOptionalPattern(value.pattern) &&
|
|
371
371
|
IsOptionalFormat(value.format));
|
|
372
372
|
}
|
|
373
|
-
exports.
|
|
373
|
+
exports.IsString = IsString;
|
|
374
374
|
/** Returns true if the given value is TSymbol */
|
|
375
|
-
function
|
|
375
|
+
function IsSymbol(value) {
|
|
376
376
|
// prettier-ignore
|
|
377
|
-
return (
|
|
377
|
+
return (IsKindOf(value, 'Symbol') &&
|
|
378
378
|
value.type === 'symbol' &&
|
|
379
379
|
IsOptionalString(value.$id));
|
|
380
380
|
}
|
|
381
|
-
exports.
|
|
381
|
+
exports.IsSymbol = IsSymbol;
|
|
382
382
|
/** Returns true if the given value is TTemplateLiteral */
|
|
383
|
-
function
|
|
383
|
+
function IsTemplateLiteral(value) {
|
|
384
384
|
// prettier-ignore
|
|
385
|
-
return (
|
|
385
|
+
return (IsKindOf(value, 'TemplateLiteral') &&
|
|
386
386
|
value.type === 'string' &&
|
|
387
387
|
ValueGuard.IsString(value.pattern) &&
|
|
388
388
|
value.pattern[0] === '^' &&
|
|
389
389
|
value.pattern[value.pattern.length - 1] === '$');
|
|
390
390
|
}
|
|
391
|
-
exports.
|
|
391
|
+
exports.IsTemplateLiteral = IsTemplateLiteral;
|
|
392
392
|
/** Returns true if the given value is TThis */
|
|
393
|
-
function
|
|
393
|
+
function IsThis(value) {
|
|
394
394
|
// prettier-ignore
|
|
395
|
-
return (
|
|
395
|
+
return (IsKindOf(value, 'This') &&
|
|
396
396
|
IsOptionalString(value.$id) &&
|
|
397
397
|
ValueGuard.IsString(value.$ref));
|
|
398
398
|
}
|
|
399
|
-
exports.
|
|
399
|
+
exports.IsThis = IsThis;
|
|
400
400
|
/** Returns true of this value is TTransform */
|
|
401
|
-
function
|
|
401
|
+
function IsTransform(value) {
|
|
402
402
|
return ValueGuard.IsObject(value) && index_1.TransformKind in value;
|
|
403
403
|
}
|
|
404
|
-
exports.
|
|
404
|
+
exports.IsTransform = IsTransform;
|
|
405
405
|
/** Returns true if the given value is TTuple */
|
|
406
|
-
function
|
|
406
|
+
function IsTuple(value) {
|
|
407
407
|
// prettier-ignore
|
|
408
|
-
return (
|
|
408
|
+
return (IsKindOf(value, 'Tuple') &&
|
|
409
409
|
value.type === 'array' &&
|
|
410
410
|
IsOptionalString(value.$id) &&
|
|
411
411
|
ValueGuard.IsNumber(value.minItems) &&
|
|
@@ -415,103 +415,103 @@ function TTuple(value) {
|
|
|
415
415
|
ValueGuard.IsUndefined(value.items) &&
|
|
416
416
|
ValueGuard.IsUndefined(value.additionalItems) &&
|
|
417
417
|
value.minItems === 0) || (ValueGuard.IsArray(value.items) &&
|
|
418
|
-
value.items.every(schema => (
|
|
418
|
+
value.items.every(schema => IsSchema(schema)))));
|
|
419
419
|
}
|
|
420
|
-
exports.
|
|
420
|
+
exports.IsTuple = IsTuple;
|
|
421
421
|
/** Returns true if the given value is TUndefined */
|
|
422
|
-
function
|
|
422
|
+
function IsUndefined(value) {
|
|
423
423
|
// prettier-ignore
|
|
424
|
-
return (
|
|
424
|
+
return (IsKindOf(value, 'Undefined') &&
|
|
425
425
|
value.type === 'undefined' &&
|
|
426
426
|
IsOptionalString(value.$id));
|
|
427
427
|
}
|
|
428
|
-
exports.
|
|
428
|
+
exports.IsUndefined = IsUndefined;
|
|
429
429
|
/** Returns true if the given value is TUnion<Literal<string | number>[]> */
|
|
430
|
-
function
|
|
431
|
-
return (
|
|
430
|
+
function IsUnionLiteral(value) {
|
|
431
|
+
return IsUnion(value) && value.anyOf.every((schema) => IsLiteralString(schema) || IsLiteralNumber(schema));
|
|
432
432
|
}
|
|
433
|
-
exports.
|
|
433
|
+
exports.IsUnionLiteral = IsUnionLiteral;
|
|
434
434
|
/** Returns true if the given value is TUnion */
|
|
435
|
-
function
|
|
435
|
+
function IsUnion(value) {
|
|
436
436
|
// prettier-ignore
|
|
437
|
-
return (
|
|
437
|
+
return (IsKindOf(value, 'Union') &&
|
|
438
438
|
IsOptionalString(value.$id) &&
|
|
439
439
|
ValueGuard.IsObject(value) &&
|
|
440
440
|
ValueGuard.IsArray(value.anyOf) &&
|
|
441
|
-
value.anyOf.every(schema => (
|
|
441
|
+
value.anyOf.every(schema => IsSchema(schema)));
|
|
442
442
|
}
|
|
443
|
-
exports.
|
|
443
|
+
exports.IsUnion = IsUnion;
|
|
444
444
|
/** Returns true if the given value is TUint8Array */
|
|
445
|
-
function
|
|
445
|
+
function IsUint8Array(value) {
|
|
446
446
|
// prettier-ignore
|
|
447
|
-
return (
|
|
447
|
+
return (IsKindOf(value, 'Uint8Array') &&
|
|
448
448
|
value.type === 'Uint8Array' &&
|
|
449
449
|
IsOptionalString(value.$id) &&
|
|
450
450
|
IsOptionalNumber(value.minByteLength) &&
|
|
451
451
|
IsOptionalNumber(value.maxByteLength));
|
|
452
452
|
}
|
|
453
|
-
exports.
|
|
453
|
+
exports.IsUint8Array = IsUint8Array;
|
|
454
454
|
/** Returns true if the given value is TUnknown */
|
|
455
|
-
function
|
|
455
|
+
function IsUnknown(value) {
|
|
456
456
|
// prettier-ignore
|
|
457
|
-
return (
|
|
457
|
+
return (IsKindOf(value, 'Unknown') &&
|
|
458
458
|
IsOptionalString(value.$id));
|
|
459
459
|
}
|
|
460
|
-
exports.
|
|
460
|
+
exports.IsUnknown = IsUnknown;
|
|
461
461
|
/** Returns true if the given value is a raw TUnsafe */
|
|
462
|
-
function
|
|
463
|
-
return
|
|
462
|
+
function IsUnsafe(value) {
|
|
463
|
+
return IsKindOf(value, 'Unsafe');
|
|
464
464
|
}
|
|
465
|
-
exports.
|
|
465
|
+
exports.IsUnsafe = IsUnsafe;
|
|
466
466
|
/** Returns true if the given value is TVoid */
|
|
467
|
-
function
|
|
467
|
+
function IsVoid(value) {
|
|
468
468
|
// prettier-ignore
|
|
469
|
-
return (
|
|
469
|
+
return (IsKindOf(value, 'Void') &&
|
|
470
470
|
value.type === 'void' &&
|
|
471
471
|
IsOptionalString(value.$id));
|
|
472
472
|
}
|
|
473
|
-
exports.
|
|
473
|
+
exports.IsVoid = IsVoid;
|
|
474
474
|
/** Returns true if the given value is TKind */
|
|
475
|
-
function
|
|
475
|
+
function IsKind(value) {
|
|
476
476
|
return ValueGuard.IsObject(value) && index_1.Kind in value && ValueGuard.IsString(value[index_1.Kind]) && !KnownTypes.includes(value[index_1.Kind]);
|
|
477
477
|
}
|
|
478
|
-
exports.
|
|
478
|
+
exports.IsKind = IsKind;
|
|
479
479
|
/** Returns true if the given value is TSchema */
|
|
480
|
-
function
|
|
480
|
+
function IsSchema(value) {
|
|
481
481
|
// prettier-ignore
|
|
482
|
-
return (ValueGuard.IsObject(value)) && ((
|
|
483
|
-
(
|
|
484
|
-
(
|
|
485
|
-
(
|
|
486
|
-
(
|
|
487
|
-
(
|
|
488
|
-
(
|
|
489
|
-
(
|
|
490
|
-
(
|
|
491
|
-
(
|
|
492
|
-
(
|
|
493
|
-
(
|
|
494
|
-
(
|
|
495
|
-
(
|
|
496
|
-
(
|
|
497
|
-
(
|
|
498
|
-
(
|
|
499
|
-
(
|
|
500
|
-
(
|
|
501
|
-
(
|
|
502
|
-
(
|
|
503
|
-
(
|
|
504
|
-
(
|
|
505
|
-
(
|
|
506
|
-
(
|
|
507
|
-
(
|
|
508
|
-
(
|
|
509
|
-
(
|
|
510
|
-
(
|
|
511
|
-
(
|
|
512
|
-
(
|
|
513
|
-
(
|
|
514
|
-
(
|
|
515
|
-
|
|
516
|
-
}
|
|
517
|
-
exports.
|
|
482
|
+
return (ValueGuard.IsObject(value)) && (IsAny(value) ||
|
|
483
|
+
IsArray(value) ||
|
|
484
|
+
IsBoolean(value) ||
|
|
485
|
+
IsBigInt(value) ||
|
|
486
|
+
IsAsyncIterator(value) ||
|
|
487
|
+
IsConstructor(value) ||
|
|
488
|
+
IsDate(value) ||
|
|
489
|
+
IsFunction(value) ||
|
|
490
|
+
IsInteger(value) ||
|
|
491
|
+
IsIntersect(value) ||
|
|
492
|
+
IsIterator(value) ||
|
|
493
|
+
IsLiteral(value) ||
|
|
494
|
+
IsMappedKey(value) ||
|
|
495
|
+
IsMappedResult(value) ||
|
|
496
|
+
IsNever(value) ||
|
|
497
|
+
IsNot(value) ||
|
|
498
|
+
IsNull(value) ||
|
|
499
|
+
IsNumber(value) ||
|
|
500
|
+
IsObject(value) ||
|
|
501
|
+
IsPromise(value) ||
|
|
502
|
+
IsRecord(value) ||
|
|
503
|
+
IsRef(value) ||
|
|
504
|
+
IsString(value) ||
|
|
505
|
+
IsSymbol(value) ||
|
|
506
|
+
IsTemplateLiteral(value) ||
|
|
507
|
+
IsThis(value) ||
|
|
508
|
+
IsTuple(value) ||
|
|
509
|
+
IsUndefined(value) ||
|
|
510
|
+
IsUnion(value) ||
|
|
511
|
+
IsUint8Array(value) ||
|
|
512
|
+
IsUnknown(value) ||
|
|
513
|
+
IsUnsafe(value) ||
|
|
514
|
+
IsVoid(value) ||
|
|
515
|
+
IsKind(value));
|
|
516
|
+
}
|
|
517
|
+
exports.IsSchema = IsSchema;
|
|
@@ -14,7 +14,7 @@ function FromTemplateLiteral(T) {
|
|
|
14
14
|
const F = (0, index_1.IsTemplateLiteralFinite)(E);
|
|
15
15
|
const S = (0, index_1.TemplateLiteralToUnion)(T);
|
|
16
16
|
return (F === true
|
|
17
|
-
? (0, type_1.
|
|
17
|
+
? (0, type_1.IsUnionLiteral)(S)
|
|
18
18
|
? S.anyOf.map(S => S.const.toString())
|
|
19
19
|
: []
|
|
20
20
|
: []);
|
|
@@ -33,11 +33,11 @@ function FromLiteral(T) {
|
|
|
33
33
|
/** Returns a tuple of PropertyKeys derived from the given TSchema */
|
|
34
34
|
// prettier-ignore
|
|
35
35
|
function IndexPropertyKeys(T) {
|
|
36
|
-
return [...new Set(((0, type_1.
|
|
37
|
-
(0, type_1.
|
|
38
|
-
(0, type_1.
|
|
39
|
-
(0, type_1.
|
|
40
|
-
(0, type_1.
|
|
36
|
+
return [...new Set(((0, type_1.IsTemplateLiteral)(T) ? FromTemplateLiteral(T) :
|
|
37
|
+
(0, type_1.IsUnion)(T) ? FromUnion(T.anyOf) :
|
|
38
|
+
(0, type_1.IsLiteral)(T) ? FromLiteral(T.const) :
|
|
39
|
+
(0, type_1.IsNumber)(T) ? ['[number]'] :
|
|
40
|
+
(0, type_1.IsInteger)(T) ? ['[number]'] :
|
|
41
41
|
[]))];
|
|
42
42
|
}
|
|
43
43
|
exports.IndexPropertyKeys = IndexPropertyKeys;
|