@sinclair/typebox 0.31.28 → 0.32.0-dev-1
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/compiler/compiler.d.ts +25 -18
- package/compiler/compiler.js +118 -107
- package/errors/errors.d.ts +7 -7
- package/errors/errors.js +48 -44
- package/index.d.ts +71 -0
- package/index.js +205 -0
- package/package.json +8 -19
- package/readme.md +183 -155
- package/system/errors.d.ts +14 -0
- package/system/errors.js +192 -0
- package/system/index.d.ts +3 -1
- package/system/index.js +10 -16
- package/system/policy.d.ts +21 -0
- package/system/policy.js +74 -0
- package/system/system.d.ts +3 -38
- package/system/system.js +15 -218
- package/type/any/any.d.ts +8 -0
- package/type/any/any.js +36 -0
- package/type/any/index.d.ts +1 -0
- package/type/any/index.js +44 -0
- package/type/array/array.d.ts +25 -0
- package/type/array/array.js +42 -0
- package/type/array/index.d.ts +1 -0
- package/type/array/index.js +44 -0
- package/type/async-iterator/async-iterator.d.ts +11 -0
- package/type/async-iterator/async-iterator.js +42 -0
- package/type/async-iterator/index.d.ts +1 -0
- package/type/async-iterator/index.js +44 -0
- package/type/awaited/awaited.d.ts +12 -0
- package/type/awaited/awaited.js +66 -0
- package/type/awaited/index.d.ts +1 -0
- package/type/awaited/index.js +44 -0
- package/type/bigint/bigint.d.ts +16 -0
- package/type/bigint/bigint.js +40 -0
- package/type/bigint/index.d.ts +1 -0
- package/type/bigint/index.js +44 -0
- package/type/boolean/boolean.d.ts +9 -0
- package/type/boolean/boolean.js +40 -0
- package/type/boolean/index.d.ts +1 -0
- package/type/boolean/index.js +44 -0
- package/type/clone/index.d.ts +2 -0
- package/type/clone/index.js +32 -0
- package/type/clone/type.d.ts +5 -0
- package/type/clone/type.js +41 -0
- package/type/clone/value.d.ts +2 -0
- package/type/clone/value.js +58 -0
- package/type/composite/composite.d.ts +15 -0
- package/type/composite/composite.js +47 -0
- package/type/composite/index.d.ts +1 -0
- package/type/composite/index.js +44 -0
- package/type/const/const.d.ts +30 -0
- package/type/const/const.js +84 -0
- package/type/const/index.d.ts +1 -0
- package/type/const/index.js +44 -0
- package/type/constructor/constructor.d.ts +17 -0
- package/type/constructor/constructor.js +43 -0
- package/type/constructor/index.d.ts +1 -0
- package/type/constructor/index.js +44 -0
- package/type/constructor-parameters/constructor-parameters.d.ts +7 -0
- package/type/constructor-parameters/constructor-parameters.js +37 -0
- package/type/constructor-parameters/index.d.ts +1 -0
- package/type/constructor-parameters/index.js +44 -0
- package/type/date/date.d.ts +21 -0
- package/type/date/date.js +40 -0
- package/type/date/index.d.ts +1 -0
- package/type/date/index.js +44 -0
- package/type/deref/deref.d.ts +24 -0
- package/type/deref/deref.js +136 -0
- package/type/deref/index.d.ts +1 -0
- package/type/deref/index.js +44 -0
- package/type/discard/discard.d.ts +1 -0
- package/type/discard/discard.js +38 -0
- package/type/discard/index.d.ts +1 -0
- package/type/discard/index.js +44 -0
- package/type/enum/enum.d.ts +14 -0
- package/type/enum/enum.js +46 -0
- package/type/enum/index.d.ts +1 -0
- package/type/enum/index.js +44 -0
- package/type/exclude/exclude.d.ts +21 -0
- package/type/exclude/exclude.js +54 -0
- package/type/exclude/index.d.ts +1 -0
- package/type/exclude/index.js +44 -0
- package/type/extends/extends-check.d.ts +9 -0
- package/type/extends/extends-check.js +654 -0
- package/type/extends/extends-undefined.d.ts +3 -0
- package/type/extends/extends-undefined.js +51 -0
- package/type/extends/extends.d.ts +9 -0
- package/type/extends/extends.js +47 -0
- package/type/extends/index.d.ts +3 -0
- package/type/extends/index.js +46 -0
- package/type/extract/extract.d.ts +20 -0
- package/type/extract/extract.js +54 -0
- package/type/extract/index.d.ts +1 -0
- package/type/extract/index.js +44 -0
- package/type/function/function.d.ts +17 -0
- package/type/function/function.js +43 -0
- package/type/function/index.d.ts +1 -0
- package/type/function/index.js +44 -0
- package/type/guard/index.d.ts +2 -0
- package/type/guard/index.js +32 -0
- package/type/guard/type.d.ts +130 -0
- package/type/guard/type.js +515 -0
- package/type/guard/value.d.ts +28 -0
- package/type/guard/value.js +100 -0
- package/type/helpers/helpers.d.ts +42 -0
- package/type/helpers/helpers.js +35 -0
- package/type/helpers/index.d.ts +1 -0
- package/type/helpers/index.js +44 -0
- package/type/index.d.ts +70 -0
- package/type/index.js +113 -0
- package/type/indexed/index.d.ts +3 -0
- package/type/indexed/index.js +46 -0
- package/type/indexed/indexed-key.d.ts +17 -0
- package/type/indexed/indexed-key.js +65 -0
- package/type/indexed/indexed-type.d.ts +33 -0
- package/type/indexed/indexed-type.js +106 -0
- package/type/indexed/indexed.d.ts +8 -0
- package/type/indexed/indexed.js +41 -0
- package/type/instance-type/index.d.ts +1 -0
- package/type/instance-type/index.js +44 -0
- package/type/instance-type/instance-type.d.ts +5 -0
- package/type/instance-type/instance-type.js +36 -0
- package/type/integer/index.d.ts +1 -0
- package/type/integer/index.js +44 -0
- package/type/integer/integer.d.ts +16 -0
- package/type/integer/integer.js +40 -0
- package/type/intersect/index.d.ts +1 -0
- package/type/intersect/index.js +44 -0
- package/type/intersect/intersect.d.ts +22 -0
- package/type/intersect/intersect.js +59 -0
- package/type/intrinsic/index.d.ts +1 -0
- package/type/intrinsic/index.js +44 -0
- package/type/intrinsic/intrinsic.d.ts +27 -0
- package/type/intrinsic/intrinsic.js +106 -0
- package/type/iterator/index.d.ts +1 -0
- package/type/iterator/index.js +44 -0
- package/type/iterator/iterator.d.ts +11 -0
- package/type/iterator/iterator.js +42 -0
- package/type/keyof/index.d.ts +3 -0
- package/type/keyof/index.js +46 -0
- package/type/keyof/keyof-string.d.ts +30 -0
- package/type/keyof/keyof-string.js +103 -0
- package/type/keyof/keyof-type.d.ts +11 -0
- package/type/keyof/keyof-type.js +48 -0
- package/type/keyof/keyof.d.ts +5 -0
- package/type/keyof/keyof.js +38 -0
- package/type/literal/index.d.ts +1 -0
- package/type/literal/index.js +44 -0
- package/type/literal/literal.d.ts +10 -0
- package/type/literal/literal.js +41 -0
- package/type/mapped/index.d.ts +1 -0
- package/type/mapped/index.js +44 -0
- package/type/mapped/mapped.d.ts +26 -0
- package/type/mapped/mapped.js +47 -0
- package/type/modifiers/index.d.ts +1 -0
- package/type/modifiers/index.js +44 -0
- package/type/modifiers/modifiers.d.ts +18 -0
- package/type/modifiers/modifiers.js +78 -0
- package/type/never/index.d.ts +1 -0
- package/type/never/index.js +44 -0
- package/type/never/never.d.ts +9 -0
- package/type/never/never.js +40 -0
- package/type/not/index.d.ts +1 -0
- package/type/not/index.js +44 -0
- package/type/not/not.d.ts +10 -0
- package/type/not/not.js +41 -0
- package/type/null/index.d.ts +1 -0
- package/type/null/index.js +44 -0
- package/type/null/null.d.ts +9 -0
- package/type/null/null.js +40 -0
- package/type/number/index.d.ts +1 -0
- package/type/number/index.js +44 -0
- package/type/number/number.d.ts +16 -0
- package/type/number/number.js +40 -0
- package/type/object/index.d.ts +1 -0
- package/type/object/index.js +44 -0
- package/type/object/object.d.ts +44 -0
- package/type/object/object.js +47 -0
- package/type/omit/index.d.ts +1 -0
- package/type/omit/index.js +44 -0
- package/type/omit/omit.d.ts +21 -0
- package/type/omit/omit.js +75 -0
- package/type/operators/index.d.ts +1 -0
- package/type/operators/index.js +44 -0
- package/type/operators/operators.d.ts +24 -0
- package/type/operators/operators.js +119 -0
- package/type/optional/index.d.ts +1 -0
- package/type/optional/index.js +44 -0
- package/type/optional/optional.d.ts +7 -0
- package/type/optional/optional.js +37 -0
- package/type/parameters/index.d.ts +1 -0
- package/type/parameters/index.js +44 -0
- package/type/parameters/parameters.d.ts +7 -0
- package/type/parameters/parameters.js +37 -0
- package/type/partial/index.d.ts +1 -0
- package/type/partial/index.js +44 -0
- package/type/partial/partial.d.ts +23 -0
- package/type/partial/partial.js +73 -0
- package/type/patterns/index.d.ts +1 -0
- package/type/patterns/index.js +44 -0
- package/type/patterns/patterns.d.ts +6 -0
- package/type/patterns/patterns.js +36 -0
- package/type/pick/index.d.ts +1 -0
- package/type/pick/index.js +44 -0
- package/type/pick/pick.d.ts +21 -0
- package/type/pick/pick.js +66 -0
- package/type/promise/index.d.ts +1 -0
- package/type/promise/index.js +44 -0
- package/type/promise/promise.d.ts +11 -0
- package/type/promise/promise.js +42 -0
- package/type/readonly/index.d.ts +1 -0
- package/type/readonly/index.js +44 -0
- package/type/readonly/readonly.d.ts +7 -0
- package/type/readonly/readonly.js +37 -0
- package/type/readonly-optional/index.d.ts +1 -0
- package/type/readonly-optional/index.js +44 -0
- package/type/readonly-optional/readonly-optional.d.ts +6 -0
- package/type/readonly-optional/readonly-optional.js +37 -0
- package/type/record/index.d.ts +1 -0
- package/type/record/index.js +44 -0
- package/type/record/record.d.ts +55 -0
- package/type/record/record.js +97 -0
- package/type/recursive/index.d.ts +1 -0
- package/type/recursive/index.js +44 -0
- package/type/recursive/recursive.d.ts +15 -0
- package/type/recursive/recursive.js +48 -0
- package/type/ref/index.d.ts +1 -0
- package/type/ref/index.js +44 -0
- package/type/ref/ref.d.ts +12 -0
- package/type/ref/ref.js +45 -0
- package/type/regexp/index.d.ts +1 -0
- package/type/regexp/index.js +44 -0
- package/type/regexp/regexp.d.ts +7 -0
- package/type/regexp/regexp.js +38 -0
- package/type/registry/format.d.ts +13 -0
- package/type/registry/format.js +62 -0
- package/type/registry/index.d.ts +2 -0
- package/type/registry/index.js +32 -0
- package/type/registry/type.d.ts +13 -0
- package/type/registry/type.js +62 -0
- package/type/required/index.d.ts +1 -0
- package/type/required/index.js +44 -0
- package/type/required/required.d.ts +23 -0
- package/type/required/required.js +72 -0
- package/type/rest/index.d.ts +1 -0
- package/type/rest/index.js +44 -0
- package/type/rest/rest.d.ts +10 -0
- package/type/rest/rest.js +41 -0
- package/type/return-type/index.d.ts +1 -0
- package/type/return-type/index.js +44 -0
- package/type/return-type/return-type.d.ts +5 -0
- package/type/return-type/return-type.js +36 -0
- package/type/schema/anyschema.d.ts +32 -0
- package/type/schema/anyschema.js +29 -0
- package/type/schema/index.d.ts +2 -0
- package/type/schema/index.js +45 -0
- package/type/schema/schema.d.ts +29 -0
- package/type/schema/schema.js +30 -0
- package/type/static/index.d.ts +1 -0
- package/type/static/index.js +44 -0
- package/type/static/static.d.ts +34 -0
- package/type/static/static.js +29 -0
- package/type/strict/index.d.ts +1 -0
- package/type/strict/index.js +44 -0
- package/type/strict/strict.d.ts +3 -0
- package/type/strict/strict.js +35 -0
- package/type/string/index.d.ts +1 -0
- package/type/string/index.js +44 -0
- package/type/string/string.d.ts +25 -0
- package/type/string/string.js +36 -0
- package/type/symbol/index.d.ts +1 -0
- package/type/symbol/index.js +44 -0
- package/type/symbol/symbol.d.ts +10 -0
- package/type/symbol/symbol.js +36 -0
- package/type/symbols/index.d.ts +1 -0
- package/type/symbols/index.js +44 -0
- package/type/symbols/symbols.d.ts +10 -0
- package/type/symbols/symbols.js +40 -0
- package/type/template-literal/finite.d.ts +16 -0
- package/type/template-literal/finite.js +71 -0
- package/type/template-literal/generate.d.ts +15 -0
- package/type/template-literal/generate.js +74 -0
- package/type/template-literal/index.d.ts +7 -0
- package/type/template-literal/index.js +50 -0
- package/type/template-literal/parser.d.ts +19 -0
- package/type/template-literal/parser.js +175 -0
- package/type/template-literal/pattern.d.ts +4 -0
- package/type/template-literal/pattern.js +61 -0
- package/type/template-literal/syntax.d.ts +20 -0
- package/type/template-literal/syntax.js +87 -0
- package/type/template-literal/template-literal.d.ts +30 -0
- package/type/template-literal/template-literal.js +43 -0
- package/type/template-literal/union.d.ts +7 -0
- package/type/template-literal/union.js +48 -0
- package/type/transform/index.d.ts +1 -0
- package/type/transform/index.js +44 -0
- package/type/transform/transform.d.ts +29 -0
- package/type/transform/transform.js +72 -0
- package/type/tuple/index.d.ts +1 -0
- package/type/tuple/index.js +44 -0
- package/type/tuple/tuple.d.ts +15 -0
- package/type/tuple/tuple.js +42 -0
- package/type/type/index.d.ts +6 -0
- package/type/type/index.js +44 -0
- package/type/type/javascript.d.ts +58 -0
- package/type/type/javascript.js +120 -0
- package/type/type/json.d.ts +139 -0
- package/type/type/json.js +255 -0
- package/type/type/type.d.ts +58 -0
- package/type/type/type.js +153 -0
- package/type/uint8array/index.d.ts +1 -0
- package/type/uint8array/index.js +44 -0
- package/type/uint8array/uint8array.d.ts +13 -0
- package/type/uint8array/uint8array.js +36 -0
- package/type/undefined/index.d.ts +1 -0
- package/type/undefined/index.js +44 -0
- package/type/undefined/undefined.d.ts +9 -0
- package/type/undefined/undefined.js +36 -0
- package/type/union/index.d.ts +1 -0
- package/type/union/index.js +44 -0
- package/type/union/union.d.ts +16 -0
- package/type/union/union.js +50 -0
- package/type/unknown/index.d.ts +1 -0
- package/type/unknown/index.js +44 -0
- package/type/unknown/unknown.d.ts +8 -0
- package/type/unknown/unknown.js +39 -0
- package/type/unsafe/index.d.ts +1 -0
- package/type/unsafe/index.js +44 -0
- package/type/unsafe/unsafe.d.ts +11 -0
- package/type/unsafe/unsafe.js +39 -0
- package/type/void/index.d.ts +1 -0
- package/type/void/index.js +44 -0
- package/type/void/void.d.ts +9 -0
- package/type/void/void.js +40 -0
- package/value/cast/cast.d.ts +23 -0
- package/value/{cast.js → cast/cast.js} +62 -83
- package/value/cast/index.d.ts +1 -0
- package/value/cast/index.js +44 -0
- package/value/check/check.d.ts +10 -0
- package/value/{check.js → check/check.js} +50 -45
- package/value/check/index.d.ts +1 -0
- package/value/check/index.js +44 -0
- package/value/clean/clean.d.ts +5 -0
- package/value/clean/clean.js +167 -0
- package/value/clean/index.d.ts +1 -0
- package/value/clean/index.js +44 -0
- package/value/{clone.js → clone/clone.js} +6 -6
- package/value/clone/index.d.ts +1 -0
- package/value/clone/index.js +44 -0
- package/value/convert/convert.d.ts +9 -0
- package/value/{convert.js → convert/convert.js} +93 -116
- package/value/convert/index.d.ts +1 -0
- package/value/convert/index.js +44 -0
- package/value/create/create.d.ts +31 -0
- package/value/{create.js → create/create.js} +69 -62
- package/value/create/index.d.ts +1 -0
- package/value/create/index.js +44 -0
- package/value/default/default.d.ts +5 -0
- package/value/default/default.js +175 -0
- package/value/default/index.d.ts +1 -0
- package/value/default/index.js +44 -0
- package/value/delta/delta.d.ts +41 -0
- package/value/{delta.js → delta/delta.js} +57 -53
- package/value/delta/index.d.ts +1 -0
- package/value/delta/index.js +44 -0
- package/value/{deref.d.ts → deref/deref.d.ts} +4 -2
- package/value/{deref.js → deref/deref.js} +1 -2
- package/value/deref/index.d.ts +1 -0
- package/value/deref/index.js +44 -0
- package/value/{equal.js → equal/equal.js} +14 -14
- package/value/equal/index.d.ts +1 -0
- package/value/equal/index.js +44 -0
- package/value/guard/index.d.ts +1 -0
- package/value/guard/index.js +44 -0
- package/value/{hash.d.ts → hash/hash.d.ts} +0 -13
- package/value/{hash.js → hash/hash.js} +26 -26
- package/value/hash/index.d.ts +1 -0
- package/value/hash/index.js +44 -0
- package/value/index.d.ts +17 -4
- package/value/index.js +91 -10
- package/value/mutate/index.d.ts +1 -0
- package/value/mutate/index.js +44 -0
- package/value/{mutate.d.ts → mutate/mutate.d.ts} +1 -1
- package/value/{mutate.js → mutate/mutate.js} +25 -25
- package/value/pointer/index.d.ts +1 -0
- package/value/pointer/index.js +31 -0
- package/value/pointer/pointer.d.ts +21 -0
- package/value/pointer/pointer.js +151 -0
- package/value/transform/decode.d.ts +19 -0
- package/value/transform/decode.js +211 -0
- package/value/transform/encode.d.ts +20 -0
- package/value/transform/encode.js +219 -0
- package/value/transform/has.d.ts +3 -0
- package/value/transform/has.js +146 -0
- package/value/transform/index.d.ts +3 -0
- package/value/transform/index.js +46 -0
- package/value/value/index.d.ts +1 -0
- package/value/value/index.js +31 -0
- package/value/value/value.d.ts +53 -0
- package/value/value/value.js +125 -0
- package/typebox.d.ts +0 -962
- package/typebox.js +0 -2364
- package/value/cast.d.ts +0 -24
- package/value/check.d.ts +0 -9
- package/value/convert.d.ts +0 -10
- package/value/create.d.ts +0 -30
- package/value/delta.d.ts +0 -41
- package/value/pointer.d.ts +0 -24
- package/value/pointer.js +0 -148
- package/value/transform.d.ts +0 -37
- package/value/transform.js +0 -473
- package/value/value.d.ts +0 -47
- package/value/value.js +0 -117
- /package/value/{clone.d.ts → clone/clone.d.ts} +0 -0
- /package/value/{equal.d.ts → equal/equal.d.ts} +0 -0
- /package/value/{guard.d.ts → guard/guard.d.ts} +0 -0
- /package/value/{guard.js → guard/guard.js} +0 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/type
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.TSchema = exports.TKind = exports.TVoid = exports.TUnsafe = exports.TUnknown = exports.TUint8Array = exports.TUnion = exports.TUnionLiteral = exports.TUndefined = exports.TTuple = exports.TTransform = exports.TThis = exports.TTemplateLiteral = exports.TSymbol = exports.TString = exports.TRef = exports.TRecursive = exports.TRecord = exports.TPromise = exports.TObject = exports.TNumber = exports.TNull = exports.TNot = exports.TNever = exports.TLiteral = exports.TLiteralBoolean = exports.TLiteralNumber = exports.TLiteralString = exports.TKindOf = exports.TIterator = exports.TIntersect = exports.TInteger = exports.TFunction = exports.TDate = exports.TConstructor = exports.TBoolean = exports.TBigInt = exports.TAsyncIterator = exports.TArray = exports.TAny = exports.TOptional = exports.TReadonly = exports.TypeGuardUnknownTypeError = void 0;
|
|
31
|
+
const ValueGuard = require("./value");
|
|
32
|
+
const index_1 = require("../symbols/index");
|
|
33
|
+
class TypeGuardUnknownTypeError extends Error {
|
|
34
|
+
}
|
|
35
|
+
exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
|
|
36
|
+
const KnownTypes = [
|
|
37
|
+
'Any',
|
|
38
|
+
'Array',
|
|
39
|
+
'AsyncIterator',
|
|
40
|
+
'BigInt',
|
|
41
|
+
'Boolean',
|
|
42
|
+
'Constructor',
|
|
43
|
+
'Date',
|
|
44
|
+
'Enum',
|
|
45
|
+
'Function',
|
|
46
|
+
'Integer',
|
|
47
|
+
'Intersect',
|
|
48
|
+
'Iterator',
|
|
49
|
+
'Literal',
|
|
50
|
+
'Not',
|
|
51
|
+
'Null',
|
|
52
|
+
'Number',
|
|
53
|
+
'Object',
|
|
54
|
+
'Promise',
|
|
55
|
+
'Record',
|
|
56
|
+
'Ref',
|
|
57
|
+
'String',
|
|
58
|
+
'Symbol',
|
|
59
|
+
'TemplateLiteral',
|
|
60
|
+
'This',
|
|
61
|
+
'Tuple',
|
|
62
|
+
'Undefined',
|
|
63
|
+
'Union',
|
|
64
|
+
'Uint8Array',
|
|
65
|
+
'Unknown',
|
|
66
|
+
'Void',
|
|
67
|
+
];
|
|
68
|
+
function IsPattern(value) {
|
|
69
|
+
try {
|
|
70
|
+
new RegExp(value);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function IsControlCharacterFree(value) {
|
|
78
|
+
if (!ValueGuard.IsString(value))
|
|
79
|
+
return false;
|
|
80
|
+
for (let i = 0; i < value.length; i++) {
|
|
81
|
+
const code = value.charCodeAt(i);
|
|
82
|
+
if ((code >= 7 && code <= 13) || code === 27 || code === 127) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
function IsAdditionalProperties(value) {
|
|
89
|
+
return IsOptionalBoolean(value) || (0, index_2.TSchema)(value);
|
|
90
|
+
}
|
|
91
|
+
function IsOptionalBigInt(value) {
|
|
92
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsBigInt(value);
|
|
93
|
+
}
|
|
94
|
+
function IsOptionalNumber(value) {
|
|
95
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsNumber(value);
|
|
96
|
+
}
|
|
97
|
+
function IsOptionalBoolean(value) {
|
|
98
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsBoolean(value);
|
|
99
|
+
}
|
|
100
|
+
function IsOptionalString(value) {
|
|
101
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsString(value);
|
|
102
|
+
}
|
|
103
|
+
function IsOptionalPattern(value) {
|
|
104
|
+
return ValueGuard.IsUndefined(value) || (ValueGuard.IsString(value) && IsControlCharacterFree(value) && IsPattern(value));
|
|
105
|
+
}
|
|
106
|
+
function IsOptionalFormat(value) {
|
|
107
|
+
return ValueGuard.IsUndefined(value) || (ValueGuard.IsString(value) && IsControlCharacterFree(value));
|
|
108
|
+
}
|
|
109
|
+
function IsOptionalSchema(value) {
|
|
110
|
+
return ValueGuard.IsUndefined(value) || (0, index_2.TSchema)(value);
|
|
111
|
+
}
|
|
112
|
+
// ------------------------------------------------------------------
|
|
113
|
+
// Modifiers
|
|
114
|
+
// ------------------------------------------------------------------
|
|
115
|
+
/** Returns true if this value has a Readonly symbol */
|
|
116
|
+
function TReadonly(schema) {
|
|
117
|
+
return ValueGuard.IsObject(schema) && schema[index_1.ReadonlyKind] === 'Readonly';
|
|
118
|
+
}
|
|
119
|
+
exports.TReadonly = TReadonly;
|
|
120
|
+
/** Returns true if this value has a Optional symbol */
|
|
121
|
+
function TOptional(schema) {
|
|
122
|
+
return ValueGuard.IsObject(schema) && schema[index_1.OptionalKind] === 'Optional';
|
|
123
|
+
}
|
|
124
|
+
exports.TOptional = TOptional;
|
|
125
|
+
// ------------------------------------------------------------------
|
|
126
|
+
// Types
|
|
127
|
+
// ------------------------------------------------------------------
|
|
128
|
+
/** Returns true if the given value is TAny */
|
|
129
|
+
function TAny(schema) {
|
|
130
|
+
// prettier-ignore
|
|
131
|
+
return (TKindOf(schema, 'Any') &&
|
|
132
|
+
IsOptionalString(schema.$id));
|
|
133
|
+
}
|
|
134
|
+
exports.TAny = TAny;
|
|
135
|
+
/** Returns true if the given value is TArray */
|
|
136
|
+
function TArray(schema) {
|
|
137
|
+
return (TKindOf(schema, 'Array') &&
|
|
138
|
+
schema.type === 'array' &&
|
|
139
|
+
IsOptionalString(schema.$id) &&
|
|
140
|
+
(0, index_2.TSchema)(schema.items) &&
|
|
141
|
+
IsOptionalNumber(schema.minItems) &&
|
|
142
|
+
IsOptionalNumber(schema.maxItems) &&
|
|
143
|
+
IsOptionalBoolean(schema.uniqueItems) &&
|
|
144
|
+
IsOptionalSchema(schema.contains) &&
|
|
145
|
+
IsOptionalNumber(schema.minContains) &&
|
|
146
|
+
IsOptionalNumber(schema.maxContains));
|
|
147
|
+
}
|
|
148
|
+
exports.TArray = TArray;
|
|
149
|
+
/** Returns true if the given value is TAsyncIterator */
|
|
150
|
+
function TAsyncIterator(schema) {
|
|
151
|
+
// prettier-ignore
|
|
152
|
+
return (TKindOf(schema, 'AsyncIterator') &&
|
|
153
|
+
schema.type === 'AsyncIterator' &&
|
|
154
|
+
IsOptionalString(schema.$id) &&
|
|
155
|
+
(0, index_2.TSchema)(schema.items));
|
|
156
|
+
}
|
|
157
|
+
exports.TAsyncIterator = TAsyncIterator;
|
|
158
|
+
/** Returns true if the given value is TBigInt */
|
|
159
|
+
function TBigInt(schema) {
|
|
160
|
+
// prettier-ignore
|
|
161
|
+
return (TKindOf(schema, 'BigInt') &&
|
|
162
|
+
schema.type === 'bigint' &&
|
|
163
|
+
IsOptionalString(schema.$id) &&
|
|
164
|
+
IsOptionalBigInt(schema.exclusiveMaximum) &&
|
|
165
|
+
IsOptionalBigInt(schema.exclusiveMinimum) &&
|
|
166
|
+
IsOptionalBigInt(schema.maximum) &&
|
|
167
|
+
IsOptionalBigInt(schema.minimum) &&
|
|
168
|
+
IsOptionalBigInt(schema.multipleOf));
|
|
169
|
+
}
|
|
170
|
+
exports.TBigInt = TBigInt;
|
|
171
|
+
/** Returns true if the given value is TBoolean */
|
|
172
|
+
function TBoolean(schema) {
|
|
173
|
+
// prettier-ignore
|
|
174
|
+
return (TKindOf(schema, 'Boolean') &&
|
|
175
|
+
schema.type === 'boolean' &&
|
|
176
|
+
IsOptionalString(schema.$id));
|
|
177
|
+
}
|
|
178
|
+
exports.TBoolean = TBoolean;
|
|
179
|
+
/** Returns true if the given value is TConstructor */
|
|
180
|
+
function TConstructor(schema) {
|
|
181
|
+
// prettier-ignore
|
|
182
|
+
return (TKindOf(schema, 'Constructor') &&
|
|
183
|
+
schema.type === 'Constructor' &&
|
|
184
|
+
IsOptionalString(schema.$id) &&
|
|
185
|
+
ValueGuard.IsArray(schema.parameters) &&
|
|
186
|
+
schema.parameters.every(schema => (0, index_2.TSchema)(schema)) &&
|
|
187
|
+
(0, index_2.TSchema)(schema.returns));
|
|
188
|
+
}
|
|
189
|
+
exports.TConstructor = TConstructor;
|
|
190
|
+
/** Returns true if the given value is TDate */
|
|
191
|
+
function TDate(schema) {
|
|
192
|
+
return (TKindOf(schema, 'Date') &&
|
|
193
|
+
schema.type === 'Date' &&
|
|
194
|
+
IsOptionalString(schema.$id) &&
|
|
195
|
+
IsOptionalNumber(schema.exclusiveMaximumTimestamp) &&
|
|
196
|
+
IsOptionalNumber(schema.exclusiveMinimumTimestamp) &&
|
|
197
|
+
IsOptionalNumber(schema.maximumTimestamp) &&
|
|
198
|
+
IsOptionalNumber(schema.minimumTimestamp) &&
|
|
199
|
+
IsOptionalNumber(schema.multipleOfTimestamp));
|
|
200
|
+
}
|
|
201
|
+
exports.TDate = TDate;
|
|
202
|
+
/** Returns true if the given value is TFunction */
|
|
203
|
+
function TFunction(schema) {
|
|
204
|
+
// prettier-ignore
|
|
205
|
+
return (TKindOf(schema, 'Function') &&
|
|
206
|
+
schema.type === 'Function' &&
|
|
207
|
+
IsOptionalString(schema.$id) &&
|
|
208
|
+
ValueGuard.IsArray(schema.parameters) &&
|
|
209
|
+
schema.parameters.every(schema => (0, index_2.TSchema)(schema)) &&
|
|
210
|
+
(0, index_2.TSchema)(schema.returns));
|
|
211
|
+
}
|
|
212
|
+
exports.TFunction = TFunction;
|
|
213
|
+
/** Returns true if the given value is TInteger */
|
|
214
|
+
function TInteger(schema) {
|
|
215
|
+
return (TKindOf(schema, 'Integer') &&
|
|
216
|
+
schema.type === 'integer' &&
|
|
217
|
+
IsOptionalString(schema.$id) &&
|
|
218
|
+
IsOptionalNumber(schema.exclusiveMaximum) &&
|
|
219
|
+
IsOptionalNumber(schema.exclusiveMinimum) &&
|
|
220
|
+
IsOptionalNumber(schema.maximum) &&
|
|
221
|
+
IsOptionalNumber(schema.minimum) &&
|
|
222
|
+
IsOptionalNumber(schema.multipleOf));
|
|
223
|
+
}
|
|
224
|
+
exports.TInteger = TInteger;
|
|
225
|
+
/** Returns true if the given value is TIntersect */
|
|
226
|
+
function TIntersect(schema) {
|
|
227
|
+
// prettier-ignore
|
|
228
|
+
return (TKindOf(schema, 'Intersect') &&
|
|
229
|
+
(ValueGuard.IsString(schema.type) && schema.type !== 'object' ? false : true) &&
|
|
230
|
+
ValueGuard.IsArray(schema.allOf) &&
|
|
231
|
+
schema.allOf.every(schema => (0, index_2.TSchema)(schema) && !TTransform(schema)) &&
|
|
232
|
+
IsOptionalString(schema.type) &&
|
|
233
|
+
(IsOptionalBoolean(schema.unevaluatedProperties) || IsOptionalSchema(schema.unevaluatedProperties)) &&
|
|
234
|
+
IsOptionalString(schema.$id));
|
|
235
|
+
}
|
|
236
|
+
exports.TIntersect = TIntersect;
|
|
237
|
+
/** Returns true if the given value is TIterator */
|
|
238
|
+
function TIterator(schema) {
|
|
239
|
+
// prettier-ignore
|
|
240
|
+
return (TKindOf(schema, 'Iterator') &&
|
|
241
|
+
schema.type === 'Iterator' &&
|
|
242
|
+
IsOptionalString(schema.$id) &&
|
|
243
|
+
(0, index_2.TSchema)(schema.items));
|
|
244
|
+
}
|
|
245
|
+
exports.TIterator = TIterator;
|
|
246
|
+
/** Returns true if the given value is a TKind with the given name. */
|
|
247
|
+
function TKindOf(schema, kind) {
|
|
248
|
+
return ValueGuard.IsObject(schema) && index_1.Kind in schema && schema[index_1.Kind] === kind;
|
|
249
|
+
}
|
|
250
|
+
exports.TKindOf = TKindOf;
|
|
251
|
+
/** Returns true if the given value is TLiteral<string> */
|
|
252
|
+
function TLiteralString(schema) {
|
|
253
|
+
return (0, index_3.TLiteral)(schema) && ValueGuard.IsString(schema.const);
|
|
254
|
+
}
|
|
255
|
+
exports.TLiteralString = TLiteralString;
|
|
256
|
+
/** Returns true if the given value is TLiteral<number> */
|
|
257
|
+
function TLiteralNumber(schema) {
|
|
258
|
+
return (0, index_3.TLiteral)(schema) && ValueGuard.IsNumber(schema.const);
|
|
259
|
+
}
|
|
260
|
+
exports.TLiteralNumber = TLiteralNumber;
|
|
261
|
+
/** Returns true if the given value is TLiteral<boolean> */
|
|
262
|
+
function TLiteralBoolean(schema) {
|
|
263
|
+
return (0, index_3.TLiteral)(schema) && ValueGuard.IsBoolean(schema.const);
|
|
264
|
+
}
|
|
265
|
+
exports.TLiteralBoolean = TLiteralBoolean;
|
|
266
|
+
/** Returns true if the given value is TLiteral */
|
|
267
|
+
function TLiteral(schema) {
|
|
268
|
+
// prettier-ignore
|
|
269
|
+
return (TKindOf(schema, 'Literal') &&
|
|
270
|
+
IsOptionalString(schema.$id) && (ValueGuard.IsBoolean(schema.const) ||
|
|
271
|
+
ValueGuard.IsNumber(schema.const) ||
|
|
272
|
+
ValueGuard.IsString(schema.const)));
|
|
273
|
+
}
|
|
274
|
+
exports.TLiteral = TLiteral;
|
|
275
|
+
/** Returns true if the given value is TNever */
|
|
276
|
+
function TNever(schema) {
|
|
277
|
+
// prettier-ignore
|
|
278
|
+
return (TKindOf(schema, 'Never') &&
|
|
279
|
+
ValueGuard.IsObject(schema.not) &&
|
|
280
|
+
Object.getOwnPropertyNames(schema.not).length === 0);
|
|
281
|
+
}
|
|
282
|
+
exports.TNever = TNever;
|
|
283
|
+
/** Returns true if the given value is TNot */
|
|
284
|
+
function TNot(schema) {
|
|
285
|
+
// prettier-ignore
|
|
286
|
+
return (TKindOf(schema, 'Not') &&
|
|
287
|
+
(0, index_2.TSchema)(schema.not));
|
|
288
|
+
}
|
|
289
|
+
exports.TNot = TNot;
|
|
290
|
+
/** Returns true if the given value is TNull */
|
|
291
|
+
function TNull(schema) {
|
|
292
|
+
// prettier-ignore
|
|
293
|
+
return (TKindOf(schema, 'Null') &&
|
|
294
|
+
schema.type === 'null' &&
|
|
295
|
+
IsOptionalString(schema.$id));
|
|
296
|
+
}
|
|
297
|
+
exports.TNull = TNull;
|
|
298
|
+
/** Returns true if the given value is TNumber */
|
|
299
|
+
function TNumber(schema) {
|
|
300
|
+
return (TKindOf(schema, 'Number') &&
|
|
301
|
+
schema.type === 'number' &&
|
|
302
|
+
IsOptionalString(schema.$id) &&
|
|
303
|
+
IsOptionalNumber(schema.exclusiveMaximum) &&
|
|
304
|
+
IsOptionalNumber(schema.exclusiveMinimum) &&
|
|
305
|
+
IsOptionalNumber(schema.maximum) &&
|
|
306
|
+
IsOptionalNumber(schema.minimum) &&
|
|
307
|
+
IsOptionalNumber(schema.multipleOf));
|
|
308
|
+
}
|
|
309
|
+
exports.TNumber = TNumber;
|
|
310
|
+
/** Returns true if the given value is TObject */
|
|
311
|
+
function TObject(schema) {
|
|
312
|
+
// prettier-ignore
|
|
313
|
+
return (TKindOf(schema, 'Object') &&
|
|
314
|
+
schema.type === 'object' &&
|
|
315
|
+
IsOptionalString(schema.$id) &&
|
|
316
|
+
ValueGuard.IsObject(schema.properties) &&
|
|
317
|
+
Object.entries(schema.properties).every(([key, schema]) => IsControlCharacterFree(key) && (0, index_2.TSchema)(schema)) &&
|
|
318
|
+
IsAdditionalProperties(schema.additionalProperties) &&
|
|
319
|
+
IsOptionalNumber(schema.minProperties) &&
|
|
320
|
+
IsOptionalNumber(schema.maxProperties));
|
|
321
|
+
}
|
|
322
|
+
exports.TObject = TObject;
|
|
323
|
+
/** Returns true if the given value is TPromise */
|
|
324
|
+
function TPromise(schema) {
|
|
325
|
+
// prettier-ignore
|
|
326
|
+
return (TKindOf(schema, 'Promise') &&
|
|
327
|
+
schema.type === 'Promise' &&
|
|
328
|
+
IsOptionalString(schema.$id) &&
|
|
329
|
+
(0, index_2.TSchema)(schema.item));
|
|
330
|
+
}
|
|
331
|
+
exports.TPromise = TPromise;
|
|
332
|
+
/** Returns true if the given value is TRecord */
|
|
333
|
+
function TRecord(schema) {
|
|
334
|
+
// prettier-ignore
|
|
335
|
+
return (TKindOf(schema, 'Record') &&
|
|
336
|
+
schema.type === 'object' &&
|
|
337
|
+
IsOptionalString(schema.$id) &&
|
|
338
|
+
IsAdditionalProperties(schema.additionalProperties) &&
|
|
339
|
+
ValueGuard.IsObject(schema.patternProperties) &&
|
|
340
|
+
((schema) => {
|
|
341
|
+
const keys = Object.getOwnPropertyNames(schema.patternProperties);
|
|
342
|
+
return (keys.length === 1 &&
|
|
343
|
+
IsPattern(keys[0]) &&
|
|
344
|
+
ValueGuard.IsObject(schema.patternProperties) &&
|
|
345
|
+
(0, index_2.TSchema)(schema.patternProperties[keys[0]]));
|
|
346
|
+
})(schema));
|
|
347
|
+
}
|
|
348
|
+
exports.TRecord = TRecord;
|
|
349
|
+
/** Returns true if this value is TRecursive */
|
|
350
|
+
function TRecursive(schema) {
|
|
351
|
+
return ValueGuard.IsObject(schema) && index_1.Hint in schema && schema[index_1.Hint] === 'Recursive';
|
|
352
|
+
}
|
|
353
|
+
exports.TRecursive = TRecursive;
|
|
354
|
+
/** Returns true if the given value is TRef */
|
|
355
|
+
function TRef(schema) {
|
|
356
|
+
// prettier-ignore
|
|
357
|
+
return (TKindOf(schema, 'Ref') &&
|
|
358
|
+
IsOptionalString(schema.$id) &&
|
|
359
|
+
ValueGuard.IsString(schema.$ref));
|
|
360
|
+
}
|
|
361
|
+
exports.TRef = TRef;
|
|
362
|
+
/** Returns true if the given value is TString */
|
|
363
|
+
function TString(schema) {
|
|
364
|
+
// prettier-ignore
|
|
365
|
+
return (TKindOf(schema, 'String') &&
|
|
366
|
+
schema.type === 'string' &&
|
|
367
|
+
IsOptionalString(schema.$id) &&
|
|
368
|
+
IsOptionalNumber(schema.minLength) &&
|
|
369
|
+
IsOptionalNumber(schema.maxLength) &&
|
|
370
|
+
IsOptionalPattern(schema.pattern) &&
|
|
371
|
+
IsOptionalFormat(schema.format));
|
|
372
|
+
}
|
|
373
|
+
exports.TString = TString;
|
|
374
|
+
/** Returns true if the given value is TSymbol */
|
|
375
|
+
function TSymbol(schema) {
|
|
376
|
+
// prettier-ignore
|
|
377
|
+
return (TKindOf(schema, 'Symbol') &&
|
|
378
|
+
schema.type === 'symbol' &&
|
|
379
|
+
IsOptionalString(schema.$id));
|
|
380
|
+
}
|
|
381
|
+
exports.TSymbol = TSymbol;
|
|
382
|
+
/** Returns true if the given value is TTemplateLiteral */
|
|
383
|
+
function TTemplateLiteral(schema) {
|
|
384
|
+
// prettier-ignore
|
|
385
|
+
return (TKindOf(schema, 'TemplateLiteral') &&
|
|
386
|
+
schema.type === 'string' &&
|
|
387
|
+
ValueGuard.IsString(schema.pattern) &&
|
|
388
|
+
schema.pattern[0] === '^' &&
|
|
389
|
+
schema.pattern[schema.pattern.length - 1] === '$');
|
|
390
|
+
}
|
|
391
|
+
exports.TTemplateLiteral = TTemplateLiteral;
|
|
392
|
+
/** Returns true if the given value is TThis */
|
|
393
|
+
function TThis(schema) {
|
|
394
|
+
// prettier-ignore
|
|
395
|
+
return (TKindOf(schema, 'This') &&
|
|
396
|
+
IsOptionalString(schema.$id) &&
|
|
397
|
+
ValueGuard.IsString(schema.$ref));
|
|
398
|
+
}
|
|
399
|
+
exports.TThis = TThis;
|
|
400
|
+
/** Returns true of this value is TTransform */
|
|
401
|
+
function TTransform(schema) {
|
|
402
|
+
return ValueGuard.IsObject(schema) && index_1.TransformKind in schema;
|
|
403
|
+
}
|
|
404
|
+
exports.TTransform = TTransform;
|
|
405
|
+
/** Returns true if the given value is TTuple */
|
|
406
|
+
function TTuple(schema) {
|
|
407
|
+
// prettier-ignore
|
|
408
|
+
return (TKindOf(schema, 'Tuple') &&
|
|
409
|
+
schema.type === 'array' &&
|
|
410
|
+
IsOptionalString(schema.$id) &&
|
|
411
|
+
ValueGuard.IsNumber(schema.minItems) &&
|
|
412
|
+
ValueGuard.IsNumber(schema.maxItems) &&
|
|
413
|
+
schema.minItems === schema.maxItems &&
|
|
414
|
+
(( // empty
|
|
415
|
+
ValueGuard.IsUndefined(schema.items) &&
|
|
416
|
+
ValueGuard.IsUndefined(schema.additionalItems) &&
|
|
417
|
+
schema.minItems === 0) || (ValueGuard.IsArray(schema.items) &&
|
|
418
|
+
schema.items.every(schema => (0, index_2.TSchema)(schema)))));
|
|
419
|
+
}
|
|
420
|
+
exports.TTuple = TTuple;
|
|
421
|
+
/** Returns true if the given value is TUndefined */
|
|
422
|
+
function TUndefined(schema) {
|
|
423
|
+
// prettier-ignore
|
|
424
|
+
return (TKindOf(schema, 'Undefined') &&
|
|
425
|
+
schema.type === 'undefined' &&
|
|
426
|
+
IsOptionalString(schema.$id));
|
|
427
|
+
}
|
|
428
|
+
exports.TUndefined = TUndefined;
|
|
429
|
+
/** Returns true if the given value is TUnion<Literal<string | number>[]> */
|
|
430
|
+
function TUnionLiteral(schema) {
|
|
431
|
+
return (0, index_4.TUnion)(schema) && schema.anyOf.every((schema) => TLiteralString(schema) || TLiteralNumber(schema));
|
|
432
|
+
}
|
|
433
|
+
exports.TUnionLiteral = TUnionLiteral;
|
|
434
|
+
/** Returns true if the given value is TUnion */
|
|
435
|
+
function TUnion(schema) {
|
|
436
|
+
// prettier-ignore
|
|
437
|
+
return (TKindOf(schema, 'Union') &&
|
|
438
|
+
IsOptionalString(schema.$id) &&
|
|
439
|
+
ValueGuard.IsObject(schema) &&
|
|
440
|
+
ValueGuard.IsArray(schema.anyOf) &&
|
|
441
|
+
schema.anyOf.every(schema => (0, index_2.TSchema)(schema)));
|
|
442
|
+
}
|
|
443
|
+
exports.TUnion = TUnion;
|
|
444
|
+
/** Returns true if the given value is TUint8Array */
|
|
445
|
+
function TUint8Array(schema) {
|
|
446
|
+
// prettier-ignore
|
|
447
|
+
return (TKindOf(schema, 'Uint8Array') &&
|
|
448
|
+
schema.type === 'Uint8Array' &&
|
|
449
|
+
IsOptionalString(schema.$id) &&
|
|
450
|
+
IsOptionalNumber(schema.minByteLength) &&
|
|
451
|
+
IsOptionalNumber(schema.maxByteLength));
|
|
452
|
+
}
|
|
453
|
+
exports.TUint8Array = TUint8Array;
|
|
454
|
+
/** Returns true if the given value is TUnknown */
|
|
455
|
+
function TUnknown(schema) {
|
|
456
|
+
// prettier-ignore
|
|
457
|
+
return (TKindOf(schema, 'Unknown') &&
|
|
458
|
+
IsOptionalString(schema.$id));
|
|
459
|
+
}
|
|
460
|
+
exports.TUnknown = TUnknown;
|
|
461
|
+
/** Returns true if the given value is a raw TUnsafe */
|
|
462
|
+
function TUnsafe(schema) {
|
|
463
|
+
return TKindOf(schema, 'Unsafe');
|
|
464
|
+
}
|
|
465
|
+
exports.TUnsafe = TUnsafe;
|
|
466
|
+
/** Returns true if the given value is TVoid */
|
|
467
|
+
function TVoid(schema) {
|
|
468
|
+
// prettier-ignore
|
|
469
|
+
return (TKindOf(schema, 'Void') &&
|
|
470
|
+
schema.type === 'void' &&
|
|
471
|
+
IsOptionalString(schema.$id));
|
|
472
|
+
}
|
|
473
|
+
exports.TVoid = TVoid;
|
|
474
|
+
/** Returns true if the given value is TKind */
|
|
475
|
+
function TKind(schema) {
|
|
476
|
+
return ValueGuard.IsObject(schema) && index_1.Kind in schema && ValueGuard.IsString(schema[index_1.Kind]) && !KnownTypes.includes(schema[index_1.Kind]);
|
|
477
|
+
}
|
|
478
|
+
exports.TKind = TKind;
|
|
479
|
+
/** Returns true if the given value is TSchema */
|
|
480
|
+
function TSchema(schema) {
|
|
481
|
+
// prettier-ignore
|
|
482
|
+
return (ValueGuard.IsObject(schema)) && ((0, index_5.TAny)(schema) ||
|
|
483
|
+
(0, index_6.TArray)(schema) ||
|
|
484
|
+
(0, index_7.TBoolean)(schema) ||
|
|
485
|
+
(0, index_8.TBigInt)(schema) ||
|
|
486
|
+
(0, index_9.TAsyncIterator)(schema) ||
|
|
487
|
+
(0, index_10.TConstructor)(schema) ||
|
|
488
|
+
(0, index_11.TDate)(schema) ||
|
|
489
|
+
(0, index_12.TFunction)(schema) ||
|
|
490
|
+
(0, index_13.TInteger)(schema) ||
|
|
491
|
+
(0, index_14.TIntersect)(schema) ||
|
|
492
|
+
(0, index_15.TIterator)(schema) ||
|
|
493
|
+
(0, index_3.TLiteral)(schema) ||
|
|
494
|
+
(0, index_16.TNever)(schema) ||
|
|
495
|
+
(0, index_17.TNot)(schema) ||
|
|
496
|
+
(0, index_18.TNull)(schema) ||
|
|
497
|
+
(0, index_19.TNumber)(schema) ||
|
|
498
|
+
(0, index_20.TObject)(schema) ||
|
|
499
|
+
(0, index_21.TPromise)(schema) ||
|
|
500
|
+
(0, index_22.TRecord)(schema) ||
|
|
501
|
+
(0, index_23.TRef)(schema) ||
|
|
502
|
+
(0, index_24.TString)(schema) ||
|
|
503
|
+
(0, index_25.TSymbol)(schema) ||
|
|
504
|
+
(0, index_26.TTemplateLiteral)(schema) ||
|
|
505
|
+
(0, index_27.TThis)(schema) ||
|
|
506
|
+
(0, index_28.TTuple)(schema) ||
|
|
507
|
+
(0, index_29.TUndefined)(schema) ||
|
|
508
|
+
(0, index_4.TUnion)(schema) ||
|
|
509
|
+
(0, index_30.TUint8Array)(schema) ||
|
|
510
|
+
(0, index_31.TUnknown)(schema) ||
|
|
511
|
+
(0, index_32.TUnsafe)(schema) ||
|
|
512
|
+
(0, index_33.TVoid)(schema) ||
|
|
513
|
+
TKind(schema));
|
|
514
|
+
}
|
|
515
|
+
exports.TSchema = TSchema;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Returns true if this value is an async iterator */
|
|
2
|
+
export declare function IsAsyncIterator(value: unknown): value is AsyncIterableIterator<unknown>;
|
|
3
|
+
/** Returns true if this value is an array */
|
|
4
|
+
export declare function IsArray(value: unknown): value is unknown[];
|
|
5
|
+
/** Returns true if this value is bigint */
|
|
6
|
+
export declare function IsBigInt(value: unknown): value is bigint;
|
|
7
|
+
/** Returns true if this value is a boolean */
|
|
8
|
+
export declare function IsBoolean(value: unknown): value is boolean;
|
|
9
|
+
/** Returns true if this value is a Date object */
|
|
10
|
+
export declare function IsDate(value: unknown): value is Date;
|
|
11
|
+
/** Returns true if this value is a function */
|
|
12
|
+
export declare function IsFunction(value: unknown): value is Function;
|
|
13
|
+
/** Returns true if this value is an iterator */
|
|
14
|
+
export declare function IsIterator(value: unknown): value is IterableIterator<unknown>;
|
|
15
|
+
/** Returns true if this value is null */
|
|
16
|
+
export declare function IsNull(value: unknown): value is null;
|
|
17
|
+
/** Returns true if this value is number */
|
|
18
|
+
export declare function IsNumber(value: unknown): value is number;
|
|
19
|
+
/** Returns true if this value is an object */
|
|
20
|
+
export declare function IsObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
21
|
+
/** Returns true if this value is string */
|
|
22
|
+
export declare function IsString(value: unknown): value is string;
|
|
23
|
+
/** Returns true if this value is symbol */
|
|
24
|
+
export declare function IsSymbol(value: unknown): value is symbol;
|
|
25
|
+
/** Returns true if this value is a Uint8Array */
|
|
26
|
+
export declare function IsUint8Array(value: unknown): value is Uint8Array;
|
|
27
|
+
/** Returns true if this value is undefined */
|
|
28
|
+
export declare function IsUndefined(value: unknown): value is undefined;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/type
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.IsUndefined = exports.IsUint8Array = exports.IsSymbol = exports.IsString = exports.IsObject = exports.IsNumber = exports.IsNull = exports.IsIterator = exports.IsFunction = exports.IsDate = exports.IsBoolean = exports.IsBigInt = exports.IsArray = exports.IsAsyncIterator = void 0;
|
|
31
|
+
/** Returns true if this value is an async iterator */
|
|
32
|
+
function IsAsyncIterator(value) {
|
|
33
|
+
return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.asyncIterator in value;
|
|
34
|
+
}
|
|
35
|
+
exports.IsAsyncIterator = IsAsyncIterator;
|
|
36
|
+
/** Returns true if this value is an array */
|
|
37
|
+
function IsArray(value) {
|
|
38
|
+
return Array.isArray(value);
|
|
39
|
+
}
|
|
40
|
+
exports.IsArray = IsArray;
|
|
41
|
+
/** Returns true if this value is bigint */
|
|
42
|
+
function IsBigInt(value) {
|
|
43
|
+
return typeof value === 'bigint';
|
|
44
|
+
}
|
|
45
|
+
exports.IsBigInt = IsBigInt;
|
|
46
|
+
/** Returns true if this value is a boolean */
|
|
47
|
+
function IsBoolean(value) {
|
|
48
|
+
return typeof value === 'boolean';
|
|
49
|
+
}
|
|
50
|
+
exports.IsBoolean = IsBoolean;
|
|
51
|
+
/** Returns true if this value is a Date object */
|
|
52
|
+
function IsDate(value) {
|
|
53
|
+
return value instanceof globalThis.Date;
|
|
54
|
+
}
|
|
55
|
+
exports.IsDate = IsDate;
|
|
56
|
+
/** Returns true if this value is a function */
|
|
57
|
+
function IsFunction(value) {
|
|
58
|
+
return typeof value === 'function';
|
|
59
|
+
}
|
|
60
|
+
exports.IsFunction = IsFunction;
|
|
61
|
+
/** Returns true if this value is an iterator */
|
|
62
|
+
function IsIterator(value) {
|
|
63
|
+
return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.iterator in value;
|
|
64
|
+
}
|
|
65
|
+
exports.IsIterator = IsIterator;
|
|
66
|
+
/** Returns true if this value is null */
|
|
67
|
+
function IsNull(value) {
|
|
68
|
+
return value === null;
|
|
69
|
+
}
|
|
70
|
+
exports.IsNull = IsNull;
|
|
71
|
+
/** Returns true if this value is number */
|
|
72
|
+
function IsNumber(value) {
|
|
73
|
+
return typeof value === 'number';
|
|
74
|
+
}
|
|
75
|
+
exports.IsNumber = IsNumber;
|
|
76
|
+
/** Returns true if this value is an object */
|
|
77
|
+
function IsObject(value) {
|
|
78
|
+
return typeof value === 'object' && value !== null;
|
|
79
|
+
}
|
|
80
|
+
exports.IsObject = IsObject;
|
|
81
|
+
/** Returns true if this value is string */
|
|
82
|
+
function IsString(value) {
|
|
83
|
+
return typeof value === 'string';
|
|
84
|
+
}
|
|
85
|
+
exports.IsString = IsString;
|
|
86
|
+
/** Returns true if this value is symbol */
|
|
87
|
+
function IsSymbol(value) {
|
|
88
|
+
return typeof value === 'symbol';
|
|
89
|
+
}
|
|
90
|
+
exports.IsSymbol = IsSymbol;
|
|
91
|
+
/** Returns true if this value is a Uint8Array */
|
|
92
|
+
function IsUint8Array(value) {
|
|
93
|
+
return value instanceof globalThis.Uint8Array;
|
|
94
|
+
}
|
|
95
|
+
exports.IsUint8Array = IsUint8Array;
|
|
96
|
+
/** Returns true if this value is undefined */
|
|
97
|
+
function IsUndefined(value) {
|
|
98
|
+
return value === undefined;
|
|
99
|
+
}
|
|
100
|
+
exports.IsUndefined = IsUndefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { TSchema } from '../schema/index';
|
|
2
|
+
import type { TProperties } from '../object/index';
|
|
3
|
+
import type { TNever } from '../never/index';
|
|
4
|
+
export type TupleToIntersect<T extends any[]> = T extends [infer I] ? I : T extends [infer I, ...infer R] ? I & TupleToIntersect<R> : never;
|
|
5
|
+
export type TupleToUnion<T extends any[]> = {
|
|
6
|
+
[K in keyof T]: T[K];
|
|
7
|
+
}[number];
|
|
8
|
+
export type UnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
|
|
9
|
+
export type UnionLast<U> = UnionToIntersect<U extends unknown ? (x: U) => 0 : never> extends (x: infer L) => 0 ? L : never;
|
|
10
|
+
export type UnionToTuple<U, L = UnionLast<U>> = [U] extends [never] ? [] : [...UnionToTuple<Exclude<U, L>>, L];
|
|
11
|
+
export type Trim<T> = T extends `${' '}${infer U}` ? Trim<U> : T extends `${infer U}${' '}` ? Trim<U> : T;
|
|
12
|
+
export type Assert<T, E> = T extends E ? T : never;
|
|
13
|
+
export type Evaluate<T> = T extends infer O ? {
|
|
14
|
+
[K in keyof O]: O[K];
|
|
15
|
+
} : never;
|
|
16
|
+
export type Ensure<T> = T extends infer U ? U : never;
|
|
17
|
+
export type EmptyString = '';
|
|
18
|
+
export type ZeroString = '0';
|
|
19
|
+
type IncrementBase = {
|
|
20
|
+
m: '9';
|
|
21
|
+
t: '01';
|
|
22
|
+
'0': '1';
|
|
23
|
+
'1': '2';
|
|
24
|
+
'2': '3';
|
|
25
|
+
'3': '4';
|
|
26
|
+
'4': '5';
|
|
27
|
+
'5': '6';
|
|
28
|
+
'6': '7';
|
|
29
|
+
'7': '8';
|
|
30
|
+
'8': '9';
|
|
31
|
+
'9': '0';
|
|
32
|
+
};
|
|
33
|
+
type IncrementTake<T extends keyof IncrementBase> = IncrementBase[T];
|
|
34
|
+
type IncrementStep<T extends string> = T extends IncrementBase['m'] ? IncrementBase['t'] : T extends `${infer L extends keyof IncrementBase}${infer R}` ? L extends IncrementBase['m'] ? `${IncrementTake<L>}${IncrementStep<R>}` : `${IncrementTake<L>}${R}` : never;
|
|
35
|
+
type IncrementReverse<T extends string> = T extends `${infer L}${infer R}` ? `${IncrementReverse<R>}${L}` : T;
|
|
36
|
+
export type Increment<T extends string> = IncrementReverse<IncrementStep<IncrementReverse<T>>>;
|
|
37
|
+
/** Increments the given string value + 1 */
|
|
38
|
+
export declare function Increment<T extends string>(T: T): Increment<T>;
|
|
39
|
+
export type AssertProperties<T> = T extends TProperties ? T : TProperties;
|
|
40
|
+
export type AssertRest<T, E extends TSchema[] = TSchema[]> = T extends E ? T : [];
|
|
41
|
+
export type AssertType<T, E extends TSchema = TSchema> = T extends E ? T : TNever;
|
|
42
|
+
export {};
|