@nmtjs/type 0.6.4 → 0.7.0
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/dist/index.js +31 -31
- package/dist/index.js.map +1 -1
- package/dist/temporal.js +7 -8
- package/dist/temporal.js.map +1 -1
- package/dist/types/any.js +4 -4
- package/dist/types/any.js.map +1 -1
- package/dist/types/array.js +23 -23
- package/dist/types/array.js.map +1 -1
- package/dist/types/base.js +65 -66
- package/dist/types/base.js.map +1 -1
- package/dist/types/boolean.js +4 -4
- package/dist/types/boolean.js.map +1 -1
- package/dist/types/custom.js +10 -9
- package/dist/types/custom.js.map +1 -1
- package/dist/types/date.js +6 -13
- package/dist/types/date.js.map +1 -1
- package/dist/types/enum.js +7 -16
- package/dist/types/enum.js.map +1 -1
- package/dist/types/literal.js +7 -6
- package/dist/types/literal.js.map +1 -1
- package/dist/types/never.js +4 -4
- package/dist/types/never.js.map +1 -1
- package/dist/types/number.js +26 -93
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +42 -31
- package/dist/types/object.js.map +1 -1
- package/dist/types/string.js +31 -47
- package/dist/types/string.js.map +1 -1
- package/dist/types/temporal.js +40 -41
- package/dist/types/temporal.js.map +1 -1
- package/dist/types/union.js +25 -18
- package/dist/types/union.js.map +1 -1
- package/dist/utils.js +0 -1
- package/dist/utils.js.map +1 -1
- package/package.json +7 -19
- package/src/index.ts +24 -25
- package/src/temporal.ts +8 -8
- package/src/types/any.ts +5 -3
- package/src/types/array.ts +24 -22
- package/src/types/base.ts +148 -81
- package/src/types/boolean.ts +5 -3
- package/src/types/custom.ts +43 -24
- package/src/types/date.ts +17 -16
- package/src/types/enum.ts +12 -22
- package/src/types/literal.ts +9 -6
- package/src/types/never.ts +5 -3
- package/src/types/number.ts +31 -93
- package/src/types/object.ts +44 -37
- package/src/types/string.ts +41 -39
- package/src/types/temporal.ts +72 -32
- package/src/types/union.ts +59 -50
- package/src/utils.ts +22 -22
- package/dist/compiler.js +0 -55
- package/dist/compiler.js.map +0 -1
- package/dist/formats.js +0 -127
- package/dist/formats.js.map +0 -1
- package/dist/inference.js +0 -1
- package/dist/inference.js.map +0 -1
- package/dist/parse.js +0 -145
- package/dist/parse.js.map +0 -1
- package/dist/runtime.js +0 -73
- package/dist/runtime.js.map +0 -1
- package/dist/schemas/default.js +0 -6
- package/dist/schemas/default.js.map +0 -1
- package/dist/schemas/discriminated-union.js +0 -9
- package/dist/schemas/discriminated-union.js.map +0 -1
- package/dist/schemas/nullable.js +0 -11
- package/dist/schemas/nullable.js.map +0 -1
- package/src/compiler.ts +0 -100
- package/src/formats.ts +0 -182
- package/src/inference.ts +0 -128
- package/src/parse.ts +0 -217
- package/src/runtime.ts +0 -137
- package/src/schemas/default.ts +0 -12
- package/src/schemas/discriminated-union.ts +0 -49
- package/src/schemas/nullable.ts +0 -20
package/src/types/union.ts
CHANGED
|
@@ -1,56 +1,64 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
DiscriminatedUnion,
|
|
12
|
-
type DiscriminatedUnionProperties,
|
|
13
|
-
type TDiscriminatedUnion,
|
|
14
|
-
} from '../schemas/discriminated-union.ts'
|
|
2
|
+
type core,
|
|
3
|
+
discriminatedUnion,
|
|
4
|
+
intersection,
|
|
5
|
+
union,
|
|
6
|
+
type ZodMiniDiscriminatedUnion,
|
|
7
|
+
type ZodMiniIntersection,
|
|
8
|
+
type ZodMiniUnion,
|
|
9
|
+
} from '@zod/mini'
|
|
15
10
|
import { BaseType, type BaseTypeAny } from './base.ts'
|
|
11
|
+
import type { LiteralType } from './literal.ts'
|
|
16
12
|
import type { ObjectType, ObjectTypeProps } from './object.ts'
|
|
17
13
|
|
|
18
14
|
export class UnionType<
|
|
19
15
|
T extends readonly BaseType[] = readonly BaseType[],
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
> extends BaseType<
|
|
17
|
+
ZodMiniUnion<core.utils.Flatten<T[number]['encodedZodType'][]>>,
|
|
18
|
+
ZodMiniUnion<core.utils.Flatten<T[number]['decodedZodType'][]>>,
|
|
19
|
+
{ options: T }
|
|
20
|
+
> {
|
|
21
|
+
static factory<T extends readonly BaseType[] = readonly BaseType[]>(
|
|
22
|
+
...options: T
|
|
23
|
+
) {
|
|
24
|
+
return new UnionType<T>({
|
|
25
|
+
encodedZodType: union(options.map((t) => t.encodedZodType)),
|
|
26
|
+
decodedZodType: union(options.map((t) => t.decodedZodType)),
|
|
27
|
+
props: { options },
|
|
28
|
+
})
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
export class IntersactionType<
|
|
36
|
-
T extends readonly BaseType
|
|
37
|
-
S extends TSchema[] = UnionToTuple<T[number]['schema']>,
|
|
33
|
+
T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],
|
|
38
34
|
> extends BaseType<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
ZodMiniIntersection<T[0]['encodedZodType'], T[1]['encodedZodType']>,
|
|
36
|
+
ZodMiniIntersection<T[0]['decodedZodType'], T[1]['decodedZodType']>,
|
|
37
|
+
{ options: T }
|
|
42
38
|
> {
|
|
43
39
|
static factory<
|
|
44
|
-
T extends readonly BaseType
|
|
45
|
-
S extends TSchema[] = UnionToTuple<T[number]['schema']>,
|
|
40
|
+
T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],
|
|
46
41
|
>(...options: T) {
|
|
47
|
-
return new IntersactionType<T
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
return new IntersactionType<T>({
|
|
43
|
+
encodedZodType: intersection(
|
|
44
|
+
options[0].encodedZodType,
|
|
45
|
+
options[1].encodedZodType,
|
|
46
|
+
),
|
|
47
|
+
decodedZodType: intersection(
|
|
48
|
+
options[0].decodedZodType,
|
|
49
|
+
options[1].decodedZodType,
|
|
50
|
+
),
|
|
51
|
+
props: { options },
|
|
52
|
+
})
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
|
|
56
|
+
export type DiscriminatedUnionProperties<K extends string = string> = {
|
|
57
|
+
[OK in K]: LiteralType<string>
|
|
58
|
+
} & {
|
|
59
|
+
[OK in string]: any
|
|
60
|
+
}
|
|
61
|
+
|
|
54
62
|
export type DiscriminatedUnionOptionType<K extends string> = ObjectType<
|
|
55
63
|
ObjectTypeProps & { [_ in K]: BaseTypeAny }
|
|
56
64
|
>
|
|
@@ -59,26 +67,27 @@ export class DiscriminatedUnionType<
|
|
|
59
67
|
K extends string = string,
|
|
60
68
|
T extends
|
|
61
69
|
readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],
|
|
62
|
-
S extends TObject<DiscriminatedUnionProperties<K>>[] = [],
|
|
63
70
|
> extends BaseType<
|
|
64
|
-
|
|
71
|
+
ZodMiniDiscriminatedUnion<core.utils.Flatten<T[number]['encodedZodType'][]>>,
|
|
72
|
+
ZodMiniDiscriminatedUnion<core.utils.Flatten<T[number]['decodedZodType'][]>>,
|
|
65
73
|
{
|
|
66
74
|
key: K
|
|
67
75
|
options: T
|
|
68
|
-
}
|
|
69
|
-
StaticInputDecode<TDiscriminatedUnion<K, S>>
|
|
76
|
+
}
|
|
70
77
|
> {
|
|
71
78
|
static factory<
|
|
72
|
-
K extends string,
|
|
73
|
-
T extends
|
|
74
|
-
|
|
75
|
-
S extends TObject<DiscriminatedUnionProperties<K>>[] = UnionToTuple<
|
|
76
|
-
T[number]['schema']
|
|
77
|
-
>,
|
|
79
|
+
K extends string = string,
|
|
80
|
+
T extends
|
|
81
|
+
readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],
|
|
78
82
|
>(key: K, ...options: T) {
|
|
79
|
-
return new DiscriminatedUnionType<K, T
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
return new DiscriminatedUnionType<K, T>({
|
|
84
|
+
encodedZodType: discriminatedUnion(
|
|
85
|
+
options.map((t) => t.encodedZodType) as any,
|
|
86
|
+
),
|
|
87
|
+
decodedZodType: discriminatedUnion(
|
|
88
|
+
options.map((t) => t.decodedZodType) as any,
|
|
89
|
+
),
|
|
90
|
+
props: { key, options },
|
|
91
|
+
})
|
|
83
92
|
}
|
|
84
93
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export type UnionToIntersectionFn<T> = (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
) extends (k: infer Intersection) => void
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never]
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never
|
|
1
|
+
// export type UnionToIntersectionFn<T> = (
|
|
2
|
+
// T extends unknown
|
|
3
|
+
// ? (k: () => T) => void
|
|
4
|
+
// : never
|
|
5
|
+
// ) extends (k: infer Intersection) => void
|
|
6
|
+
// ? Intersection
|
|
7
|
+
// : never
|
|
8
|
+
// export type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last
|
|
9
|
+
// ? Last
|
|
10
|
+
// : never
|
|
11
|
+
// export type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never]
|
|
12
|
+
// ? Tuple
|
|
13
|
+
// : UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>
|
|
14
|
+
// export type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never
|
|
15
15
|
|
|
16
|
-
export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>
|
|
16
|
+
// export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>
|
|
17
17
|
|
|
18
|
-
export type Merge<T, U> = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
18
|
+
// export type Merge<T, U> = {
|
|
19
|
+
// [K in keyof T | keyof U]: K extends keyof U
|
|
20
|
+
// ? U[K]
|
|
21
|
+
// : K extends keyof T
|
|
22
|
+
// ? T[K]
|
|
23
|
+
// : never
|
|
24
|
+
// }
|
package/dist/compiler.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { TypeCompiler } from '@sinclair/typebox/compiler';
|
|
2
|
-
import { TransformDecode, TransformEncode } from '@sinclair/typebox/value';
|
|
3
|
-
import { _applyDefaults, _parse, _traversErrors } from "./runtime.js";
|
|
4
|
-
function compileType(type) {
|
|
5
|
-
const { schema } = type;
|
|
6
|
-
const compiled = TypeCompiler.Compile(schema);
|
|
7
|
-
const check = (value)=>compiled.Check(value);
|
|
8
|
-
const applyDefaults = (value)=>_applyDefaults(schema, value);
|
|
9
|
-
const parse = (value, cloneOptions)=>_parse(schema, value, cloneOptions);
|
|
10
|
-
const errors = (value)=>_traversErrors(compiled.Errors(value));
|
|
11
|
-
const decode = TransformDecode.bind(null, schema, compiled.References());
|
|
12
|
-
const encode = TransformEncode.bind(null, schema, compiled.References());
|
|
13
|
-
return {
|
|
14
|
-
check,
|
|
15
|
-
parse,
|
|
16
|
-
errors,
|
|
17
|
-
applyDefaults,
|
|
18
|
-
decode,
|
|
19
|
-
encode
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export function compile(type) {
|
|
23
|
-
const compiled = compileType(type);
|
|
24
|
-
function decodeSafe(val) {
|
|
25
|
-
try {
|
|
26
|
-
return {
|
|
27
|
-
success: true,
|
|
28
|
-
value: compiled.decode(val)
|
|
29
|
-
};
|
|
30
|
-
} catch (error) {
|
|
31
|
-
return {
|
|
32
|
-
success: false,
|
|
33
|
-
error
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function encodeSafe(val) {
|
|
38
|
-
try {
|
|
39
|
-
return {
|
|
40
|
-
success: true,
|
|
41
|
-
value: compiled.encode(val)
|
|
42
|
-
};
|
|
43
|
-
} catch (error) {
|
|
44
|
-
return {
|
|
45
|
-
success: false,
|
|
46
|
-
error
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
...compiled,
|
|
52
|
-
decodeSafe,
|
|
53
|
-
encodeSafe
|
|
54
|
-
};
|
|
55
|
-
}
|
package/dist/compiler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/compiler.ts"],"sourcesContent":["import { TypeCompiler } from '@sinclair/typebox/compiler'\nimport { TransformDecode, TransformEncode } from '@sinclair/typebox/value'\nimport type {\n StaticInputEncode,\n StaticOutputDecode,\n StaticOutputEncode,\n} from './inference.ts'\nimport {\n _applyDefaults,\n _parse,\n _traversErrors,\n type CloneOptions,\n type ValidationError,\n} from './runtime.ts'\nimport type { BaseType } from './types/base.ts'\n\nexport type Compiled<T extends BaseType = BaseType> = {\n check: (val: unknown) => val is StaticInputEncode<T['schema']>\n errors: (val: unknown) => ValidationError[]\n parse: (val: unknown, cloneOptions?: CloneOptions) => unknown\n applyDefaults: (val: unknown) => unknown\n /**\n * Requires to `check` before calling\n */\n decode: (val: unknown) => StaticOutputDecode<T['schema']>\n /**\n * Requires to `check` before calling\n */\n encode: (val: unknown) => StaticOutputEncode<T['schema']>\n /**\n * Requires to `check` before calling\n */\n decodeSafe: (\n val: unknown,\n ) =>\n | { success: true; value: StaticOutputDecode<T['schema']> }\n | { success: false; error: any }\n /**\n * Requires to `check` before calling\n */\n encodeSafe: (\n val: unknown,\n ) =>\n | { success: true; value: StaticOutputEncode<T['schema']> }\n | { success: false; error: any }\n}\n\nfunction compileType(type: BaseType) {\n const { schema } = type\n const compiled = TypeCompiler.Compile(schema)\n\n const check = (value: unknown) => compiled.Check(value)\n const applyDefaults = (value: unknown) => _applyDefaults(schema, value)\n const parse = (value: unknown, cloneOptions?: CloneOptions) =>\n _parse(schema, value, cloneOptions)\n const errors = (value: unknown) => _traversErrors(compiled.Errors(value))\n const decode = TransformDecode.bind(null, schema, compiled.References())\n const encode = TransformEncode.bind(null, schema, compiled.References())\n\n return {\n check,\n parse,\n errors,\n applyDefaults,\n decode,\n encode,\n }\n}\n\nexport function compile<T extends BaseType>(type: T): Compiled<T> {\n const compiled = compileType(type)\n\n function decodeSafe(val: unknown) {\n try {\n return {\n success: true as const,\n value: compiled.decode(val),\n }\n } catch (error) {\n return { success: false as const, error }\n }\n }\n\n function encodeSafe(val: unknown) {\n try {\n return {\n success: true as const,\n value: compiled.encode(val),\n }\n } catch (error) {\n return { success: false as const, error }\n }\n }\n\n return {\n ...compiled,\n decodeSafe,\n encodeSafe,\n } as any\n}\n"],"names":["TypeCompiler","TransformDecode","TransformEncode","_applyDefaults","_parse","_traversErrors","compileType","type","schema","compiled","Compile","check","value","Check","applyDefaults","parse","cloneOptions","errors","Errors","decode","bind","References","encode","compile","decodeSafe","val","success","error","encodeSafe"],"mappings":"AAAA,SAASA,YAAY,QAAQ,6BAA4B;AACzD,SAASC,eAAe,EAAEC,eAAe,QAAQ,0BAAyB;AAM1E,SACEC,cAAc,EACdC,MAAM,EACNC,cAAc,QAGT,eAAc;AAkCrB,SAASC,YAAYC,IAAc;IACjC,MAAM,EAAEC,MAAM,EAAE,GAAGD;IACnB,MAAME,WAAWT,aAAaU,OAAO,CAACF;IAEtC,MAAMG,QAAQ,CAACC,QAAmBH,SAASI,KAAK,CAACD;IACjD,MAAME,gBAAgB,CAACF,QAAmBT,eAAeK,QAAQI;IACjE,MAAMG,QAAQ,CAACH,OAAgBI,eAC7BZ,OAAOI,QAAQI,OAAOI;IACxB,MAAMC,SAAS,CAACL,QAAmBP,eAAeI,SAASS,MAAM,CAACN;IAClE,MAAMO,SAASlB,gBAAgBmB,IAAI,CAAC,MAAMZ,QAAQC,SAASY,UAAU;IACrE,MAAMC,SAASpB,gBAAgBkB,IAAI,CAAC,MAAMZ,QAAQC,SAASY,UAAU;IAErE,OAAO;QACLV;QACAI;QACAE;QACAH;QACAK;QACAG;IACF;AACF;AAEA,OAAO,SAASC,QAA4BhB,IAAO;IACjD,MAAME,WAAWH,YAAYC;IAE7B,SAASiB,WAAWC,GAAY;QAC9B,IAAI;YACF,OAAO;gBACLC,SAAS;gBACTd,OAAOH,SAASU,MAAM,CAACM;YACzB;QACF,EAAE,OAAOE,OAAO;YACd,OAAO;gBAAED,SAAS;gBAAgBC;YAAM;QAC1C;IACF;IAEA,SAASC,WAAWH,GAAY;QAC9B,IAAI;YACF,OAAO;gBACLC,SAAS;gBACTd,OAAOH,SAASa,MAAM,CAACG;YACzB;QACF,EAAE,OAAOE,OAAO;YACd,OAAO;gBAAED,SAAS;gBAAgBC;YAAM;QAC1C;IACF;IAEA,OAAO;QACL,GAAGlB,QAAQ;QACXe;QACAI;IACF;AACF"}
|
package/dist/formats.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { FormatRegistry } from '@sinclair/typebox/type';
|
|
2
|
-
export const register = ()=>{
|
|
3
|
-
for (const [name, format] of Object.entries(fullFormats)){
|
|
4
|
-
if (format === true) {
|
|
5
|
-
FormatRegistry.Set(name, ()=>true);
|
|
6
|
-
continue;
|
|
7
|
-
}
|
|
8
|
-
if (typeof format === 'function') {
|
|
9
|
-
FormatRegistry.Set(name, format);
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
FormatRegistry.Set(name, (value)=>format.test(value));
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
export const fullFormats = {
|
|
16
|
-
date,
|
|
17
|
-
time: getTime(true),
|
|
18
|
-
'date-time': getDateTime(true),
|
|
19
|
-
'iso-time': getTime(),
|
|
20
|
-
'iso-date-time': getDateTime(),
|
|
21
|
-
duration: /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?((\d+|\d+\.\d+)S)?)?|(\d+W)?)$/,
|
|
22
|
-
uri,
|
|
23
|
-
'uri-reference': /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,
|
|
24
|
-
'uri-template': /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,
|
|
25
|
-
url: /^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,
|
|
26
|
-
email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
|
|
27
|
-
hostname: /^(?=.{1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|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,
|
|
30
|
-
regex,
|
|
31
|
-
uuid: /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,
|
|
32
|
-
'json-pointer': /^(?:\/(?:[^~/]|~0|~1)*)*$/,
|
|
33
|
-
'json-pointer-uri-fragment': /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,
|
|
34
|
-
'relative-json-pointer': /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,
|
|
35
|
-
byte,
|
|
36
|
-
int32: validateInt32,
|
|
37
|
-
int64: validateInt64,
|
|
38
|
-
float: validateNumber,
|
|
39
|
-
double: validateNumber,
|
|
40
|
-
password: true,
|
|
41
|
-
binary: true
|
|
42
|
-
};
|
|
43
|
-
function isLeapYear(year) {
|
|
44
|
-
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
45
|
-
}
|
|
46
|
-
const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
47
|
-
const DAYS = [
|
|
48
|
-
0,
|
|
49
|
-
31,
|
|
50
|
-
28,
|
|
51
|
-
31,
|
|
52
|
-
30,
|
|
53
|
-
31,
|
|
54
|
-
30,
|
|
55
|
-
31,
|
|
56
|
-
31,
|
|
57
|
-
30,
|
|
58
|
-
31,
|
|
59
|
-
30,
|
|
60
|
-
31
|
|
61
|
-
];
|
|
62
|
-
function date(str) {
|
|
63
|
-
const matches = DATE.exec(str);
|
|
64
|
-
if (!matches) return false;
|
|
65
|
-
const year = +matches[1];
|
|
66
|
-
const month = +matches[2];
|
|
67
|
-
const day = +matches[3];
|
|
68
|
-
return month >= 1 && month <= 12 && day >= 1 && day <= (month === 2 && isLeapYear(year) ? 29 : DAYS[month]);
|
|
69
|
-
}
|
|
70
|
-
const TIME = /^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i;
|
|
71
|
-
function getTime(strictTimeZone) {
|
|
72
|
-
return function time(str) {
|
|
73
|
-
const matches = TIME.exec(str);
|
|
74
|
-
if (!matches) return false;
|
|
75
|
-
const hr = +matches[1];
|
|
76
|
-
const min = +matches[2];
|
|
77
|
-
const sec = +matches[3];
|
|
78
|
-
const tz = matches[4];
|
|
79
|
-
const tzSign = matches[5] === '-' ? -1 : 1;
|
|
80
|
-
const tzH = +(matches[6] || 0);
|
|
81
|
-
const tzM = +(matches[7] || 0);
|
|
82
|
-
if (tzH > 23 || tzM > 59 || strictTimeZone && !tz) return false;
|
|
83
|
-
if (hr <= 23 && min <= 59 && sec < 60) return true;
|
|
84
|
-
const utcMin = min - tzM * tzSign;
|
|
85
|
-
const utcHr = hr - tzH * tzSign - (utcMin < 0 ? 1 : 0);
|
|
86
|
-
return (utcHr === 23 || utcHr === -1) && (utcMin === 59 || utcMin === -1) && sec < 61;
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
const DATE_TIME_SEPARATOR = /t|\s/i;
|
|
90
|
-
function getDateTime(strictTimeZone) {
|
|
91
|
-
const time = getTime(strictTimeZone);
|
|
92
|
-
return function date_time(str) {
|
|
93
|
-
const dateTime = str.split(DATE_TIME_SEPARATOR);
|
|
94
|
-
return dateTime.length === 2 && date(dateTime[0]) && time(dateTime[1]);
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
const NOT_URI_FRAGMENT = /\/|:/;
|
|
98
|
-
const URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
99
|
-
function uri(str) {
|
|
100
|
-
return NOT_URI_FRAGMENT.test(str) && URI.test(str);
|
|
101
|
-
}
|
|
102
|
-
const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;
|
|
103
|
-
function byte(str) {
|
|
104
|
-
BYTE.lastIndex = 0;
|
|
105
|
-
return BYTE.test(str);
|
|
106
|
-
}
|
|
107
|
-
const MIN_INT32 = -(2 ** 31);
|
|
108
|
-
const MAX_INT32 = 2 ** 31 - 1;
|
|
109
|
-
function validateInt32(value) {
|
|
110
|
-
return Number.isInteger(value) && value <= MAX_INT32 && value >= MIN_INT32;
|
|
111
|
-
}
|
|
112
|
-
function validateInt64(value) {
|
|
113
|
-
return Number.isInteger(value);
|
|
114
|
-
}
|
|
115
|
-
function validateNumber() {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
const Z_ANCHOR = /[^\\]\\Z/;
|
|
119
|
-
function regex(str) {
|
|
120
|
-
if (Z_ANCHOR.test(str)) return false;
|
|
121
|
-
try {
|
|
122
|
-
new RegExp(str);
|
|
123
|
-
return true;
|
|
124
|
-
} catch (e) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
}
|
package/dist/formats.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/formats.ts"],"sourcesContent":["// Source: https://gist.github.com/ChuckJonas/74d9cfb6ba46244ef4eaa5818c06987b\n// TODO: review all of this\n\nimport { FormatRegistry } from '@sinclair/typebox/type'\n\nexport const register = () => {\n for (const [name, format] of Object.entries(fullFormats)) {\n if (format === true) {\n FormatRegistry.Set(name, () => true)\n continue\n }\n\n if (typeof format === 'function') {\n FormatRegistry.Set(name, format)\n continue\n }\n\n FormatRegistry.Set(name, (value) => format.test(value))\n }\n}\n\nexport const fullFormats: Record<\n string,\n RegExp | ((v: any) => boolean) | true\n> = {\n // date: http://tools.ietf.org/html/rfc3339#section-5.6\n date,\n // date-time: http://tools.ietf.org/html/rfc3339#section-5.6\n time: getTime(true),\n 'date-time': getDateTime(true),\n 'iso-time': getTime(),\n 'iso-date-time': getDateTime(),\n // duration: https://tools.ietf.org/html/rfc3339#appendix-A\n duration:\n /^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?((\\d+|\\d+\\.\\d+)S)?)?|(\\d+W)?)$/,\n uri,\n 'uri-reference':\n /^(?:[a-z][a-z0-9+\\-.]*:)?(?:\\/?\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\\.[a-z0-9\\-._~!$&'()*+,;=:]+)\\]|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)|(?:[a-z0-9\\-._~!$&'\"()*+,;=]|%[0-9a-f]{2})*)(?::\\d*)?(?:\\/(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})*)*|\\/(?:(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\\?(?:[a-z0-9\\-._~!$&'\"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'\"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,\n // uri-template: https://tools.ietf.org/html/rfc6570\n 'uri-template':\n // biome-ignore lint/suspicious/noControlCharactersInRegex:\n /^(?:(?:[^\\x00-\\x20\"'<>%\\\\^`{|}]|%[0-9a-f]{2})|\\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?)*\\})*$/i,\n // For the source: https://gist.github.com/dperini/729294\n // For test cases: https://mathiasbynens.be/demo/url-regex\n url: /^(?:https?|ftp):\\/\\/(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)(?:\\.(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)*(?:\\.(?:[a-z\\u{00a1}-\\u{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$/iu,\n email:\n /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,\n hostname:\n /^(?=.{1,253}\\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\\.?$/i,\n // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html\n ipv4: /^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/,\n ipv6: /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))$/i,\n regex,\n // uuid: http://tools.ietf.org/html/rfc4122\n uuid: /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,\n // JSON-pointer: https://tools.ietf.org/html/rfc6901\n // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A\n 'json-pointer': /^(?:\\/(?:[^~/]|~0|~1)*)*$/,\n 'json-pointer-uri-fragment':\n /^#(?:\\/(?:[a-z0-9_\\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,\n // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00\n 'relative-json-pointer': /^(?:0|[1-9][0-9]*)(?:#|(?:\\/(?:[^~/]|~0|~1)*)*)$/,\n // the following formats are used by the openapi specification: https://spec.openapis.org/oas/v3.0.0#data-types\n // byte: https://github.com/miguelmota/is-base64\n byte,\n // signed 32 bit integer\n int32: validateInt32,\n // signed 64 bit integer\n int64: validateInt64,\n // C-type float\n float: validateNumber,\n // C-type double\n double: validateNumber,\n // hint to the UI to hide input strings\n password: true,\n // unchecked string payload\n binary: true,\n}\n\nfunction isLeapYear(year: number): boolean {\n // https://tools.ietf.org/html/rfc3339#appendix-C\n return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)\n}\n\nconst DATE = /^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)$/\nconst DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n\nfunction date(str: string): boolean {\n // full-date from http://tools.ietf.org/html/rfc3339#section-5.6\n const matches: string[] | null = DATE.exec(str)\n if (!matches) return false\n const year: number = +matches[1]\n const month: number = +matches[2]\n const day: number = +matches[3]\n return (\n month >= 1 &&\n month <= 12 &&\n day >= 1 &&\n day <= (month === 2 && isLeapYear(year) ? 29 : DAYS[month])\n )\n}\n\nconst TIME = /^(\\d\\d):(\\d\\d):(\\d\\d(?:\\.\\d+)?)(z|([+-])(\\d\\d)(?::?(\\d\\d))?)?$/i\n\nfunction getTime(strictTimeZone?: boolean): (str: string) => boolean {\n return function time(str: string): boolean {\n const matches: string[] | null = TIME.exec(str)\n if (!matches) return false\n const hr: number = +matches[1]\n const min: number = +matches[2]\n const sec: number = +matches[3]\n const tz: string | undefined = matches[4]\n const tzSign: number = matches[5] === '-' ? -1 : 1\n const tzH: number = +(matches[6] || 0)\n const tzM: number = +(matches[7] || 0)\n if (tzH > 23 || tzM > 59 || (strictTimeZone && !tz)) return false\n if (hr <= 23 && min <= 59 && sec < 60) return true\n // leap second\n const utcMin = min - tzM * tzSign\n const utcHr = hr - tzH * tzSign - (utcMin < 0 ? 1 : 0)\n return (\n (utcHr === 23 || utcHr === -1) &&\n (utcMin === 59 || utcMin === -1) &&\n sec < 61\n )\n }\n}\n\nconst DATE_TIME_SEPARATOR = /t|\\s/i\nfunction getDateTime(strictTimeZone?: boolean): (str: string) => boolean {\n const time = getTime(strictTimeZone)\n\n return function date_time(str: string): boolean {\n // http://tools.ietf.org/html/rfc3339#section-5.6\n const dateTime: string[] = str.split(DATE_TIME_SEPARATOR)\n return dateTime.length === 2 && date(dateTime[0]) && time(dateTime[1])\n }\n}\n\nconst NOT_URI_FRAGMENT = /\\/|:/\nconst URI =\n /^(?:[a-z][a-z0-9+\\-.]*:)(?:\\/?\\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]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i\n\nfunction uri(str: string): boolean {\n // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required \".\"\n return NOT_URI_FRAGMENT.test(str) && URI.test(str)\n}\n\nconst BYTE =\n /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm\n\nfunction byte(str: string): boolean {\n BYTE.lastIndex = 0\n return BYTE.test(str)\n}\n\nconst MIN_INT32 = -(2 ** 31)\nconst MAX_INT32 = 2 ** 31 - 1\n\nfunction validateInt32(value: number): boolean {\n return Number.isInteger(value) && value <= MAX_INT32 && value >= MIN_INT32\n}\n\nfunction validateInt64(value: number): boolean {\n // JSON and javascript max Int is 2**53, so any int that passes isInteger is valid for Int64\n return Number.isInteger(value)\n}\n\nfunction validateNumber(): boolean {\n return true\n}\n\nconst Z_ANCHOR = /[^\\\\]\\\\Z/\nfunction regex(str: string): boolean {\n if (Z_ANCHOR.test(str)) return false\n try {\n new RegExp(str)\n return true\n } catch (e) {\n return false\n }\n}\n"],"names":["FormatRegistry","register","name","format","Object","entries","fullFormats","Set","value","test","date","time","getTime","getDateTime","duration","uri","url","email","hostname","ipv4","ipv6","regex","uuid","byte","int32","validateInt32","int64","validateInt64","float","validateNumber","double","password","binary","isLeapYear","year","DATE","DAYS","str","matches","exec","month","day","TIME","strictTimeZone","hr","min","sec","tz","tzSign","tzH","tzM","utcMin","utcHr","DATE_TIME_SEPARATOR","date_time","dateTime","split","length","NOT_URI_FRAGMENT","URI","BYTE","lastIndex","MIN_INT32","MAX_INT32","Number","isInteger","Z_ANCHOR","RegExp","e"],"mappings":"AAGA,SAASA,cAAc,QAAQ,yBAAwB;AAEvD,OAAO,MAAMC,WAAW;IACtB,KAAK,MAAM,CAACC,MAAMC,OAAO,IAAIC,OAAOC,OAAO,CAACC,aAAc;QACxD,IAAIH,WAAW,MAA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IAAI,CAAC4B;AAChD;AAEA,MAAMuB,OACJ;AAEF,SAASrC,KAAKc,GAAW;IACvBuB,KAAKC,SAAS,GAAG;IACjB,OAAOD,KAAKnD,IAAI,CAAC4B;AACnB;AAEA,MAAMyB,YAAY,CAAE,CAAA,KAAK,EAAC;AAC1B,MAAMC,YAAY,KAAK,KAAK;AAE5B,SAAStC,cAAcjB,KAAa;IAClC,OAAOwD,OAAOC,SAAS,CAACzD,UAAUA,SAASuD,aAAavD,SAASsD;AACnE;AAEA,SAASnC,cAAcnB,KAAa;IAElC,OAAOwD,OAAOC,SAAS,CAACzD;AAC1B;AAEA,SAASqB;IACP,OAAO;AACT;AAEA,MAAMqC,WAAW;AACjB,SAAS7C,MAAMgB,GAAW;IACxB,IAAI6B,SAASzD,IAAI,CAAC4B,MAAM,OAAO;IAC/B,IAAI;QACF,IAAI8B,OAAO9B;QACX,OAAO;IACT,EAAE,OAAO+B,GAAG;QACV,OAAO;IACT;AACF"}
|
package/dist/inference.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/inference.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/inference.ts"],"sourcesContent":["import type * as Types from '@sinclair/typebox'\nimport type { TProperties, TSchema } from '@sinclair/typebox'\nimport type { TDefault } from './schemas/default.ts'\n\nexport type StaticInputEncode<Type extends TSchema> =\n Type extends Types.TOptional<TSchema>\n ? Types.StaticEncode<Type> | undefined\n : Types.StaticEncode<Type>\n\nexport type StaticInputDecode<Type extends TSchema> =\n Type extends Types.TOptional<TSchema>\n ? Types.StaticDecode<Type> | undefined\n : Types.StaticDecode<Type>\n\nexport type StaticOutputEncode<Type extends TSchema> = Types.StaticEncode<\n TMap<Type, StaticOutputMapping>\n>\n\nexport type StaticOutputDecode<Type extends TSchema> = Types.StaticDecode<\n TMap<Type, StaticOutputMapping>\n>\n\ninterface StaticOutputMapping extends TMapping {\n output: this['input']\n}\n\ninterface TMapping {\n input: unknown\n output: unknown\n}\n\ntype TApply<\n Type extends TSchema,\n Mapping extends TMapping,\n Mapped = (Mapping & { input: Type })['output'],\n Result = Mapped extends TSchema ? Mapped : never,\n> = Result\n\ntype TFromProperties<\n Properties extends TProperties,\n Mapping extends TMapping,\n Result extends TProperties = {\n [Key in keyof Properties]: TMap<Properties[Key], Mapping>\n },\n> = Result\n\ntype TFromRest<\n Types extends TSchema[],\n Mapping extends TMapping,\n Result extends TSchema[] = [],\n> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]]\n ? TFromRest<Right, Mapping, [...Result, TMap<Left, Mapping>]>\n : Result\n\ntype TFromType<\n Type extends TSchema,\n Mapping extends TMapping,\n Result extends TSchema = TApply<Type, Mapping>,\n> = Result\n\ntype UnwrapDefault<T extends TSchema> = T extends TDefault<infer U>\n ? U extends Types.TOptional<infer V>\n ? V\n : U\n : T\n\ntype TMap<\n Type extends TSchema,\n Mapping extends TMapping,\n // Maps the Exterior Type\n Exterior extends TSchema = TFromType<Type, Mapping>,\n // Maps the Interior Parameterized Types\n Interior extends TSchema = Exterior extends Types.TConstructor<\n infer Parameters extends TSchema[],\n infer ReturnType extends TSchema\n >\n ? Types.TConstructor<\n TFromRest<Parameters, Mapping>,\n TFromType<ReturnType, Mapping>\n >\n : Exterior extends Types.TFunction<\n infer Parameters extends TSchema[],\n infer ReturnType extends TSchema\n >\n ? Types.TFunction<\n TFromRest<Parameters, Mapping>,\n TFromType<ReturnType, Mapping>\n >\n : Exterior extends Types.TIntersect<infer Types extends TSchema[]>\n ? Types.TIntersect<TFromRest<Types, Mapping>>\n : Exterior extends Types.TUnion<infer Types extends TSchema[]>\n ? Types.TUnion<TFromRest<Types, Mapping>>\n : Exterior extends Types.TTuple<infer Types extends TSchema[]>\n ? Types.TTuple<TFromRest<Types, Mapping>>\n : Exterior extends Types.TArray<infer Type extends TSchema>\n ? Types.TArray<TFromType<Type, Mapping>>\n : Exterior extends Types.TAsyncIterator<\n infer Type extends TSchema\n >\n ? Types.TAsyncIterator<TFromType<Type, Mapping>>\n : Exterior extends Types.TIterator<infer Type extends TSchema>\n ? Types.TIterator<TFromType<Type, Mapping>>\n : Exterior extends Types.TPromise<infer Type extends TSchema>\n ? Types.TPromise<TFromType<Type, Mapping>>\n : Exterior extends Types.TObject<\n infer Properties extends TProperties\n >\n ? Types.TObject<TFromProperties<Properties, Mapping>>\n : Exterior extends Types.TRecord<\n infer Key extends TSchema,\n infer Value extends TSchema\n >\n ? Types.TRecordOrObject<\n TFromType<Key, Mapping>,\n TFromType<Value, Mapping>\n >\n : Exterior,\n // Modifiers Derived from Exterior Type Mapping\n IsOptional extends number = Exterior extends Types.TOptional<TSchema> ? 1 : 0,\n IsReadonly extends number = Exterior extends Types.TReadonly<TSchema> ? 1 : 0,\n Result extends TSchema = [IsReadonly, IsOptional] extends [1, 1]\n ? Types.TReadonly<UnwrapDefault<Interior>>\n : [IsReadonly, IsOptional] extends [0, 1]\n ? UnwrapDefault<Interior>\n : [IsReadonly, IsOptional] extends [1, 0]\n ? Types.TReadonly<UnwrapDefault<Interior>>\n : UnwrapDefault<Interior>,\n> = Result\n"],"names":[],"mappings":"AAkBA,WAEC"}
|
package/dist/parse.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
export function IsAsyncIterator(value) {
|
|
2
|
-
return IsObject(value) && Symbol.asyncIterator in value;
|
|
3
|
-
}
|
|
4
|
-
export function IsIterator(value) {
|
|
5
|
-
return IsObject(value) && Symbol.iterator in value;
|
|
6
|
-
}
|
|
7
|
-
export function IsStandardObject(value) {
|
|
8
|
-
return IsObject(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
9
|
-
}
|
|
10
|
-
export function IsInstanceObject(value) {
|
|
11
|
-
return IsObject(value) && !IsArray(value) && IsFunction(value.constructor) && value.constructor.name !== 'Object';
|
|
12
|
-
}
|
|
13
|
-
export function IsPromise(value) {
|
|
14
|
-
return value instanceof Promise;
|
|
15
|
-
}
|
|
16
|
-
export function IsDate(value) {
|
|
17
|
-
return value instanceof Date && Number.isFinite(value.getTime());
|
|
18
|
-
}
|
|
19
|
-
export function IsMap(value) {
|
|
20
|
-
return value instanceof globalThis.Map;
|
|
21
|
-
}
|
|
22
|
-
export function IsSet(value) {
|
|
23
|
-
return value instanceof globalThis.Set;
|
|
24
|
-
}
|
|
25
|
-
export function IsRegExp(value) {
|
|
26
|
-
return value instanceof globalThis.RegExp;
|
|
27
|
-
}
|
|
28
|
-
export function IsTypedArray(value) {
|
|
29
|
-
return ArrayBuffer.isView(value);
|
|
30
|
-
}
|
|
31
|
-
export function IsInt8Array(value) {
|
|
32
|
-
return value instanceof globalThis.Int8Array;
|
|
33
|
-
}
|
|
34
|
-
export function IsUint8Array(value) {
|
|
35
|
-
return value instanceof globalThis.Uint8Array;
|
|
36
|
-
}
|
|
37
|
-
export function IsUint8ClampedArray(value) {
|
|
38
|
-
return value instanceof globalThis.Uint8ClampedArray;
|
|
39
|
-
}
|
|
40
|
-
export function IsInt16Array(value) {
|
|
41
|
-
return value instanceof globalThis.Int16Array;
|
|
42
|
-
}
|
|
43
|
-
export function IsUint16Array(value) {
|
|
44
|
-
return value instanceof globalThis.Uint16Array;
|
|
45
|
-
}
|
|
46
|
-
export function IsInt32Array(value) {
|
|
47
|
-
return value instanceof globalThis.Int32Array;
|
|
48
|
-
}
|
|
49
|
-
export function IsUint32Array(value) {
|
|
50
|
-
return value instanceof globalThis.Uint32Array;
|
|
51
|
-
}
|
|
52
|
-
export function IsFloat32Array(value) {
|
|
53
|
-
return value instanceof globalThis.Float32Array;
|
|
54
|
-
}
|
|
55
|
-
export function IsFloat64Array(value) {
|
|
56
|
-
return value instanceof globalThis.Float64Array;
|
|
57
|
-
}
|
|
58
|
-
export function IsBigInt64Array(value) {
|
|
59
|
-
return value instanceof globalThis.BigInt64Array;
|
|
60
|
-
}
|
|
61
|
-
export function IsBigUint64Array(value) {
|
|
62
|
-
return value instanceof globalThis.BigUint64Array;
|
|
63
|
-
}
|
|
64
|
-
export function HasPropertyKey(value, key) {
|
|
65
|
-
return key in value;
|
|
66
|
-
}
|
|
67
|
-
export function IsObject(value) {
|
|
68
|
-
return value !== null && typeof value === 'object';
|
|
69
|
-
}
|
|
70
|
-
export function IsArray(value) {
|
|
71
|
-
return Array.isArray(value) && !ArrayBuffer.isView(value);
|
|
72
|
-
}
|
|
73
|
-
export function IsUndefined(value) {
|
|
74
|
-
return value === undefined;
|
|
75
|
-
}
|
|
76
|
-
export function IsNull(value) {
|
|
77
|
-
return value === null;
|
|
78
|
-
}
|
|
79
|
-
export function IsBoolean(value) {
|
|
80
|
-
return typeof value === 'boolean';
|
|
81
|
-
}
|
|
82
|
-
export function IsNumber(value) {
|
|
83
|
-
return typeof value === 'number';
|
|
84
|
-
}
|
|
85
|
-
export function IsInteger(value) {
|
|
86
|
-
return Number.isInteger(value);
|
|
87
|
-
}
|
|
88
|
-
export function IsBigInt(value) {
|
|
89
|
-
return typeof value === 'bigint';
|
|
90
|
-
}
|
|
91
|
-
export function IsString(value) {
|
|
92
|
-
return typeof value === 'string';
|
|
93
|
-
}
|
|
94
|
-
export function IsFunction(value) {
|
|
95
|
-
return typeof value === 'function';
|
|
96
|
-
}
|
|
97
|
-
export function IsSymbol(value) {
|
|
98
|
-
return typeof value === 'symbol';
|
|
99
|
-
}
|
|
100
|
-
export function IsValueType(value) {
|
|
101
|
-
return IsBigInt(value) || IsBoolean(value) || IsNull(value) || IsNumber(value) || IsString(value) || IsSymbol(value) || IsUndefined(value);
|
|
102
|
-
}
|
|
103
|
-
function FromObject(value, exclude) {
|
|
104
|
-
const Acc = {};
|
|
105
|
-
for (const key of Object.getOwnPropertyNames(value)){
|
|
106
|
-
Acc[key] = Clone(value[key], exclude);
|
|
107
|
-
}
|
|
108
|
-
for (const key of Object.getOwnPropertySymbols(value)){
|
|
109
|
-
Acc[key] = Clone(value[key], exclude);
|
|
110
|
-
}
|
|
111
|
-
return Acc;
|
|
112
|
-
}
|
|
113
|
-
function FromArray(value, exclude) {
|
|
114
|
-
return value.map((element)=>Clone(element, exclude));
|
|
115
|
-
}
|
|
116
|
-
function FromTypedArray(value) {
|
|
117
|
-
return value.slice();
|
|
118
|
-
}
|
|
119
|
-
function FromMap(value, exclude) {
|
|
120
|
-
return new Map(Clone([
|
|
121
|
-
...value.entries()
|
|
122
|
-
], exclude));
|
|
123
|
-
}
|
|
124
|
-
function FromSet(value, exclude) {
|
|
125
|
-
return new Set(Clone([
|
|
126
|
-
...value.entries()
|
|
127
|
-
], exclude));
|
|
128
|
-
}
|
|
129
|
-
function FromDate(value) {
|
|
130
|
-
return new Date(value.toISOString());
|
|
131
|
-
}
|
|
132
|
-
function FromValue(value) {
|
|
133
|
-
return value;
|
|
134
|
-
}
|
|
135
|
-
export function Clone(value, exclude) {
|
|
136
|
-
if (IsArray(value)) return FromArray(value, exclude);
|
|
137
|
-
if (IsDate(value)) return FromDate(value);
|
|
138
|
-
if (IsTypedArray(value)) return FromTypedArray(value);
|
|
139
|
-
if (IsMap(value)) return FromMap(value, exclude);
|
|
140
|
-
if (IsSet(value)) return FromSet(value, exclude);
|
|
141
|
-
if (IsObject(value)) return FromObject(value, exclude);
|
|
142
|
-
if (IsValueType(value)) return FromValue(value);
|
|
143
|
-
if (exclude?.has(value.constructor)) return value;
|
|
144
|
-
throw new Error('Cannot clone value');
|
|
145
|
-
}
|
package/dist/parse.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/parse.ts"],"sourcesContent":["// --------------------------------------------------------------------------\n// Iterators\n// --------------------------------------------------------------------------\n\n/** Returns true if this value is an async iterator */\nexport function IsAsyncIterator(value) {\n return IsObject(value) && Symbol.asyncIterator in value\n}\n/** Returns true if this value is an iterator */\nexport function IsIterator(value) {\n return IsObject(value) && Symbol.iterator in value\n}\n// --------------------------------------------------------------------------\n// Object Instances\n// --------------------------------------------------------------------------\n/** Returns true if this value is not an instance of a class */\nexport function IsStandardObject(value) {\n return (\n IsObject(value) &&\n (Object.getPrototypeOf(value) === Object.prototype ||\n Object.getPrototypeOf(value) === null)\n )\n}\n/** Returns true if this value is an instance of a class */\nexport function IsInstanceObject(value) {\n return (\n IsObject(value) &&\n !IsArray(value) &&\n IsFunction(value.constructor) &&\n value.constructor.name !== 'Object'\n )\n}\n// --------------------------------------------------------------------------\n// JavaScript\n// --------------------------------------------------------------------------\n/** Returns true if this value is a Promise */\nexport function IsPromise(value) {\n return value instanceof Promise\n}\n/** Returns true if this value is a Date */\nexport function IsDate(value) {\n return value instanceof Date && Number.isFinite(value.getTime())\n}\n/** Returns true if this value is an instance of Map<K, T> */\nexport function IsMap(value) {\n return value instanceof globalThis.Map\n}\n/** Returns true if this value is an instance of Set<T> */\nexport function IsSet(value) {\n return value instanceof globalThis.Set\n}\n/** Returns true if this value is RegExp */\nexport function IsRegExp(value) {\n return value instanceof globalThis.RegExp\n}\n/** Returns true if this value is a typed array */\nexport function IsTypedArray(value) {\n return ArrayBuffer.isView(value)\n}\n/** Returns true if the value is a Int8Array */\nexport function IsInt8Array(value) {\n return value instanceof globalThis.Int8Array\n}\n/** Returns true if the value is a Uint8Array */\nexport function IsUint8Array(value) {\n return value instanceof globalThis.Uint8Array\n}\n/** Returns true if the value is a Uint8ClampedArray */\nexport function IsUint8ClampedArray(value) {\n return value instanceof globalThis.Uint8ClampedArray\n}\n/** Returns true if the value is a Int16Array */\nexport function IsInt16Array(value) {\n return value instanceof globalThis.Int16Array\n}\n/** Returns true if the value is a Uint16Array */\nexport function IsUint16Array(value) {\n return value instanceof globalThis.Uint16Array\n}\n/** Returns true if the value is a Int32Array */\nexport function IsInt32Array(value) {\n return value instanceof globalThis.Int32Array\n}\n/** Returns true if the value is a Uint32Array */\nexport function IsUint32Array(value) {\n return value instanceof globalThis.Uint32Array\n}\n/** Returns true if the value is a Float32Array */\nexport function IsFloat32Array(value) {\n return value instanceof globalThis.Float32Array\n}\n/** Returns true if the value is a Float64Array */\nexport function IsFloat64Array(value) {\n return value instanceof globalThis.Float64Array\n}\n/** Returns true if the value is a BigInt64Array */\nexport function IsBigInt64Array(value) {\n return value instanceof globalThis.BigInt64Array\n}\n/** Returns true if the value is a BigUint64Array */\nexport function IsBigUint64Array(value) {\n return value instanceof globalThis.BigUint64Array\n}\n// --------------------------------------------------------------------------\n// PropertyKey\n// --------------------------------------------------------------------------\n/** Returns true if this value has this property key */\nexport function HasPropertyKey(value, key) {\n return key in value\n}\n// --------------------------------------------------------------------------\n// Standard\n// --------------------------------------------------------------------------\n/** Returns true of this value is an object type */\nexport function IsObject(value) {\n return value !== null && typeof value === 'object'\n}\n/** Returns true if this value is an array, but not a typed array */\nexport function IsArray(value) {\n return Array.isArray(value) && !ArrayBuffer.isView(value)\n}\n/** Returns true if this value is an undefined */\nexport function IsUndefined(value) {\n return value === undefined\n}\n/** Returns true if this value is an null */\nexport function IsNull(value) {\n return value === null\n}\n/** Returns true if this value is an boolean */\nexport function IsBoolean(value) {\n return typeof value === 'boolean'\n}\n/** Returns true if this value is an number */\nexport function IsNumber(value) {\n return typeof value === 'number'\n}\n/** Returns true if this value is an integer */\nexport function IsInteger(value) {\n return Number.isInteger(value)\n}\n/** Returns true if this value is bigint */\nexport function IsBigInt(value) {\n return typeof value === 'bigint'\n}\n/** Returns true if this value is string */\nexport function IsString(value) {\n return typeof value === 'string'\n}\n/** Returns true if this value is a function */\nexport function IsFunction(value) {\n return typeof value === 'function'\n}\n/** Returns true if this value is a symbol */\nexport function IsSymbol(value) {\n return typeof value === 'symbol'\n}\n/** Returns true if this value is a value type such as number, string, boolean */\nexport function IsValueType(value) {\n // prettier-ignore\n return (\n IsBigInt(value) ||\n IsBoolean(value) ||\n IsNull(value) ||\n IsNumber(value) ||\n IsString(value) ||\n IsSymbol(value) ||\n IsUndefined(value)\n )\n}\n\n// ------------------------------------------------------------------\n// Clonable\n// ------------------------------------------------------------------\nfunction FromObject(value, exclude) {\n const Acc = {}\n for (const key of Object.getOwnPropertyNames(value)) {\n Acc[key] = Clone(value[key], exclude)\n }\n for (const key of Object.getOwnPropertySymbols(value)) {\n Acc[key] = Clone(value[key], exclude)\n }\n return Acc\n}\nfunction FromArray(value, exclude) {\n return value.map((element) => Clone(element, exclude))\n}\nfunction FromTypedArray(value) {\n return value.slice()\n}\nfunction FromMap(value, exclude) {\n return new Map(Clone([...value.entries()], exclude))\n}\nfunction FromSet(value, exclude) {\n return new Set(Clone([...value.entries()], exclude))\n}\nfunction FromDate(value) {\n return new Date(value.toISOString())\n}\nfunction FromValue(value) {\n return value\n}\n// ------------------------------------------------------------------\n// Clone\n// ------------------------------------------------------------------\n/** Returns a clone of the given value */\nexport function Clone(value, exclude?: Set<any>) {\n if (IsArray(value)) return FromArray(value, exclude)\n if (IsDate(value)) return FromDate(value)\n if (IsTypedArray(value)) return FromTypedArray(value)\n if (IsMap(value)) return FromMap(value, exclude)\n if (IsSet(value)) return FromSet(value, exclude)\n if (IsObject(value)) return FromObject(value, exclude)\n if (IsValueType(value)) return FromValue(value)\n if (exclude?.has(value.constructor)) return value\n throw new Error('Cannot clone value')\n}\n"],"names":["IsAsyncIterator","value","IsObject","Symbol","asyncIterator","IsIterator","iterator","IsStandardObject","Object","getPrototypeOf","prototype","IsInstanceObject","IsArray","IsFunction","constructor","name","IsPromise","Promise","IsDate","Date","Number","isFinite","getTime","IsMap","globalThis","Map","IsSet","Set","IsRegExp","RegExp","IsTypedArray","ArrayBuffer","isView","IsInt8Array","Int8Array","IsUint8Array","Uint8Array","IsUint8ClampedArray","Uint8ClampedArray","IsInt16Array","Int16Array","IsUint16Array","Uint16Array","IsInt32Array","Int32Array","IsUint32Array","Uint32Array","IsFloat32Array","Float32Array","IsFloat64Array","Float64Array","IsBigInt64Array","BigInt64Array","IsBigUint64Array","BigUint64Array","HasPropertyKey","key","Array","isArray","IsUndefined","undefined","IsNull","IsBoolean","IsNumber","IsInteger","isInteger","IsBigInt","IsString","IsSymbol","IsValueType","FromObject","exclude","Acc","getOwnPropertyNames","Clone","getOwnPropertySymbols","FromArray","map","element","FromTypedArray","slice","FromMap","entries","FromSet","FromDate","toISOString","FromValue","has","Error"],"mappings":"AAKA,OAAO,SAASA,gBAAgBC,KAAK;IACnC,OAAOC,SAASD,UAAUE,OAAOC,aAAa,IAAIH;AACpD;AAEA,OAAO,SAASI,WAAWJ,KAAK;IAC9B,OAAOC,SAASD,UAAUE,OAAOG,QAAQ,IAAIL;AAC/C;AAKA,OAAO,SAASM,iBAAiBN,KAAK;IACpC,OACEC,SAASD,UACRO,CAAAA,OAAOC,cAAc,CAACR,WAAWO,OAAOE,SAAS,IAChDF,OAAOC,cAAc,CAACR,WAAW,IAAG;AAE1C;AAEA,OAAO,SAASU,iBAAiBV,KAAK;IACpC,OACEC,SAASD,UACT,CAACW,QAAQX,UACTY,WAAWZ,MAAMa,WAAW,KAC5Bb,MAAMa,WAAW,CAACC,IAAI,KAAK;AAE/B;AAKA,OAAO,SAASC,UAAUf,KAAK;IAC7B,OAAOA,iBAAiBgB;AAC1B;AAEA,OAAO,SAASC,OAAOjB,KAAK;IAC1B,OAAOA,iBAAiBkB,QAAQC,OAAOC,QAAQ,CAACpB,MAAMqB,OAAO;AAC/D;AAEA,OAAO,SAASC,MAAMtB,KAAK;IACzB,OAAOA,iBAAiBuB,WAAWC,GAAG;AACxC;AAEA,OAAO,SAASC,MAAMzB,KAAK;IACzB,OAAOA,iBAAiBuB,WAAWG,GAAG;AACxC;AAEA,OAAO,SAASC,SAAS3B,KAAK;IAC5B,OAAOA,iBAAiBuB,WAAWK,MAAM;AAC3C;AAEA,OAAO,SAASC,aAAa7B,KAAK;IAChC,OAAO8B,YAAYC,MAAM,CAAC/B;AAC5B;AAEA,OAAO,SAASgC,YAAYhC,KAAK;IAC/B,OAAOA,iBAAiBuB,WAAWU,SAAS;AAC9C;AAEA,OAAO,SAASC,aAAalC,KAAK;IAChC,OAAOA,iBAAiBuB,WAAWY,UAAU;AAC/C;AAEA,OAAO,SAASC,oBAAoBpC,KAAK;IACvC,OAAOA,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