typebox 1.1.20 → 1.1.22

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 (210) hide show
  1. package/build/compile/compile.mjs +1 -0
  2. package/build/compile/validator.mjs +1 -1
  3. package/build/error/errors.mjs +1 -0
  4. package/build/format/iri-reference.mjs +1 -0
  5. package/build/format/uri-reference.mjs +1 -0
  6. package/build/guard/globals.d.mts +3 -3
  7. package/build/guard/guard.d.mts +1 -1
  8. package/build/schema/build.mjs +3 -3
  9. package/build/schema/engine/_functions.mjs +1 -1
  10. package/build/schema/engine/_guard.d.mts +3 -3
  11. package/build/schema/engine/_guard.mjs +3 -3
  12. package/build/schema/engine/_refine.d.mts +3 -3
  13. package/build/schema/engine/_refine.mjs +3 -3
  14. package/build/schema/engine/additionalProperties.d.mts +2 -2
  15. package/build/schema/engine/additionalProperties.mjs +2 -2
  16. package/build/schema/engine/anyOf.mjs +1 -1
  17. package/build/schema/engine/boolean.d.mts +2 -2
  18. package/build/schema/engine/boolean.mjs +2 -2
  19. package/build/schema/engine/const.d.mts +2 -2
  20. package/build/schema/engine/const.mjs +2 -2
  21. package/build/schema/engine/dependentRequired.d.mts +3 -3
  22. package/build/schema/engine/dependentRequired.mjs +3 -3
  23. package/build/schema/engine/enum.d.mts +2 -2
  24. package/build/schema/engine/enum.mjs +2 -2
  25. package/build/schema/engine/exclusiveMaximum.d.mts +2 -2
  26. package/build/schema/engine/exclusiveMaximum.mjs +2 -2
  27. package/build/schema/engine/exclusiveMinimum.d.mts +2 -2
  28. package/build/schema/engine/exclusiveMinimum.mjs +2 -2
  29. package/build/schema/engine/format.d.mts +2 -2
  30. package/build/schema/engine/format.mjs +2 -2
  31. package/build/schema/engine/maxItems.d.mts +2 -2
  32. package/build/schema/engine/maxItems.mjs +2 -2
  33. package/build/schema/engine/maxLength.d.mts +2 -2
  34. package/build/schema/engine/maxLength.mjs +2 -2
  35. package/build/schema/engine/maxProperties.d.mts +2 -2
  36. package/build/schema/engine/maxProperties.mjs +2 -2
  37. package/build/schema/engine/maximum.d.mts +2 -2
  38. package/build/schema/engine/maximum.mjs +2 -2
  39. package/build/schema/engine/minItems.d.mts +2 -2
  40. package/build/schema/engine/minItems.mjs +2 -2
  41. package/build/schema/engine/minLength.d.mts +2 -2
  42. package/build/schema/engine/minLength.mjs +2 -2
  43. package/build/schema/engine/minProperties.d.mts +2 -2
  44. package/build/schema/engine/minProperties.mjs +2 -2
  45. package/build/schema/engine/minimum.d.mts +2 -2
  46. package/build/schema/engine/minimum.mjs +2 -2
  47. package/build/schema/engine/multipleOf.d.mts +2 -2
  48. package/build/schema/engine/multipleOf.mjs +2 -2
  49. package/build/schema/engine/pattern.d.mts +2 -2
  50. package/build/schema/engine/pattern.mjs +2 -2
  51. package/build/schema/engine/recursiveRef.d.mts +1 -1
  52. package/build/schema/engine/recursiveRef.mjs +1 -1
  53. package/build/schema/engine/ref.d.mts +1 -1
  54. package/build/schema/engine/ref.mjs +1 -1
  55. package/build/schema/engine/required.d.mts +3 -3
  56. package/build/schema/engine/required.mjs +3 -3
  57. package/build/schema/engine/type.mjs +2 -2
  58. package/build/schema/engine/uniqueItems.d.mts +3 -3
  59. package/build/schema/engine/uniqueItems.mjs +3 -3
  60. package/build/schema/resolve/ref.mjs +1 -1
  61. package/build/schema/static/additionalProperties.mjs +1 -0
  62. package/build/schema/static/ref.mjs +1 -0
  63. package/build/schema/static/required.mjs +1 -0
  64. package/build/schema/static/static.mjs +1 -0
  65. package/build/schema/static/type.mjs +1 -0
  66. package/build/schema/static/unevaluatedProperties.mjs +1 -0
  67. package/build/system/environment/environment.d.mts +1 -1
  68. package/build/system/environment/environment.mjs +1 -1
  69. package/build/system/environment/evaluate.d.mts +9 -0
  70. package/build/system/environment/evaluate.mjs +37 -0
  71. package/build/system/memory/assign.mjs +1 -0
  72. package/build/system/memory/create.mjs +2 -1
  73. package/build/system/memory/discard.mjs +1 -0
  74. package/build/type/action/awaited.mjs +1 -0
  75. package/build/type/action/capitalize.mjs +1 -0
  76. package/build/type/action/conditional.mjs +1 -0
  77. package/build/type/action/constructor-parameters.mjs +1 -0
  78. package/build/type/action/evaluate.mjs +1 -0
  79. package/build/type/action/exclude.mjs +1 -0
  80. package/build/type/action/extract.mjs +1 -0
  81. package/build/type/action/indexed.mjs +1 -0
  82. package/build/type/action/instance-type.mjs +1 -0
  83. package/build/type/action/interface.mjs +1 -0
  84. package/build/type/action/keyof.mjs +1 -0
  85. package/build/type/action/lowercase.mjs +1 -0
  86. package/build/type/action/mapped.mjs +1 -0
  87. package/build/type/action/module.mjs +1 -0
  88. package/build/type/action/non-nullable.mjs +1 -0
  89. package/build/type/action/omit.mjs +1 -0
  90. package/build/type/action/options.mjs +1 -0
  91. package/build/type/action/parameters.mjs +1 -0
  92. package/build/type/action/partial.mjs +1 -0
  93. package/build/type/action/pick.mjs +1 -0
  94. package/build/type/action/readonly-type.mjs +1 -0
  95. package/build/type/action/required.mjs +1 -0
  96. package/build/type/action/return-type.mjs +1 -0
  97. package/build/type/action/uncapitalize.mjs +1 -0
  98. package/build/type/action/uppercase.mjs +1 -0
  99. package/build/type/engine/constructor-parameters/instantiate.mjs +1 -0
  100. package/build/type/engine/cyclic/extends.mjs +4 -4
  101. package/build/type/engine/cyclic/instantiate.mjs +1 -0
  102. package/build/type/engine/evaluate/broaden.mjs +1 -1
  103. package/build/type/engine/evaluate/compare.mjs +1 -0
  104. package/build/type/engine/exclude/instantiate.mjs +1 -0
  105. package/build/type/engine/extract/instantiate.mjs +1 -0
  106. package/build/type/engine/helpers/union.mjs +1 -0
  107. package/build/type/engine/indexed/from-array.mjs +1 -0
  108. package/build/type/engine/indexed/from-tuple.mjs +1 -0
  109. package/build/type/engine/interface/instantiate.mjs +1 -1
  110. package/build/type/engine/mapped/instantiate.mjs +1 -0
  111. package/build/type/engine/module/instantiate.mjs +1 -0
  112. package/build/type/engine/non-nullable/instantiate.mjs +1 -0
  113. package/build/type/engine/object/from-intersect.mjs +1 -0
  114. package/build/type/engine/object/from-type.mjs +1 -0
  115. package/build/type/engine/parameters/instantiate.mjs +1 -0
  116. package/build/type/engine/partial/from-type.mjs +1 -0
  117. package/build/type/engine/pick/instantiate.mjs +1 -0
  118. package/build/type/engine/record/from-key-integer.d.mts +2 -2
  119. package/build/type/engine/record/from-key-integer.mjs +1 -1
  120. package/build/type/engine/record/from-key-number.d.mts +1 -1
  121. package/build/type/engine/record/from-key-number.mjs +1 -1
  122. package/build/type/engine/required/from-type.mjs +1 -0
  123. package/build/type/engine/template-literal/encode.mjs +1 -1
  124. package/build/type/engine/template-literal/is-finite.mjs +1 -1
  125. package/build/type/engine/tuple/to-object.mjs +1 -0
  126. package/build/type/extends/extends-right.d.mts +1 -1
  127. package/build/type/extends/extends-right.mjs +1 -1
  128. package/build/type/extends/inference.mjs +1 -0
  129. package/build/type/extends/object.mjs +1 -0
  130. package/build/type/types/_codec.d.mts +1 -1
  131. package/build/type/types/_codec.mjs +1 -0
  132. package/build/type/types/base.d.mts +2 -2
  133. package/build/type/types/base.mjs +2 -2
  134. package/build/type/types/call.mjs +1 -0
  135. package/build/type/types/never.mjs +1 -0
  136. package/build/type/types/properties.mjs +0 -1
  137. package/build/type/types/record.mjs +1 -0
  138. package/build/type/types/ref.mjs +1 -0
  139. package/build/value/clean/from-base.d.mts +1 -1
  140. package/build/value/clean/from-base.mjs +1 -1
  141. package/build/value/codec/callback.mjs +2 -2
  142. package/build/value/codec/from-union.mjs +1 -1
  143. package/build/value/convert/from-array.mjs +3 -4
  144. package/build/value/convert/from-base.d.mts +1 -1
  145. package/build/value/convert/from-base.mjs +1 -1
  146. package/build/value/convert/from-bigint.d.mts +1 -1
  147. package/build/value/convert/from-bigint.mjs +1 -4
  148. package/build/value/convert/from-boolean.d.mts +1 -1
  149. package/build/value/convert/from-boolean.mjs +1 -4
  150. package/build/value/convert/from-integer.d.mts +1 -1
  151. package/build/value/convert/from-integer.mjs +1 -4
  152. package/build/value/convert/from-literal.mjs +4 -4
  153. package/build/value/convert/from-null.d.mts +1 -1
  154. package/build/value/convert/from-null.mjs +1 -4
  155. package/build/value/convert/from-number.d.mts +1 -1
  156. package/build/value/convert/from-number.mjs +1 -4
  157. package/build/value/convert/from-string.d.mts +1 -1
  158. package/build/value/convert/from-string.mjs +1 -4
  159. package/build/value/convert/from-type.d.mts +2 -2
  160. package/build/value/convert/from-type.mjs +21 -21
  161. package/build/value/convert/from-undefined.d.mts +1 -1
  162. package/build/value/convert/from-undefined.mjs +1 -4
  163. package/build/value/convert/from-void.d.mts +1 -1
  164. package/build/value/convert/from-void.mjs +1 -4
  165. package/build/value/convert/try/try-array.d.mts +2 -0
  166. package/build/value/convert/try/try-array.mjs +6 -0
  167. package/build/value/convert/try/try-bigint.mjs +4 -33
  168. package/build/value/convert/try/try-boolean.mjs +3 -26
  169. package/build/value/convert/try/try-null.mjs +2 -19
  170. package/build/value/convert/try/try-number.mjs +6 -38
  171. package/build/value/convert/try/try-result.mjs +0 -1
  172. package/build/value/convert/try/try-string.mjs +6 -50
  173. package/build/value/convert/try/try-undefined.mjs +2 -19
  174. package/build/value/convert/try/try.d.mts +1 -0
  175. package/build/value/convert/try/try.mjs +1 -0
  176. package/build/value/create/from-async-iterator.d.mts +1 -1
  177. package/build/value/create/from-async-iterator.mjs +1 -1
  178. package/build/value/create/from-base.d.mts +1 -1
  179. package/build/value/create/from-base.mjs +1 -1
  180. package/build/value/create/from-bigint.d.mts +1 -1
  181. package/build/value/create/from-bigint.mjs +1 -1
  182. package/build/value/create/from-boolean.d.mts +1 -1
  183. package/build/value/create/from-boolean.mjs +1 -1
  184. package/build/value/create/from-default.d.mts +1 -1
  185. package/build/value/create/from-default.mjs +1 -1
  186. package/build/value/create/from-integer.d.mts +1 -1
  187. package/build/value/create/from-integer.mjs +1 -1
  188. package/build/value/create/from-iterator.d.mts +1 -1
  189. package/build/value/create/from-iterator.mjs +1 -1
  190. package/build/value/create/from-literal.d.mts +1 -1
  191. package/build/value/create/from-literal.mjs +1 -1
  192. package/build/value/create/from-never.d.mts +1 -1
  193. package/build/value/create/from-never.mjs +1 -1
  194. package/build/value/create/from-null.d.mts +1 -1
  195. package/build/value/create/from-null.mjs +1 -1
  196. package/build/value/create/from-number.d.mts +1 -1
  197. package/build/value/create/from-number.mjs +1 -1
  198. package/build/value/create/from-record.d.mts +1 -1
  199. package/build/value/create/from-record.mjs +1 -1
  200. package/build/value/create/from-string.d.mts +1 -1
  201. package/build/value/create/from-string.mjs +1 -1
  202. package/build/value/create/from-symbol.d.mts +1 -1
  203. package/build/value/create/from-symbol.mjs +1 -1
  204. package/build/value/create/from-undefined.d.mts +1 -1
  205. package/build/value/create/from-undefined.mjs +1 -1
  206. package/build/value/create/from-void.d.mts +1 -1
  207. package/build/value/create/from-void.mjs +1 -1
  208. package/package.json +1 -1
  209. package/build/system/environment/can-evaluate.d.mts +0 -2
  210. package/build/system/environment/can-evaluate.mjs +0 -26
@@ -1,5 +1,4 @@
1
1
  // deno-fmt-ignore-file
2
- // deno-lint-ignore-file
3
2
  import { Guard } from '../../../guard/index.mjs';
4
3
  import { Ok, Fail } from './try-result.mjs';
5
4
  // ------------------------------------------------------------------
@@ -11,14 +10,6 @@ function FromBigInt(value) {
11
10
  Fail());
12
11
  }
13
12
  // ------------------------------------------------------------------
14
- // Boolean
15
- // ------------------------------------------------------------------
16
- // deno-coverage-ignore-start - unreachable | guarded
17
- function FromBoolean(value) {
18
- return Ok(value);
19
- }
20
- // deno-coverage-ignore-stop
21
- // ------------------------------------------------------------------
22
13
  // Number
23
14
  // ------------------------------------------------------------------
24
15
  function FromNumber(value) {
@@ -27,12 +18,6 @@ function FromNumber(value) {
27
18
  Fail());
28
19
  }
29
20
  // ------------------------------------------------------------------
30
- // Null
31
- // ------------------------------------------------------------------
32
- function FromNull(value) {
33
- return Ok(false);
34
- }
35
- // ------------------------------------------------------------------
36
21
  // String
37
22
  // ------------------------------------------------------------------
38
23
  function FromString(value) {
@@ -43,22 +28,14 @@ function FromString(value) {
43
28
  Fail());
44
29
  }
45
30
  // ------------------------------------------------------------------
46
- // Undefined
47
- // ------------------------------------------------------------------
48
- function FromUndefined(value) {
49
- return Ok(false);
50
- }
51
- // ------------------------------------------------------------------
52
31
  // Try
53
32
  // ------------------------------------------------------------------
54
- // deno-coverage-ignore-start - unreachable | guarded
55
33
  export function TryBoolean(value) {
56
34
  return (Guard.IsBigInt(value) ? FromBigInt(value) :
57
- Guard.IsBoolean(value) ? FromBoolean(value) :
35
+ Guard.IsBoolean(value) ? Ok(value) :
58
36
  Guard.IsNumber(value) ? FromNumber(value) :
59
- Guard.IsNull(value) ? FromNull(value) :
37
+ Guard.IsNull(value) ? Ok(false) :
60
38
  Guard.IsString(value) ? FromString(value) :
61
- Guard.IsUndefined(value) ? FromUndefined(value) :
39
+ Guard.IsUndefined(value) ? Ok(false) :
62
40
  Fail());
63
41
  }
64
- // deno-coverage-ignore-stop
@@ -1,5 +1,4 @@
1
1
  // deno-fmt-ignore-file
2
- // deno-lint-ignore-file
3
2
  import { Guard } from '../../../guard/index.mjs';
4
3
  import { Ok, Fail } from './try-result.mjs';
5
4
  // ------------------------------------------------------------------
@@ -21,14 +20,6 @@ function FromNumber(value) {
21
20
  return Guard.IsEqual(value, 0) ? Ok(null) : Fail();
22
21
  }
23
22
  // ------------------------------------------------------------------
24
- // Null
25
- // ------------------------------------------------------------------
26
- // deno-coverage-ignore-start - unreachable | guarded
27
- function FromNull(value) {
28
- return Ok(null);
29
- }
30
- // deno-coverage-ignore-stop
31
- // ------------------------------------------------------------------
32
23
  // String
33
24
  // ------------------------------------------------------------------
34
25
  function FromString(value) {
@@ -40,22 +31,14 @@ function FromString(value) {
40
31
  return predicate ? Ok(null) : Fail();
41
32
  }
42
33
  // ------------------------------------------------------------------
43
- // Undefined
44
- // ------------------------------------------------------------------
45
- function FromUndefined(value) {
46
- return Ok(null);
47
- }
48
- // ------------------------------------------------------------------
49
34
  // Try
50
35
  // ------------------------------------------------------------------
51
- // deno-coverage-ignore-start - unreachable | guarded
52
36
  export function TryNull(value) {
53
37
  return (Guard.IsBigInt(value) ? FromBigInt(value) :
54
38
  Guard.IsBoolean(value) ? FromBoolean(value) :
55
39
  Guard.IsNumber(value) ? FromNumber(value) :
56
- Guard.IsNull(value) ? FromNull(value) :
40
+ Guard.IsNull(value) ? Ok(null) :
57
41
  Guard.IsString(value) ? FromString(value) :
58
- Guard.IsUndefined(value) ? FromUndefined(value) :
42
+ Guard.IsUndefined(value) ? Ok(null) :
59
43
  Fail());
60
44
  }
61
- // deno-coverage-ignore-stop
@@ -1,41 +1,17 @@
1
1
  // deno-fmt-ignore-file
2
- // deno-lint-ignore-file
3
2
  import { Guard } from '../../../guard/index.mjs';
4
3
  import { Ok, Fail, IsOk } from './try-result.mjs';
5
- // ------------------------------------------------------------------
6
- // Two-Phase
7
- // ------------------------------------------------------------------
8
4
  import { TryBigInt } from './try-bigint.mjs';
9
5
  // ------------------------------------------------------------------
10
6
  // BigInt
11
7
  // ------------------------------------------------------------------
12
8
  const maxBigInt = BigInt(Number.MAX_SAFE_INTEGER);
13
9
  const minBigInt = BigInt(Number.MIN_SAFE_INTEGER);
14
- function CanBigIntDowncast(value) {
15
- return (value <= maxBigInt && value >= minBigInt);
16
- }
17
10
  function FromBigInt(value) {
18
- return CanBigIntDowncast(value) ? Ok(Number(value)) : Fail();
11
+ return (value <= maxBigInt && value >= minBigInt) ? Ok(Number(value)) : Fail();
19
12
  }
20
- // ------------------------------------------------------------------
21
- // Boolean
22
- // ------------------------------------------------------------------
23
13
  function FromBoolean(value) {
24
- return value ? Ok(1) : Ok(0);
25
- }
26
- // ------------------------------------------------------------------
27
- // Number
28
- // ------------------------------------------------------------------
29
- // deno-coverage-ignore-start - unreachable | guarded
30
- function FromNumber(value) {
31
- return Ok(value);
32
- }
33
- // deno-coverage-ignore-stop
34
- // ------------------------------------------------------------------
35
- // Null
36
- // ------------------------------------------------------------------
37
- function FromNull(value) {
38
- return Ok(0);
14
+ return Ok(value ? 1 : 0);
39
15
  }
40
16
  // ------------------------------------------------------------------
41
17
  // String
@@ -51,26 +27,18 @@ function FromString(value) {
51
27
  return Ok(1);
52
28
  const result = TryBigInt(value);
53
29
  if (IsOk(result))
54
- return FromBigInt(result.value);
30
+ return (result.value <= maxBigInt && result.value >= minBigInt) ? Ok(Number(result.value)) : Fail();
55
31
  return Fail();
56
32
  }
57
33
  // ------------------------------------------------------------------
58
- // Undefined
59
- // ------------------------------------------------------------------
60
- function FromUndefined(value) {
61
- return Ok(0);
62
- }
63
- // ------------------------------------------------------------------
64
34
  // Try
65
35
  // ------------------------------------------------------------------
66
- // deno-coverage-ignore-start - unreachable | guarded
67
36
  export function TryNumber(value) {
68
37
  return (Guard.IsBigInt(value) ? FromBigInt(value) :
69
38
  Guard.IsBoolean(value) ? FromBoolean(value) :
70
- Guard.IsNumber(value) ? FromNumber(value) :
71
- Guard.IsNull(value) ? FromNull(value) :
39
+ Guard.IsNumber(value) ? Ok(value) :
40
+ Guard.IsNull(value) ? Ok(0) :
72
41
  Guard.IsString(value) ? FromString(value) :
73
- Guard.IsUndefined(value) ? FromUndefined(value) :
42
+ Guard.IsUndefined(value) ? Ok(0) :
74
43
  Fail());
75
44
  }
76
- // deno-coverage-ignore-stop
@@ -1,5 +1,4 @@
1
1
  // deno-fmt-ignore-file
2
- // deno-lint-ignore-file
3
2
  import { Guard } from '../../../guard/index.mjs';
4
3
  // ------------------------------------------------------------------
5
4
  // Guard
@@ -1,56 +1,12 @@
1
1
  // deno-fmt-ignore-file
2
- // deno-lint-ignore-file
3
2
  import { Guard } from '../../../guard/index.mjs';
4
3
  import { Ok, Fail } from './try-result.mjs';
5
- // ------------------------------------------------------------------
6
- // BigInt
7
- // ------------------------------------------------------------------
8
- function FromBigInt(value) {
9
- return Ok(value.toString());
10
- }
11
- // ------------------------------------------------------------------
12
- // Boolean
13
- // ------------------------------------------------------------------
14
- function FromBoolean(value) {
15
- return Ok(value.toString());
16
- }
17
- // ------------------------------------------------------------------
18
- // Number
19
- // ------------------------------------------------------------------
20
- function FromNumber(value) {
21
- return Ok(value.toString());
22
- }
23
- // ------------------------------------------------------------------
24
- // Null
25
- // ------------------------------------------------------------------
26
- function FromNull(value) {
27
- return Ok('null');
28
- }
29
- // ------------------------------------------------------------------
30
- // String
31
- // ------------------------------------------------------------------
32
- // deno-coverage-ignore-start - unreachable | guarded
33
- function FromString(value) {
34
- return Ok(value);
35
- }
36
- // deno-coverage-ignore-stop
37
- // ------------------------------------------------------------------
38
- // Undefined
39
- // ------------------------------------------------------------------
40
- function FromUndefined(value) {
41
- return Ok('');
42
- }
43
- // ------------------------------------------------------------------
44
- // Try
45
- // ------------------------------------------------------------------
46
- // deno-coverage-ignore-start - unreachable | guarded
47
4
  export function TryString(value) {
48
- return (Guard.IsBigInt(value) ? FromBigInt(value) :
49
- Guard.IsBoolean(value) ? FromBoolean(value) :
50
- Guard.IsNumber(value) ? FromNumber(value) :
51
- Guard.IsNull(value) ? FromNull(value) :
52
- Guard.IsString(value) ? FromString(value) :
53
- Guard.IsUndefined(value) ? FromUndefined(value) :
5
+ return (Guard.IsBigInt(value) ? Ok(value.toString()) :
6
+ Guard.IsBoolean(value) ? Ok(value.toString()) :
7
+ Guard.IsNumber(value) ? Ok(value.toString()) :
8
+ Guard.IsNull(value) ? Ok('null') :
9
+ Guard.IsString(value) ? Ok(value) :
10
+ Guard.IsUndefined(value) ? Ok('') :
54
11
  Fail());
55
12
  }
56
- // deno-coverage-ignore-stop
@@ -1,5 +1,4 @@
1
1
  // deno-fmt-ignore-file
2
- // deno-lint-ignore-file
3
2
  import { Guard } from '../../../guard/index.mjs';
4
3
  import { Ok, Fail } from './try-result.mjs';
5
4
  // ------------------------------------------------------------------
@@ -21,12 +20,6 @@ function FromNumber(value) {
21
20
  return Guard.IsEqual(value, 0) ? Ok(undefined) : Fail();
22
21
  }
23
22
  // ------------------------------------------------------------------
24
- // Null
25
- // ------------------------------------------------------------------
26
- function FromNull(value) {
27
- return Ok(undefined);
28
- }
29
- // ------------------------------------------------------------------
30
23
  // String
31
24
  // ------------------------------------------------------------------
32
25
  function FromString(value) {
@@ -38,24 +31,14 @@ function FromString(value) {
38
31
  return predicate ? Ok(undefined) : Fail();
39
32
  }
40
33
  // ------------------------------------------------------------------
41
- // Undefined
42
- // ------------------------------------------------------------------
43
- // deno-coverage-ignore-start - unreachable | guarded
44
- function FromUndefined(value) {
45
- return Ok(undefined);
46
- }
47
- // deno-coverage-ignore-stop
48
- // ------------------------------------------------------------------
49
34
  // Try
50
35
  // ------------------------------------------------------------------
51
- // deno-coverage-ignore-start - unreachable | guarded
52
36
  export function TryUndefined(value) {
53
37
  return (Guard.IsBigInt(value) ? FromBigInt(value) :
54
38
  Guard.IsBoolean(value) ? FromBoolean(value) :
55
39
  Guard.IsNumber(value) ? FromNumber(value) :
56
- Guard.IsNull(value) ? FromNull(value) :
40
+ Guard.IsNull(value) ? Ok(undefined) :
57
41
  Guard.IsString(value) ? FromString(value) :
58
- Guard.IsUndefined(value) ? FromUndefined(value) :
42
+ Guard.IsUndefined(value) ? Ok(value) :
59
43
  Fail());
60
44
  }
61
- // deno-coverage-ignore-stop
@@ -1,3 +1,4 @@
1
+ export * from './try-array.mjs';
1
2
  export * from './try-bigint.mjs';
2
3
  export * from './try-boolean.mjs';
3
4
  export * from './try-null.mjs';
@@ -1,3 +1,4 @@
1
+ export * from './try-array.mjs';
1
2
  export * from './try-bigint.mjs';
2
3
  export * from './try-boolean.mjs';
3
4
  export * from './try-null.mjs';
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TAsyncIterator } from '../../type/index.mjs';
2
- export declare function FromAsyncIterator(context: TProperties, type: TAsyncIterator): unknown;
2
+ export declare function FromAsyncIterator(_context: TProperties, _type: TAsyncIterator): unknown;
@@ -1,5 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
2
  async function* CreateAsyncIterator() { }
3
- export function FromAsyncIterator(context, type) {
3
+ export function FromAsyncIterator(_context, _type) {
4
4
  return CreateAsyncIterator();
5
5
  }
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, Base } from '../../type/index.mjs';
2
- export declare function FromBase(context: TProperties, type: Base): unknown;
2
+ export declare function FromBase(_context: TProperties, type: Base): unknown;
@@ -1,4 +1,4 @@
1
1
  // deno-fmt-ignore-file
2
- export function FromBase(context, type) {
2
+ export function FromBase(_context, type) {
3
3
  return type.Create();
4
4
  }
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TBigInt } from '../../type/index.mjs';
2
- export declare function FromBigInt(context: TProperties, type: TBigInt): unknown;
2
+ export declare function FromBigInt(_context: TProperties, type: TBigInt): unknown;
@@ -1,6 +1,6 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { IsExclusiveMinimum, IsMinimum } from '../../schema/types/index.mjs';
3
- export function FromBigInt(context, type) {
3
+ export function FromBigInt(_context, type) {
4
4
  return (IsExclusiveMinimum(type) ? BigInt(type.exclusiveMinimum) + BigInt(1) :
5
5
  IsMinimum(type) ? BigInt(type.minimum) :
6
6
  BigInt(0));
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TBoolean } from '../../type/index.mjs';
2
- export declare function FromBoolean(context: TProperties, type: TBoolean): unknown;
2
+ export declare function FromBoolean(_context: TProperties, _type: TBoolean): unknown;
@@ -1,4 +1,4 @@
1
1
  // deno-fmt-ignore-file
2
- export function FromBoolean(context, type) {
2
+ export function FromBoolean(_context, _type) {
3
3
  return false;
4
4
  }
@@ -1,3 +1,3 @@
1
1
  import { type TProperties } from '../../type/index.mjs';
2
2
  import { type XDefault } from '../../schema/types/index.mjs';
3
- export declare function FromDefault(context: TProperties, schema: XDefault): unknown;
3
+ export declare function FromDefault(_context: TProperties, schema: XDefault): unknown;
@@ -1,7 +1,7 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { Guard } from '../../guard/index.mjs';
3
3
  import { Clone } from '../clone/index.mjs';
4
- export function FromDefault(context, schema) {
4
+ export function FromDefault(_context, schema) {
5
5
  return Guard.IsFunction(schema.default)
6
6
  ? schema.default(schema)
7
7
  : Guard.IsObject(schema.default)
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TInteger } from '../../type/index.mjs';
2
- export declare function FromInteger(context: TProperties, type: TInteger): unknown;
2
+ export declare function FromInteger(_context: TProperties, type: TInteger): unknown;
@@ -1,7 +1,7 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { Guard } from '../../guard/index.mjs';
3
3
  import { IsExclusiveMinimum, IsMinimum } from '../../schema/types/index.mjs';
4
- export function FromInteger(context, type) {
4
+ export function FromInteger(_context, type) {
5
5
  return ((IsExclusiveMinimum(type) && Guard.IsNumber(type.exclusiveMinimum)) ? type.exclusiveMinimum + 1 :
6
6
  IsMinimum(type) ? type.minimum :
7
7
  0);
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TIterator } from '../../type/index.mjs';
2
- export declare function FromIterator(context: TProperties, type: TIterator): unknown;
2
+ export declare function FromIterator(_context: TProperties, _type: TIterator): unknown;
@@ -1,5 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
2
  function* CreateIterator() { }
3
- export function FromIterator(context, type) {
3
+ export function FromIterator(_context, _type) {
4
4
  return CreateIterator();
5
5
  }
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TLiteral } from '../../type/index.mjs';
2
- export declare function FromLiteral(context: TProperties, type: TLiteral): unknown;
2
+ export declare function FromLiteral(_context: TProperties, type: TLiteral): unknown;
@@ -1,4 +1,4 @@
1
1
  // deno-fmt-ignore-file
2
- export function FromLiteral(context, type) {
2
+ export function FromLiteral(_context, type) {
3
3
  return type.const;
4
4
  }
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TNever } from '../../type/index.mjs';
2
- export declare function FromNever(context: TProperties, type: TNever): unknown;
2
+ export declare function FromNever(_context: TProperties, type: TNever): unknown;
@@ -1,5 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { CreateError } from './error.mjs';
3
- export function FromNever(context, type) {
3
+ export function FromNever(_context, type) {
4
4
  throw new CreateError(type, 'Cannot create TNever types');
5
5
  }
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TNull } from '../../type/index.mjs';
2
- export declare function FromNull(context: TProperties, type: TNull): unknown;
2
+ export declare function FromNull(_context: TProperties, _type: TNull): unknown;
@@ -1,4 +1,4 @@
1
1
  // deno-fmt-ignore-file
2
- export function FromNull(context, type) {
2
+ export function FromNull(_context, _type) {
3
3
  return null;
4
4
  }
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TNumber } from '../../type/index.mjs';
2
- export declare function FromNumber(context: TProperties, type: TNumber): unknown;
2
+ export declare function FromNumber(_context: TProperties, type: TNumber): unknown;
@@ -1,7 +1,7 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { Guard } from '../../guard/index.mjs';
3
3
  import { IsExclusiveMinimum, IsMinimum } from '../../schema/types/index.mjs';
4
- export function FromNumber(context, type) {
4
+ export function FromNumber(_context, type) {
5
5
  return (IsExclusiveMinimum(type) && Guard.IsNumber(type.exclusiveMinimum) ? type.exclusiveMinimum + 1 :
6
6
  IsMinimum(type) ? type.minimum :
7
7
  0);
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TRecord } from '../../type/index.mjs';
2
- export declare function FromRecord(context: TProperties, type: TRecord): unknown;
2
+ export declare function FromRecord(_context: TProperties, type: TRecord): unknown;
@@ -1,7 +1,7 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { IsMinProperties, IsDefault } from '../../schema/types/index.mjs';
3
3
  import { CreateError } from './error.mjs';
4
- export function FromRecord(context, type) {
4
+ export function FromRecord(_context, type) {
5
5
  if (IsMinProperties(type) && !IsDefault(type))
6
6
  throw new CreateError(type, 'Record with the minProperties constraint must have a default annotation');
7
7
  return {};
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TString } from '../../type/index.mjs';
2
- export declare function FromString(context: TProperties, type: TString): unknown;
2
+ export declare function FromString(_context: TProperties, type: TString): unknown;
@@ -1,6 +1,6 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { IsPattern, IsFormat, IsDefault, IsMinLength } from '../../schema/types/index.mjs';
3
- export function FromString(context, type) {
3
+ export function FromString(_context, type) {
4
4
  const needsDefault = (IsPattern(type) || IsFormat(type)) && !IsDefault(type);
5
5
  if (needsDefault)
6
6
  throw Error('Strings with format or pattern constraints must specify default');
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TSymbol } from '../../type/index.mjs';
2
- export declare function FromSymbol(context: TProperties, type: TSymbol): unknown;
2
+ export declare function FromSymbol(_context: TProperties, _type: TSymbol): unknown;
@@ -1,4 +1,4 @@
1
1
  // deno-fmt-ignore-file
2
- export function FromSymbol(context, type) {
2
+ export function FromSymbol(_context, _type) {
3
3
  return Symbol();
4
4
  }
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TUndefined } from '../../type/index.mjs';
2
- export declare function FromUndefined(context: TProperties, type: TUndefined): unknown;
2
+ export declare function FromUndefined(_context: TProperties, _type: TUndefined): unknown;
@@ -1,4 +1,4 @@
1
1
  // deno-fmt-ignore-file
2
- export function FromUndefined(context, type) {
2
+ export function FromUndefined(_context, _type) {
3
3
  return undefined;
4
4
  }
@@ -1,2 +1,2 @@
1
1
  import type { TProperties, TVoid } from '../../type/index.mjs';
2
- export declare function FromVoid(context: TProperties, type: TVoid): unknown;
2
+ export declare function FromVoid(_context: TProperties, _type: TVoid): unknown;
@@ -1,4 +1,4 @@
1
1
  // deno-fmt-ignore-file
2
- export function FromVoid(context, type) {
2
+ export function FromVoid(_context, _type) {
3
3
  return void 0;
4
4
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
4
- "version": "1.1.20",
4
+ "version": "1.1.22",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"
@@ -1,2 +0,0 @@
1
- /** Returns true if the environment supports dynamic JavaScript evaluation */
2
- export declare function CanAccelerate(): boolean;
@@ -1,26 +0,0 @@
1
- import { Settings } from '../settings/index.mjs';
2
- import { Guard } from '../../guard/index.mjs';
3
- let supported = undefined;
4
- // ------------------------------------------------------------------
5
- // TryEval
6
- // ------------------------------------------------------------------
7
- // deno-coverage-ignore-start - catch is environment dependent
8
- function TryEval() {
9
- try {
10
- new globalThis.Function('null')();
11
- return true;
12
- }
13
- catch {
14
- return false;
15
- }
16
- }
17
- // deno-coverage-ignore-stop
18
- // ------------------------------------------------------------------
19
- // CanEvaluate
20
- // ------------------------------------------------------------------
21
- /** Returns true if the environment supports dynamic JavaScript evaluation */
22
- export function CanAccelerate() {
23
- if (Guard.IsUndefined(supported))
24
- supported = TryEval();
25
- return supported && Settings.Get().useAcceleration;
26
- }