@sinclair/typebox 0.32.24 → 0.32.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/build/import/type/awaited/awaited.mjs +1 -1
  2. package/build/import/type/clone/value.mjs +8 -3
  3. package/build/import/type/composite/composite.mjs +14 -10
  4. package/build/import/type/const/const.mjs +4 -3
  5. package/build/import/type/deref/deref.d.mts +1 -1
  6. package/build/import/type/deref/deref.mjs +6 -4
  7. package/build/import/type/exclude/exclude-from-mapped-result.mjs +4 -3
  8. package/build/import/type/exclude/exclude.mjs +1 -1
  9. package/build/import/type/extends/extends-from-mapped-result.mjs +4 -3
  10. package/build/import/type/extends/extends.mjs +1 -1
  11. package/build/import/type/extract/extract-from-mapped-result.mjs +4 -3
  12. package/build/import/type/extract/extract.mjs +1 -1
  13. package/build/import/type/guard/index.d.mts +1 -0
  14. package/build/import/type/guard/index.mjs +1 -0
  15. package/build/import/type/guard/kind.d.mts +136 -0
  16. package/build/import/type/guard/kind.mjs +217 -0
  17. package/build/import/type/guard/type.d.mts +2 -2
  18. package/build/import/type/indexed/indexed-from-mapped-result.mjs +5 -3
  19. package/build/import/type/indexed/indexed-property-keys.mjs +5 -4
  20. package/build/import/type/indexed/indexed.mjs +1 -1
  21. package/build/import/type/intersect/intersect-create.mjs +1 -1
  22. package/build/import/type/intersect/intersect-evaluated.mjs +1 -2
  23. package/build/import/type/intersect/intersect.mjs +1 -1
  24. package/build/import/type/intrinsic/intrinsic.mjs +1 -1
  25. package/build/import/type/keyof/keyof-from-mapped-result.mjs +4 -3
  26. package/build/import/type/keyof/keyof-property-keys.mjs +5 -4
  27. package/build/import/type/keyof/keyof.mjs +1 -1
  28. package/build/import/type/mapped/mapped.d.mts +1 -1
  29. package/build/import/type/mapped/mapped.mjs +14 -12
  30. package/build/import/type/object/object.mjs +4 -2
  31. package/build/import/type/omit/omit-from-mapped-result.mjs +4 -3
  32. package/build/import/type/omit/omit.mjs +2 -4
  33. package/build/import/type/optional/optional-from-mapped-result.mjs +4 -3
  34. package/build/import/type/optional/optional.mjs +1 -1
  35. package/build/import/type/partial/partial-from-mapped-result.mjs +4 -3
  36. package/build/import/type/partial/partial.mjs +5 -4
  37. package/build/import/type/pick/pick-from-mapped-result.mjs +4 -3
  38. package/build/import/type/pick/pick.d.mts +1 -1
  39. package/build/import/type/pick/pick.mjs +6 -4
  40. package/build/import/type/readonly/readonly-from-mapped-result.mjs +4 -3
  41. package/build/import/type/readonly/readonly.mjs +1 -1
  42. package/build/import/type/record/record.mjs +5 -3
  43. package/build/import/type/required/required-from-mapped-result.mjs +4 -3
  44. package/build/import/type/required/required.mjs +5 -4
  45. package/build/import/type/rest/rest.mjs +4 -4
  46. package/build/import/type/sets/set.mjs +4 -1
  47. package/build/import/type/template-literal/pattern.mjs +1 -2
  48. package/build/import/type/transform/transform.mjs +1 -1
  49. package/build/import/type/union/union-evaluated.mjs +1 -1
  50. package/build/import/value/clean/clean.mjs +1 -1
  51. package/build/import/value/clone/clone.mjs +8 -2
  52. package/build/import/value/create/create.mjs +11 -7
  53. package/build/import/value/hash/hash.mjs +1 -1
  54. package/build/import/value/mutate/mutate.mjs +2 -2
  55. package/build/import/value/transform/decode.mjs +30 -30
  56. package/build/import/value/transform/encode.mjs +33 -30
  57. package/build/require/type/awaited/awaited.js +4 -4
  58. package/build/require/type/clone/value.js +8 -3
  59. package/build/require/type/composite/composite.js +15 -11
  60. package/build/require/type/const/const.js +4 -3
  61. package/build/require/type/deref/deref.d.ts +1 -1
  62. package/build/require/type/deref/deref.js +17 -15
  63. package/build/require/type/exclude/exclude-from-mapped-result.js +4 -3
  64. package/build/require/type/exclude/exclude.js +4 -4
  65. package/build/require/type/extends/extends-from-mapped-result.js +4 -3
  66. package/build/require/type/extends/extends.js +3 -3
  67. package/build/require/type/extract/extract-from-mapped-result.js +4 -3
  68. package/build/require/type/extract/extract.js +4 -4
  69. package/build/require/type/guard/index.d.ts +1 -0
  70. package/build/require/type/guard/index.js +2 -1
  71. package/build/require/type/guard/kind.d.ts +136 -0
  72. package/build/require/type/guard/kind.js +266 -0
  73. package/build/require/type/guard/type.d.ts +2 -2
  74. package/build/require/type/indexed/indexed-from-mapped-result.js +5 -3
  75. package/build/require/type/indexed/indexed-property-keys.js +10 -9
  76. package/build/require/type/indexed/indexed.js +11 -11
  77. package/build/require/type/intersect/intersect-create.js +4 -4
  78. package/build/require/type/intersect/intersect-evaluated.js +4 -5
  79. package/build/require/type/intersect/intersect.js +2 -2
  80. package/build/require/type/intrinsic/intrinsic.js +5 -5
  81. package/build/require/type/keyof/keyof-from-mapped-result.js +4 -3
  82. package/build/require/type/keyof/keyof-property-keys.js +11 -10
  83. package/build/require/type/keyof/keyof.js +2 -2
  84. package/build/require/type/mapped/mapped.d.ts +1 -1
  85. package/build/require/type/mapped/mapped.js +29 -27
  86. package/build/require/type/object/object.js +6 -4
  87. package/build/require/type/omit/omit-from-mapped-result.js +4 -3
  88. package/build/require/type/omit/omit.js +8 -10
  89. package/build/require/type/optional/optional-from-mapped-result.js +4 -3
  90. package/build/require/type/optional/optional.js +2 -2
  91. package/build/require/type/partial/partial-from-mapped-result.js +4 -3
  92. package/build/require/type/partial/partial.js +9 -8
  93. package/build/require/type/pick/pick-from-mapped-result.js +4 -3
  94. package/build/require/type/pick/pick.d.ts +1 -1
  95. package/build/require/type/pick/pick.js +12 -10
  96. package/build/require/type/readonly/readonly-from-mapped-result.js +4 -3
  97. package/build/require/type/readonly/readonly.js +2 -2
  98. package/build/require/type/record/record.js +12 -10
  99. package/build/require/type/required/required-from-mapped-result.js +4 -3
  100. package/build/require/type/required/required.js +9 -8
  101. package/build/require/type/rest/rest.js +4 -4
  102. package/build/require/type/sets/set.js +4 -1
  103. package/build/require/type/template-literal/pattern.js +9 -10
  104. package/build/require/type/transform/transform.js +2 -2
  105. package/build/require/type/union/union-evaluated.js +3 -3
  106. package/build/require/value/clean/clean.js +1 -1
  107. package/build/require/value/clone/clone.js +8 -2
  108. package/build/require/value/create/create.js +11 -7
  109. package/build/require/value/hash/hash.js +1 -1
  110. package/build/require/value/mutate/mutate.js +2 -2
  111. package/build/require/value/transform/decode.js +30 -30
  112. package/build/require/value/transform/encode.js +33 -30
  113. package/package.json +1 -1
  114. package/readme.md +4 -4
@@ -7,8 +7,7 @@ import { IntersectCreate } from './intersect-create.mjs';
7
7
  // ------------------------------------------------------------------
8
8
  // TypeGuard
9
9
  // ------------------------------------------------------------------
10
- // prettier-ignore
11
- import { IsOptional, IsTransform, } from '../guard/type.mjs';
10
+ import { IsOptional, IsTransform } from '../guard/kind.mjs';
12
11
  // prettier-ignore
13
12
  function IsIntersectOptional(T) {
14
13
  return T.every(L => IsOptional(L));
@@ -4,7 +4,7 @@ import { IntersectCreate } from './intersect-create.mjs';
4
4
  // ------------------------------------------------------------------
5
5
  // TypeGuard
6
6
  // ------------------------------------------------------------------
7
- import { IsTransform } from '../guard/type.mjs';
7
+ import { IsTransform } from '../guard/kind.mjs';
8
8
  /** `[Json]` Creates an evaluated Intersect type */
9
9
  export function Intersect(T, options = {}) {
10
10
  if (T.length === 0)
@@ -5,7 +5,7 @@ import { Union } from '../union/index.mjs';
5
5
  // ------------------------------------------------------------------
6
6
  // TypeGuard
7
7
  // ------------------------------------------------------------------
8
- import { IsMappedKey, IsTemplateLiteral, IsUnion, IsLiteral } from '../guard/type.mjs';
8
+ import { IsMappedKey, IsTemplateLiteral, IsUnion, IsLiteral } from '../guard/kind.mjs';
9
9
  // ------------------------------------------------------------------
10
10
  // Apply
11
11
  // ------------------------------------------------------------------
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
2
2
  import { KeyOf } from './keyof.mjs';
3
3
  // prettier-ignore
4
4
  function FromProperties(K, options) {
5
- return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => {
6
- return { ...Acc, [K2]: KeyOf(K[K2], options) };
7
- }, {});
5
+ const Acc = {};
6
+ for (const K2 of globalThis.Object.getOwnPropertyNames(K))
7
+ Acc[K2] = KeyOf(K[K2], options);
8
+ return Acc;
8
9
  }
9
10
  // prettier-ignore
10
11
  function FromMappedResult(R, options) {
@@ -2,12 +2,13 @@ import { SetUnionMany, SetIntersectMany } from '../sets/index.mjs';
2
2
  // ------------------------------------------------------------------
3
3
  // TypeGuard
4
4
  // ------------------------------------------------------------------
5
- import { IsIntersect, IsUnion, IsTuple, IsArray, IsObject, IsRecord } from '../guard/type.mjs';
5
+ import { IsIntersect, IsUnion, IsTuple, IsArray, IsObject, IsRecord } from '../guard/kind.mjs';
6
6
  // prettier-ignore
7
7
  function FromRest(T) {
8
- return T.reduce((Acc, L) => {
9
- return [...Acc, KeyOfPropertyKeys(L)];
10
- }, []);
8
+ const Acc = [];
9
+ for (const L of T)
10
+ Acc.push(KeyOfPropertyKeys(L));
11
+ return Acc;
11
12
  }
12
13
  // prettier-ignore
13
14
  function FromIntersect(T) {
@@ -7,7 +7,7 @@ import { KeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
7
7
  // ------------------------------------------------------------------
8
8
  // TypeGuard
9
9
  // ------------------------------------------------------------------
10
- import { IsMappedResult } from '../guard/type.mjs';
10
+ import { IsMappedResult } from '../guard/kind.mjs';
11
11
  // prettier-ignore
12
12
  export function KeyOfPropertyKeysToRest(T) {
13
13
  return T.map(L => L === '[number]' ? Number() : Literal(L));
@@ -36,7 +36,7 @@ declare function FromSchemaType<K extends PropertyKey, T extends TSchema>(K: K,
36
36
  export type TMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema, Acc extends TProperties = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TMappedFunctionReturnType<R, T, Acc & {
37
37
  [_ in L]: FromSchemaType<L, T>;
38
38
  }> : Acc);
39
- export declare function MappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T, Acc?: TProperties): TMappedFunctionReturnType<K, T>;
39
+ export declare function MappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T): TMappedFunctionReturnType<K, T>;
40
40
  export type TMappedFunction<K extends PropertyKey[], I = TMappedKey<K>> = (T: I) => TSchema;
41
41
  export type TMapped<K extends PropertyKey[], F extends TMappedFunction<K>, R extends TProperties = Evaluate<TMappedFunctionReturnType<K, ReturnType<F>>>> = Ensure<TObject<R>>;
42
42
  /** `[Json]` Creates a Mapped object type */
@@ -23,8 +23,7 @@ import { MappedResult } from './mapped-result.mjs';
23
23
  // ------------------------------------------------------------------
24
24
  // TypeGuard
25
25
  // ------------------------------------------------------------------
26
- // prettier-ignore
27
- import { IsArray, IsAsyncIterator, IsConstructor, IsFunction, IsIntersect, IsIterator, IsReadonly, IsMappedResult, IsMappedKey, IsObject, IsOptional, IsPromise, IsSchema, IsTuple, IsUnion, } from '../guard/type.mjs';
26
+ import { IsArray, IsAsyncIterator, IsConstructor, IsFunction, IsIntersect, IsIterator, IsReadonly, IsMappedResult, IsMappedKey, IsObject, IsOptional, IsPromise, IsSchema, IsTuple, IsUnion } from '../guard/kind.mjs';
28
27
  // prettier-ignore
29
28
  function FromMappedResult(K, P) {
30
29
  return (K in P
@@ -37,9 +36,10 @@ function MappedKeyToKnownMappedResultProperties(K) {
37
36
  }
38
37
  // prettier-ignore
39
38
  function MappedKeyToUnknownMappedResultProperties(P) {
40
- return P.reduce((Acc, L) => {
41
- return { ...Acc, [L]: Literal(L) };
42
- }, {});
39
+ const Acc = {};
40
+ for (const L of P)
41
+ Acc[L] = Literal(L);
42
+ return Acc;
43
43
  }
44
44
  // prettier-ignore
45
45
  function MappedKeyToMappedResultProperties(K, P) {
@@ -58,9 +58,10 @@ function FromRest(K, T) {
58
58
  }
59
59
  // prettier-ignore
60
60
  function FromProperties(K, T) {
61
- return globalThis.Object.getOwnPropertyNames(T).reduce((Acc, K2) => {
62
- return { ...Acc, [K2]: FromSchemaType(K, T[K2]) };
63
- }, {});
61
+ const Acc = {};
62
+ for (const K2 of globalThis.Object.getOwnPropertyNames(T))
63
+ Acc[K2] = FromSchemaType(K, T[K2]);
64
+ return Acc;
64
65
  }
65
66
  // prettier-ignore
66
67
  function FromSchemaType(K, T) {
@@ -85,10 +86,11 @@ function FromSchemaType(K, T) {
85
86
  T);
86
87
  }
87
88
  // prettier-ignore
88
- export function MappedFunctionReturnType(K, T, Acc = {}) {
89
- return K.reduce((Acc, L) => {
90
- return { ...Acc, [L]: FromSchemaType(L, T) };
91
- }, {});
89
+ export function MappedFunctionReturnType(K, T) {
90
+ const Acc = {};
91
+ for (const L of K)
92
+ Acc[L] = FromSchemaType(L, T);
93
+ return Acc;
92
94
  }
93
95
  /** `[Json]` Creates a Mapped object type */
94
96
  export function Mapped(key, map, options = {}) {
@@ -3,14 +3,16 @@ import { Kind } from '../symbols/index.mjs';
3
3
  // ------------------------------------------------------------------
4
4
  // TypeGuard
5
5
  // ------------------------------------------------------------------
6
- import { IsOptional, IsSchema } from '../guard/type.mjs';
6
+ import { IsOptional, IsSchema } from '../guard/kind.mjs';
7
7
  /** `[Json]` Creates an Object type */
8
8
  function _Object(properties, options = {}) {
9
9
  const propertyKeys = globalThis.Object.getOwnPropertyNames(properties);
10
10
  const optionalKeys = propertyKeys.filter((key) => IsOptional(properties[key]));
11
11
  const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
12
12
  const clonedAdditionalProperties = IsSchema(options.additionalProperties) ? { additionalProperties: CloneType(options.additionalProperties) } : {};
13
- const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: CloneType(properties[key]) }), {});
13
+ const clonedProperties = {};
14
+ for (const key of propertyKeys)
15
+ clonedProperties[key] = CloneType(properties[key]);
14
16
  return (requiredKeys.length > 0
15
17
  ? { ...options, ...clonedAdditionalProperties, [Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys }
16
18
  : { ...options, ...clonedAdditionalProperties, [Kind]: 'Object', type: 'object', properties: clonedProperties });
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
2
2
  import { Omit } from './omit.mjs';
3
3
  // prettier-ignore
4
4
  function FromProperties(P, K, options) {
5
- return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
6
- return { ...Acc, [K2]: Omit(P[K2], K, options) };
7
- }, {});
5
+ const Acc = {};
6
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
7
+ Acc[K2] = Omit(P[K2], K, options);
8
+ return Acc;
8
9
  }
9
10
  // prettier-ignore
10
11
  function FromMappedResult(R, K, options) {
@@ -10,7 +10,7 @@ import { OmitFromMappedResult } from './omit-from-mapped-result.mjs';
10
10
  // ------------------------------------------------------------------
11
11
  // TypeGuard
12
12
  // ------------------------------------------------------------------
13
- import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema, IsMappedResult } from '../guard/type.mjs';
13
+ import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema, IsMappedResult } from '../guard/kind.mjs';
14
14
  // prettier-ignore
15
15
  function FromIntersect(T, K) {
16
16
  return T.map((T) => OmitResolve(T, K));
@@ -29,9 +29,7 @@ function FromProperty(T, K) {
29
29
  }
30
30
  // prettier-ignore
31
31
  function FromProperties(T, K) {
32
- return K.reduce((T, K2) => {
33
- return FromProperty(T, K2);
34
- }, T);
32
+ return K.reduce((T, K2) => FromProperty(T, K2), T);
35
33
  }
36
34
  // ------------------------------------------------------------------
37
35
  // OmitResolve
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
2
2
  import { Optional } from './optional.mjs';
3
3
  // prettier-ignore
4
4
  function FromProperties(P, F) {
5
- return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
6
- return { ...Acc, [K2]: Optional(P[K2], F) };
7
- }, {});
5
+ const Acc = {};
6
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
7
+ Acc[K2] = Optional(P[K2], F);
8
+ return Acc;
8
9
  }
9
10
  // prettier-ignore
10
11
  function FromMappedResult(R, F) {
@@ -2,7 +2,7 @@ import { OptionalKind } from '../symbols/index.mjs';
2
2
  import { CloneType } from '../clone/type.mjs';
3
3
  import { Discard } from '../discard/index.mjs';
4
4
  import { OptionalFromMappedResult } from './optional-from-mapped-result.mjs';
5
- import { IsMappedResult } from '../guard/type.mjs';
5
+ import { IsMappedResult } from '../guard/kind.mjs';
6
6
  function RemoveOptional(schema) {
7
7
  return Discard(CloneType(schema), [OptionalKind]);
8
8
  }
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
2
2
  import { Partial } from './partial.mjs';
3
3
  // prettier-ignore
4
4
  function FromProperties(K, options) {
5
- return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => {
6
- return { ...Acc, [K2]: Partial(K[K2], options) };
7
- }, {});
5
+ const Acc = {};
6
+ for (const K2 of globalThis.Object.getOwnPropertyNames(K))
7
+ Acc[K2] = Partial(K[K2], options);
8
+ return Acc;
8
9
  }
9
10
  // prettier-ignore
10
11
  function FromMappedResult(R, options) {
@@ -9,16 +9,17 @@ import { PartialFromMappedResult } from './partial-from-mapped-result.mjs';
9
9
  // ------------------------------------------------------------------
10
10
  // TypeGuard
11
11
  // ------------------------------------------------------------------
12
- import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/type.mjs';
12
+ import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/kind.mjs';
13
13
  // prettier-ignore
14
14
  function FromRest(T) {
15
15
  return T.map(L => PartialResolve(L));
16
16
  }
17
17
  // prettier-ignore
18
18
  function FromProperties(T) {
19
- return globalThis.Object.getOwnPropertyNames(T).reduce((Acc, K) => {
20
- return { ...Acc, [K]: Optional(T[K]) };
21
- }, {});
19
+ const Acc = {};
20
+ for (const K of globalThis.Object.getOwnPropertyNames(T))
21
+ Acc[K] = Optional(T[K]);
22
+ return Acc;
22
23
  }
23
24
  // ------------------------------------------------------------------
24
25
  // PartialResolve
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
2
2
  import { Pick } from './pick.mjs';
3
3
  // prettier-ignore
4
4
  function FromProperties(P, K, options) {
5
- return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
6
- return { ...Acc, [K2]: Pick(P[K2], K, options) };
7
- }, {});
5
+ const Acc = {};
6
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
7
+ Acc[K2] = Pick(P[K2], K, options);
8
+ return Acc;
8
9
  }
9
10
  // prettier-ignore
10
11
  function FromMappedResult(R, K, options) {
@@ -13,7 +13,7 @@ declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T:
13
13
  type FromUnion<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? FromUnion<R, K, [...Acc, TPick<L, K>]> : Acc;
14
14
  declare function FromUnion<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromUnion<T, K, []>;
15
15
  type FromProperties<T extends TProperties, K extends PropertyKey[], I extends PropertyKey = TupleToUnion<K>> = Evaluate<Pick<T, I & keyof T>>;
16
- declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(T: T, K: K): {};
16
+ declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(T: T, K: K): never;
17
17
  export type TPick<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<TPick<S, K>> : T extends TIntersect<infer S> ? TIntersect<FromIntersect<S, K>> : T extends TUnion<infer S> ? TUnion<FromUnion<S, K>> : T extends TObject<infer S> ? TObject<FromProperties<S, K>> : TObject<{}>;
18
18
  /** `[Json]` Constructs a type whose keys are picked from the given type */
19
19
  export declare function Pick<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K], options?: SchemaOptions): TPickFromMappedResult<T, K>;
@@ -10,7 +10,7 @@ import { PickFromMappedResult } from './pick-from-mapped-result.mjs';
10
10
  // ------------------------------------------------------------------
11
11
  // TypeGuard
12
12
  // ------------------------------------------------------------------
13
- import { IsMappedKey, IsMappedResult, IsIntersect, IsUnion, IsObject, IsSchema } from '../guard/type.mjs';
13
+ import { IsMappedKey, IsMappedResult, IsIntersect, IsUnion, IsObject, IsSchema } from '../guard/kind.mjs';
14
14
  function FromIntersect(T, K) {
15
15
  return T.map((T) => PickResolve(T, K));
16
16
  }
@@ -20,9 +20,11 @@ function FromUnion(T, K) {
20
20
  }
21
21
  // prettier-ignore
22
22
  function FromProperties(T, K) {
23
- return K.reduce((Acc, K) => {
24
- return K in T ? { ...Acc, [K]: T[K] } : Acc;
25
- }, {});
23
+ const Acc = {};
24
+ for (const K2 of K)
25
+ if (K2 in T)
26
+ Acc[K2] = T[K2];
27
+ return Acc;
26
28
  }
27
29
  // ------------------------------------------------------------------
28
30
  // PickResolve
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
2
2
  import { Readonly } from './readonly.mjs';
3
3
  // prettier-ignore
4
4
  function FromProperties(K, F) {
5
- return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => {
6
- return { ...Acc, [K2]: Readonly(K[K2], F) };
7
- }, {});
5
+ const Acc = {};
6
+ for (const K2 of globalThis.Object.getOwnPropertyNames(K))
7
+ Acc[K2] = Readonly(K[K2], F);
8
+ return Acc;
8
9
  }
9
10
  // prettier-ignore
10
11
  function FromMappedResult(R, F) {
@@ -2,7 +2,7 @@ import { ReadonlyKind } from '../symbols/index.mjs';
2
2
  import { CloneType } from '../clone/type.mjs';
3
3
  import { Discard } from '../discard/index.mjs';
4
4
  import { ReadonlyFromMappedResult } from './readonly-from-mapped-result.mjs';
5
- import { IsMappedResult } from '../guard/type.mjs';
5
+ import { IsMappedResult } from '../guard/kind.mjs';
6
6
  function RemoveReadonly(schema) {
7
7
  return Discard(CloneType(schema), [ReadonlyKind]);
8
8
  }
@@ -13,7 +13,7 @@ import { IsUndefined } from '../guard/value.mjs';
13
13
  // ------------------------------------------------------------------
14
14
  // TypeGuard
15
15
  // ------------------------------------------------------------------
16
- import { IsInteger, IsLiteral, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion } from '../guard/type.mjs';
16
+ import { IsInteger, IsLiteral, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion } from '../guard/kind.mjs';
17
17
  // ------------------------------------------------------------------
18
18
  // RecordCreateFromPattern
19
19
  // ------------------------------------------------------------------
@@ -31,8 +31,10 @@ function RecordCreateFromPattern(pattern, T, options) {
31
31
  // ------------------------------------------------------------------
32
32
  // prettier-ignore
33
33
  function RecordCreateFromKeys(K, T, options) {
34
- const P = K.reduce((Acc, K) => ({ ...Acc, [K]: CloneType(T) }), {});
35
- return Object(P, { ...options, [Hint]: 'Record' });
34
+ const Acc = {};
35
+ for (const K2 of K)
36
+ Acc[K2] = CloneType(T);
37
+ return Object(Acc, { ...options, [Hint]: 'Record' });
36
38
  }
37
39
  // prettier-ignore
38
40
  function FromTemplateLiteralKey(K, T, options) {
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
2
2
  import { Required } from './required.mjs';
3
3
  // prettier-ignore
4
4
  function FromProperties(P, options) {
5
- return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
6
- return { ...Acc, [K2]: Required(P[K2], options) };
7
- }, {});
5
+ const Acc = {};
6
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
7
+ Acc[K2] = Required(P[K2], options);
8
+ return Acc;
8
9
  }
9
10
  // prettier-ignore
10
11
  function FromMappedResult(R, options) {
@@ -8,16 +8,17 @@ import { RequiredFromMappedResult } from './required-from-mapped-result.mjs';
8
8
  // ------------------------------------------------------------------
9
9
  // TypeGuard
10
10
  // ------------------------------------------------------------------
11
- import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/type.mjs';
11
+ import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/kind.mjs';
12
12
  // prettier-ignore
13
13
  function FromRest(T) {
14
14
  return T.map(L => RequiredResolve(L));
15
15
  }
16
16
  // prettier-ignore
17
17
  function FromProperties(T) {
18
- return globalThis.Object.getOwnPropertyNames(T).reduce((Acc, K) => {
19
- return { ...Acc, [K]: Discard(T[K], [OptionalKind]) };
20
- }, {});
18
+ const Acc = {};
19
+ for (const K of globalThis.Object.getOwnPropertyNames(T))
20
+ Acc[K] = Discard(T[K], [OptionalKind]);
21
+ return Acc;
21
22
  }
22
23
  // ------------------------------------------------------------------
23
24
  // RequiredResolve
@@ -2,12 +2,12 @@ import { CloneRest } from '../clone/type.mjs';
2
2
  // ------------------------------------------------------------------
3
3
  // TypeGuard
4
4
  // ------------------------------------------------------------------
5
- import { IsIntersect, IsUnion, IsTuple } from '../guard/type.mjs';
5
+ import { IsIntersect, IsUnion, IsTuple } from '../guard/kind.mjs';
6
6
  // prettier-ignore
7
7
  function RestResolve(T) {
8
- return (IsIntersect(T) ? [...T.allOf] :
9
- IsUnion(T) ? [...T.anyOf] :
10
- IsTuple(T) ? [...(T.items ?? [])] :
8
+ return (IsIntersect(T) ? CloneRest(T.allOf) :
9
+ IsUnion(T) ? CloneRest(T.anyOf) :
10
+ IsTuple(T) ? CloneRest(T.items ?? []) :
11
11
  []);
12
12
  }
13
13
  /** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
@@ -41,5 +41,8 @@ export function SetIntersectMany(T) {
41
41
  }
42
42
  /** Returns the Union of multiple sets */
43
43
  export function SetUnionMany(T) {
44
- return T.reduce((Acc, L) => [...Acc, ...L], []);
44
+ const Acc = [];
45
+ for (const L of T)
46
+ Acc.push(...L);
47
+ return Acc;
45
48
  }
@@ -4,8 +4,7 @@ import { TypeBoxError } from '../error/index.mjs';
4
4
  // ------------------------------------------------------------------
5
5
  // TypeGuard
6
6
  // ------------------------------------------------------------------
7
- // prettier-ignore
8
- import { IsTemplateLiteral, IsUnion, IsNumber, IsInteger, IsBigInt, IsString, IsLiteral, IsBoolean } from '../guard/type.mjs';
7
+ import { IsTemplateLiteral, IsUnion, IsNumber, IsInteger, IsBigInt, IsString, IsLiteral, IsBoolean } from '../guard/kind.mjs';
9
8
  // ------------------------------------------------------------------
10
9
  // TemplateLiteralPatternError
11
10
  // ------------------------------------------------------------------
@@ -3,7 +3,7 @@ import { CloneType } from '../clone/type.mjs';
3
3
  // ------------------------------------------------------------------
4
4
  // TypeGuard
5
5
  // ------------------------------------------------------------------
6
- import { IsTransform } from '../guard/type.mjs';
6
+ import { IsTransform } from '../guard/kind.mjs';
7
7
  // ------------------------------------------------------------------
8
8
  // TransformBuilders
9
9
  // ------------------------------------------------------------------
@@ -7,7 +7,7 @@ import { UnionCreate } from './union-create.mjs';
7
7
  // ------------------------------------------------------------------
8
8
  // TypeGuard
9
9
  // ------------------------------------------------------------------
10
- import { IsOptional } from '../guard/type.mjs';
10
+ import { IsOptional } from '../guard/kind.mjs';
11
11
  // prettier-ignore
12
12
  function IsUnionOptional(T) {
13
13
  return T.some(L => IsOptional(L));
@@ -64,7 +64,7 @@ function FromRecord(schema, references, value) {
64
64
  if (!IsObject(value))
65
65
  return value;
66
66
  const additionalProperties = schema.additionalProperties;
67
- const propertyKeys = Object.keys(value);
67
+ const propertyKeys = Object.getOwnPropertyNames(value);
68
68
  const [propertyKey, propertySchema] = Object.entries(schema.patternProperties)[0];
69
69
  const propertyKeyTest = new RegExp(propertyKey);
70
70
  for (const key of propertyKeys) {
@@ -6,8 +6,14 @@ import { IsArray, IsDate, IsStandardObject, IsTypedArray, IsValueType } from '..
6
6
  // Clonable
7
7
  // ------------------------------------------------------------------
8
8
  function ObjectType(value) {
9
- const keys = [...Object.getOwnPropertyNames(value), ...Object.getOwnPropertySymbols(value)];
10
- return keys.reduce((acc, key) => ({ ...acc, [key]: Clone(value[key]) }), {});
9
+ const Acc = {};
10
+ for (const key of Object.getOwnPropertyNames(value)) {
11
+ Acc[key] = Clone(value[key]);
12
+ }
13
+ for (const key of Object.getOwnPropertySymbols(value)) {
14
+ Acc[key] = Clone(value[key]);
15
+ }
16
+ return Acc;
11
17
  }
12
18
  function ArrayType(value) {
13
19
  return value.map((element) => Clone(element));
@@ -207,10 +207,13 @@ function FromObject(schema, references) {
207
207
  }
208
208
  else {
209
209
  const required = new Set(schema.required);
210
- return (FromDefault(schema.default) ||
211
- Object.entries(schema.properties).reduce((acc, [key, schema]) => {
212
- return required.has(key) ? { ...acc, [key]: Visit(schema, references) } : { ...acc };
213
- }, {}));
210
+ const Acc = {};
211
+ for (const [key, subschema] of Object.entries(schema.properties)) {
212
+ if (!required.has(key))
213
+ continue;
214
+ Acc[key] = Visit(subschema, references);
215
+ }
216
+ return Acc;
214
217
  }
215
218
  }
216
219
  function FromPromise(schema, references) {
@@ -228,9 +231,10 @@ function FromRecord(schema, references) {
228
231
  }
229
232
  else if (!(keyPattern === PatternStringExact || keyPattern === PatternNumberExact)) {
230
233
  const propertyKeys = keyPattern.slice(1, keyPattern.length - 1).split('|');
231
- return propertyKeys.reduce((acc, key) => {
232
- return { ...acc, [key]: Visit(valueSchema, references) };
233
- }, {});
234
+ const Acc = {};
235
+ for (const key of propertyKeys)
236
+ Acc[key] = Visit(valueSchema, references);
237
+ return Acc;
234
238
  }
235
239
  else {
236
240
  return {};
@@ -81,7 +81,7 @@ function NumberType(value) {
81
81
  }
82
82
  function ObjectType(value) {
83
83
  FNV1A64(ByteMarker.Object);
84
- for (const key of globalThis.Object.keys(value).sort()) {
84
+ for (const key of globalThis.Object.getOwnPropertyNames(value).sort()) {
85
85
  Visit(key);
86
86
  Visit(value[key]);
87
87
  }
@@ -15,8 +15,8 @@ function ObjectType(root, path, current, next) {
15
15
  ValuePointer.Set(root, path, Clone(next));
16
16
  }
17
17
  else {
18
- const currentKeys = Object.keys(current);
19
- const nextKeys = Object.keys(next);
18
+ const currentKeys = Object.getOwnPropertyNames(current);
19
+ const nextKeys = Object.getOwnPropertyNames(next);
20
20
  for (const currentKey of currentKeys) {
21
21
  if (!nextKeys.includes(currentKey)) {
22
22
  delete current[currentKey];