typia 5.0.0-dev.20230823 → 5.0.0-dev.2023084

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 (217) hide show
  1. package/lib/Primitive.d.ts +14 -12
  2. package/lib/Resolved.d.ts +46 -0
  3. package/lib/{schemas/metadata/IMetadataResolved.js → Resolved.js} +1 -1
  4. package/lib/Resolved.js.map +1 -0
  5. package/lib/factories/MetadataFactory.d.ts +1 -1
  6. package/lib/factories/MetadataTagFactory.js +10 -8
  7. package/lib/factories/MetadataTagFactory.js.map +1 -1
  8. package/lib/factories/ProtobufFactory.js +4 -3
  9. package/lib/factories/ProtobufFactory.js.map +1 -1
  10. package/lib/factories/internal/metadata/emend_metadata_atomics.js +6 -6
  11. package/lib/factories/internal/metadata/emend_metadata_atomics.js.map +1 -1
  12. package/lib/factories/internal/metadata/explore_metadata.js +3 -3
  13. package/lib/factories/internal/metadata/explore_metadata.js.map +1 -1
  14. package/lib/factories/internal/metadata/iterate_metadata_atomic.js +1 -1
  15. package/lib/factories/internal/metadata/iterate_metadata_atomic.js.map +1 -1
  16. package/lib/factories/internal/metadata/iterate_metadata_collection.js +6 -6
  17. package/lib/factories/internal/metadata/iterate_metadata_collection.js.map +1 -1
  18. package/lib/factories/internal/metadata/iterate_metadata_native.js +2 -10
  19. package/lib/factories/internal/metadata/iterate_metadata_native.js.map +1 -1
  20. package/lib/factories/internal/metadata/iterate_metadata_resolve.js +6 -6
  21. package/lib/factories/internal/metadata/iterate_metadata_resolve.js.map +1 -1
  22. package/lib/factories/internal/metadata/iterate_metadata_sort.js +2 -2
  23. package/lib/factories/internal/metadata/iterate_metadata_sort.js.map +1 -1
  24. package/lib/functional/$ProtobufWriter.js.map +1 -1
  25. package/lib/json.d.ts +15 -15
  26. package/lib/misc.d.ts +42 -42
  27. package/lib/module.d.ts +18 -17
  28. package/lib/module.js +1 -0
  29. package/lib/module.js.map +1 -1
  30. package/lib/programmers/AssertProgrammer.js +1 -1
  31. package/lib/programmers/AssertProgrammer.js.map +1 -1
  32. package/lib/programmers/CheckerProgrammer.js +7 -7
  33. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  34. package/lib/programmers/IsProgrammer.js +2 -2
  35. package/lib/programmers/IsProgrammer.js.map +1 -1
  36. package/lib/programmers/RandomProgrammer.js +311 -136
  37. package/lib/programmers/RandomProgrammer.js.map +1 -1
  38. package/lib/programmers/ValidateProgrammer.js +1 -1
  39. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  40. package/lib/programmers/helpers/AtomicPredicator.js +2 -2
  41. package/lib/programmers/helpers/AtomicPredicator.js.map +1 -1
  42. package/lib/programmers/helpers/FunctionImporeter.d.ts +2 -0
  43. package/lib/programmers/helpers/FunctionImporeter.js +2 -1
  44. package/lib/programmers/helpers/FunctionImporeter.js.map +1 -1
  45. package/lib/programmers/helpers/ProtobufUtil.js +2 -2
  46. package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
  47. package/lib/programmers/helpers/StringifyPredicator.js +1 -2
  48. package/lib/programmers/helpers/StringifyPredicator.js.map +1 -1
  49. package/lib/programmers/helpers/disable_function_importer_declare.js +1 -0
  50. package/lib/programmers/helpers/disable_function_importer_declare.js.map +1 -1
  51. package/lib/programmers/internal/application_default_string.js +2 -2
  52. package/lib/programmers/internal/application_default_string.js.map +1 -1
  53. package/lib/programmers/internal/application_resolved.d.ts +2 -2
  54. package/lib/programmers/internal/application_resolved.js.map +1 -1
  55. package/lib/programmers/internal/application_schema.js +7 -7
  56. package/lib/programmers/internal/application_schema.js.map +1 -1
  57. package/lib/programmers/internal/metadata_to_pattern.js +4 -4
  58. package/lib/programmers/internal/metadata_to_pattern.js.map +1 -1
  59. package/lib/programmers/internal/stringify_dynamic_properties.js +2 -1
  60. package/lib/programmers/internal/stringify_dynamic_properties.js.map +1 -1
  61. package/lib/programmers/json/JsonStringifyProgrammer.js +20 -14
  62. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  63. package/lib/programmers/misc/MiscAssertCloneProgrammer.js +1 -1
  64. package/lib/programmers/misc/MiscAssertCloneProgrammer.js.map +1 -1
  65. package/lib/programmers/misc/MiscCloneProgrammer.js +114 -33
  66. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  67. package/lib/programmers/misc/MiscIsCloneProgrammer.js +1 -1
  68. package/lib/programmers/misc/MiscIsCloneProgrammer.js.map +1 -1
  69. package/lib/programmers/misc/MiscLiteralsProgrammer.js +3 -3
  70. package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
  71. package/lib/programmers/misc/MiscPruneProgrammer.js +2 -2
  72. package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
  73. package/lib/programmers/misc/MiscValidateCloneProgrammer.js +1 -1
  74. package/lib/programmers/misc/MiscValidateCloneProgrammer.js.map +1 -1
  75. package/lib/programmers/protobuf/ProtobufAssertDecodeProgrammer.js +3 -3
  76. package/lib/programmers/protobuf/ProtobufAssertDecodeProgrammer.js.map +1 -1
  77. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +3 -3
  78. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  79. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +1 -1
  80. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
  81. package/lib/programmers/protobuf/ProtobufIsDecodeProgrammer.js +2 -2
  82. package/lib/programmers/protobuf/ProtobufIsDecodeProgrammer.js.map +1 -1
  83. package/lib/programmers/protobuf/ProtobufValidateDecodeProgrammer.js +1 -1
  84. package/lib/programmers/protobuf/ProtobufValidateDecodeProgrammer.js.map +1 -1
  85. package/lib/protobuf.d.ts +631 -10
  86. package/lib/protobuf.js +13 -13
  87. package/lib/protobuf.js.map +1 -1
  88. package/lib/schemas/metadata/IMetadata.d.ts +4 -4
  89. package/lib/schemas/metadata/IMetadataAtomic.d.ts +12 -0
  90. package/lib/schemas/metadata/IMetadataAtomic.js +3 -0
  91. package/lib/schemas/metadata/IMetadataAtomic.js.map +1 -0
  92. package/lib/schemas/metadata/{IMetadataResolved.d.ts → IMetadataEscaped.d.ts} +1 -1
  93. package/lib/schemas/metadata/IMetadataEscaped.js +3 -0
  94. package/lib/schemas/metadata/IMetadataEscaped.js.map +1 -0
  95. package/lib/schemas/metadata/Metadata.d.ts +4 -4
  96. package/lib/schemas/metadata/Metadata.js +64 -59
  97. package/lib/schemas/metadata/Metadata.js.map +1 -1
  98. package/lib/schemas/metadata/{MetadataResolved.d.ts → MetadataEscaped.d.ts} +3 -3
  99. package/lib/schemas/metadata/{MetadataResolved.js → MetadataEscaped.js} +11 -11
  100. package/lib/schemas/metadata/MetadataEscaped.js.map +1 -0
  101. package/lib/tags/ExclusiveMaximum.d.ts +8 -0
  102. package/lib/tags/ExclusiveMaximum.js +3 -0
  103. package/lib/tags/ExclusiveMaximum.js.map +1 -0
  104. package/lib/tags/ExclusiveMinimum.d.ts +8 -0
  105. package/lib/tags/ExclusiveMinimum.js +3 -0
  106. package/lib/tags/ExclusiveMinimum.js.map +1 -0
  107. package/lib/tags/Format.d.ts +8 -0
  108. package/lib/tags/Format.js +3 -0
  109. package/lib/tags/Format.js.map +1 -0
  110. package/lib/tags/MaxItems.d.ts +8 -0
  111. package/lib/tags/MaxItems.js +3 -0
  112. package/lib/tags/MaxItems.js.map +1 -0
  113. package/lib/tags/MaxLength.d.ts +8 -0
  114. package/lib/tags/MaxLength.js +3 -0
  115. package/lib/tags/MaxLength.js.map +1 -0
  116. package/lib/tags/Maximum.d.ts +8 -0
  117. package/lib/tags/Maximum.js +3 -0
  118. package/lib/tags/Maximum.js.map +1 -0
  119. package/lib/tags/MinItems.d.ts +8 -0
  120. package/lib/tags/MinItems.js +3 -0
  121. package/lib/tags/MinItems.js.map +1 -0
  122. package/lib/tags/MinLength.d.ts +8 -0
  123. package/lib/tags/MinLength.js +3 -0
  124. package/lib/tags/MinLength.js.map +1 -0
  125. package/lib/tags/Minimum.d.ts +8 -0
  126. package/lib/tags/Minimum.js +3 -0
  127. package/lib/tags/Minimum.js.map +1 -0
  128. package/lib/tags/MultipleOf.d.ts +8 -0
  129. package/lib/tags/MultipleOf.js +3 -0
  130. package/lib/tags/MultipleOf.js.map +1 -0
  131. package/lib/tags/Pattern.d.ts +8 -0
  132. package/lib/tags/Pattern.js +3 -0
  133. package/lib/tags/Pattern.js.map +1 -0
  134. package/lib/tags/TagBase.d.ts +10 -0
  135. package/lib/tags/TagBase.js +3 -0
  136. package/lib/tags/TagBase.js.map +1 -0
  137. package/lib/tags/Type.d.ts +13 -0
  138. package/lib/tags/Type.js +3 -0
  139. package/lib/tags/Type.js.map +1 -0
  140. package/lib/tags/index.d.ts +12 -0
  141. package/lib/tags/index.js +29 -0
  142. package/lib/tags/index.js.map +1 -0
  143. package/lib/transformers/features/json/JsonApplicationTransformer.js +2 -2
  144. package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
  145. package/lib/transformers/features/misc/MetadataTransformer.js +1 -1
  146. package/lib/transformers/features/misc/MetadataTransformer.js.map +1 -1
  147. package/lib/utils/RandomGenerator.js +3 -2
  148. package/lib/utils/RandomGenerator.js.map +1 -1
  149. package/package.json +2 -1
  150. package/src/Primitive.ts +135 -131
  151. package/src/Resolved.ts +116 -0
  152. package/src/factories/MetadataFactory.ts +46 -46
  153. package/src/factories/MetadataTagFactory.ts +366 -364
  154. package/src/factories/ProtobufFactory.ts +268 -266
  155. package/src/factories/internal/metadata/emend_metadata_atomics.ts +35 -33
  156. package/src/factories/internal/metadata/explore_metadata.ts +38 -38
  157. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +63 -59
  158. package/src/factories/internal/metadata/iterate_metadata_collection.ts +133 -133
  159. package/src/factories/internal/metadata/iterate_metadata_native.ts +210 -219
  160. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +49 -49
  161. package/src/factories/internal/metadata/iterate_metadata_sort.ts +69 -69
  162. package/src/functional/$ProtobufWriter.ts +151 -151
  163. package/src/json.ts +648 -648
  164. package/src/misc.ts +651 -651
  165. package/src/module.ts +709 -708
  166. package/src/programmers/AssertProgrammer.ts +281 -279
  167. package/src/programmers/CheckerProgrammer.ts +1174 -1173
  168. package/src/programmers/IsProgrammer.ts +241 -239
  169. package/src/programmers/RandomProgrammer.ts +874 -578
  170. package/src/programmers/ValidateProgrammer.ts +307 -305
  171. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  172. package/src/programmers/helpers/FunctionImporeter.ts +91 -89
  173. package/src/programmers/helpers/ProtobufUtil.ts +29 -29
  174. package/src/programmers/helpers/StringifyPredicator.ts +12 -13
  175. package/src/programmers/helpers/disable_function_importer_declare.ts +32 -27
  176. package/src/programmers/internal/application_default_string.ts +37 -33
  177. package/src/programmers/internal/application_resolved.ts +55 -55
  178. package/src/programmers/internal/application_schema.ts +157 -157
  179. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  180. package/src/programmers/internal/stringify_dynamic_properties.ts +171 -171
  181. package/src/programmers/json/JsonStringifyProgrammer.ts +995 -987
  182. package/src/programmers/misc/MiscAssertCloneProgrammer.ts +71 -71
  183. package/src/programmers/misc/MiscCloneProgrammer.ts +775 -587
  184. package/src/programmers/misc/MiscIsCloneProgrammer.ts +78 -78
  185. package/src/programmers/misc/MiscLiteralsProgrammer.ts +64 -64
  186. package/src/programmers/misc/MiscPruneProgrammer.ts +544 -542
  187. package/src/programmers/misc/MiscValidateCloneProgrammer.ts +85 -85
  188. package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +75 -66
  189. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +673 -669
  190. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +814 -814
  191. package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +85 -75
  192. package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +75 -75
  193. package/src/protobuf.ts +881 -249
  194. package/src/schemas/metadata/IMetadata.ts +27 -28
  195. package/src/schemas/metadata/IMetadataAtomic.ts +13 -0
  196. package/src/schemas/metadata/{IMetadataResolved.ts → IMetadataEscaped.ts} +6 -6
  197. package/src/schemas/metadata/Metadata.ts +643 -637
  198. package/src/schemas/metadata/{MetadataResolved.ts → MetadataEscaped.ts} +51 -51
  199. package/src/tags/ExclusiveMaximum.ts +8 -0
  200. package/src/tags/ExclusiveMinimum.ts +8 -0
  201. package/src/tags/Format.ts +29 -0
  202. package/src/tags/MaxItems.ts +8 -0
  203. package/src/tags/MaxLength.ts +8 -0
  204. package/src/tags/Maximum.ts +8 -0
  205. package/src/tags/MinItems.ts +8 -0
  206. package/src/tags/MinLength.ts +8 -0
  207. package/src/tags/Minimum.ts +8 -0
  208. package/src/tags/MultipleOf.ts +10 -0
  209. package/src/tags/Pattern.ts +8 -0
  210. package/src/tags/TagBase.ts +17 -0
  211. package/src/tags/Type.ts +30 -0
  212. package/src/tags/index.ts +12 -0
  213. package/src/transformers/features/json/JsonApplicationTransformer.ts +111 -111
  214. package/src/transformers/features/misc/MetadataTransformer.ts +53 -53
  215. package/src/utils/RandomGenerator.ts +83 -81
  216. package/lib/schemas/metadata/IMetadataResolved.js.map +0 -1
  217. package/lib/schemas/metadata/MetadataResolved.js.map +0 -1
package/src/module.ts CHANGED
@@ -1,708 +1,709 @@
1
- import { $dictionary } from "./functional/$dictionary";
2
- import { Namespace } from "./functional/Namespace";
3
-
4
- import { IMetadataApplication } from "./schemas/metadata/IMetadataApplication";
5
-
6
- import { MapUtil } from "./utils/MapUtil";
7
-
8
- import { CustomValidatorMap } from "./CustomValidatorMap";
9
- import { IRandomGenerator } from "./IRandomGenerator";
10
- import { IValidation } from "./IValidation";
11
- import { Primitive } from "./Primitive";
12
-
13
- export * as json from "./json";
14
- export * as protobuf from "./protobuf";
15
- export * as misc from "./misc";
16
-
17
- export * from "./schemas/json/IJsonApplication";
18
- export * from "./schemas/json/IJsonComponents";
19
- export * from "./schemas/json/IJsonSchema";
20
- export * from "./IRandomGenerator";
21
- export * from "./IValidation";
22
- export * from "./Primitive";
23
- export * from "./TypeGuardError";
24
-
25
- /**
26
- * Custom validators.
27
- *
28
- * If you want to add a custom validation logic utilizing comment tags,
29
- * add a closure function with its tag and type name. Below example code
30
- * would helpful to understand how to use this instance.
31
- *
32
- * ```ts
33
- * typia.customValidators.insert("powerOf")("number")(
34
- * (text: string) => {
35
- * const denominator: number = Math.log(Number(text));
36
- * return (value: number) => {
37
- * value = Math.log(value) / denominator;
38
- * return value === Math.floor(value);
39
- * };
40
- * }
41
- * );
42
- * typia.customValidators.insert("dollar")("string")(
43
- * () => (value: string) => value.startsWith("$"),
44
- * );
45
- *
46
- * interface TagCustom {
47
- * /**
48
- * * @powerOf 10
49
- * *\/
50
- * powerOf: number;
51
- *
52
- * /**
53
- * * @dollar
54
- * *\/
55
- * dollar: string;
56
- * }
57
- * ```
58
- *
59
- * @author Jeongho Nam - https://github.com/samchon
60
- */
61
- export const customValidators: CustomValidatorMap = {
62
- size: (name?: string) =>
63
- name ? $dictionary.get(name)?.size ?? 0 : $dictionary.size,
64
- has: (name) => (type) => $dictionary.get(name)?.has(type) ?? false,
65
- get: (name) => (type) => $dictionary.get(name)?.get(type),
66
- insert: (name) => (type) => (closure) => {
67
- const internal = MapUtil.take($dictionary)(name, () => new Map());
68
- if (internal.has(type)) return false;
69
- internal.set(type, closure);
70
- return true;
71
- },
72
- erase: (name) => (type) => $dictionary.get(name)?.delete(type) ?? false,
73
- };
74
-
75
- /* -----------------------------------------------------------
76
- BASIC VALIDATORS
77
- ----------------------------------------------------------- */
78
- /**
79
- * Asserts a value type.
80
- *
81
- * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
82
- * reason, if the parametric value is not following the type `T`. Otherwise, the
83
- * value is following the type `T`, just input parameter would be returned.
84
- *
85
- * If what you want is not asserting but just knowing whether the parametric value is
86
- * following the type `T` or not, you can choose the {@link is} function instead.
87
- * Otherwise you want to know all the errors, {@link validate} is the way to go.
88
- *
89
- * On the other and, if you don't want to allow any superfluous property that is not
90
- * enrolled to the type `T`, you can use {@link assertEquals} function instead.
91
- *
92
- * @template T Type of the input value
93
- * @param input A value to be asserted
94
- * @returns Parametric input value
95
- * @throws A {@link TypeGuardError} instance with detailed reason
96
- *
97
- * @author Jeongho Nam - https://github.com/samchon
98
- */
99
- export function assert<T>(input: T): T;
100
-
101
- /**
102
- * Asserts a value type.
103
- *
104
- * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
105
- * reason, if the parametric value is not following the type `T`. Otherwise, the
106
- * value is following the type `T`, just input parameter would be returned.
107
- *
108
- * If what you want is not asserting but just knowing whether the parametric value is
109
- * following the type `T` or not, you can choose the {@link is} function instead.
110
- * Otherwise, you want to know all the errors, {@link validate} is the way to go.
111
- *
112
- * On the other and, if you don't want to allow any superfluous property that is not
113
- * enrolled to the type `T`, you can use {@link assertEquals} function instead.
114
- *
115
- * @template T Type of the input value
116
- * @param input A value to be asserted
117
- * @returns Parametric input value casted as `T`
118
- * @throws A {@link TypeGuardError} instance with detailed reason
119
- *
120
- * @author Jeongho Nam - https://github.com/samchon
121
- */
122
- export function assert<T>(input: unknown): T;
123
-
124
- /**
125
- * @internal
126
- */
127
- export function assert(): never {
128
- halt("assert");
129
- }
130
- Object.assign(assert, Namespace.assert("assert"));
131
-
132
- /**
133
- * Tests a value type.
134
- *
135
- * Tests a parametric value type and returns whether it's following the type `T` or not.
136
- * If the parametric value is matched with the type `T`, `true` value would be returned.
137
- * Otherwise, the parametric value is not following the type `T`, `false` value would be
138
- * returned.
139
- *
140
- * If what you want is not just knowing whether the parametric value is following the
141
- * type `T` or not, but throwing an exception with detailed reason, you can choose
142
- * {@link assert} function instead. Also, if you want to know all the errors with
143
- * detailed reasons, {@link validate} function would be useful.
144
- *
145
- * On the other and, if you don't want to allow any superfluous property that is not
146
- * enrolled to the type `T`, you can use {@link equals} function instead.
147
- *
148
- * @template T Type of the input value
149
- * @param input A value to be tested
150
- * @returns Whether the parametric value is following the type `T` or not
151
- *
152
- * @author Jeongho Nam - https://github.com/samchon
153
- */
154
- export function is<T>(input: T): input is T;
155
-
156
- /**
157
- * Tests a value type.
158
- *
159
- * Tests a parametric value type and returns whether it's following the type `T` or not.
160
- * If the parametric value is matched with the type `T`, `true` value would be returned.
161
- * Otherwise, the parametric value is not following the type `T`, `false` value would be
162
- * returned.
163
- *
164
- * If what you want is not just knowing whether the parametric value is following the
165
- * type `T` or not, but throwing an exception with detailed reason, you can choose
166
- * {@link assert} function instead. Also, if you want to know all the errors with
167
- * detailed reasons, {@link validate} function would be useful.
168
- *
169
- * On the other and, if you don't want to allow any superfluous property that is not
170
- * enrolled to the type `T`, you can use {@link equals} function instead.
171
- *
172
- * @template T Type of the input value
173
- * @param input A value to be tested
174
- * @returns Whether the parametric value is following the type `T` or not
175
- *
176
- * @author Jeongho Nam - https://github.com/samchon
177
- */
178
- export function is<T>(input: unknown): input is T;
179
-
180
- /**
181
- * @internal
182
- */
183
- export function is(): never {
184
- halt("is");
185
- }
186
- Object.assign(is, Namespace.assert("is"));
187
-
188
- /**
189
- * Validates a value type.
190
- *
191
- * Validates a parametric value type and archives all the type errors into an
192
- * {@link IValidation.errors} array, if the parametric value is not following the
193
- * type `T`. Of course, if the parametric value is following the type `T`, the
194
- * {@link IValidation.errors} array would be empty and {@link IValidation.success}
195
- * would have the `true` value.
196
- *
197
- * If what you want is not finding all the error, but asserting the parametric value
198
- * type with exception throwing, you can choose {@link assert} function instead.
199
- * Otherwise, you just want to know whether the parametric value is matched with the
200
- * type `T`, {@link is} function is the way to go.
201
- *
202
- * On the other and, if you don't want to allow any superfluous property that is not
203
- * enrolled to the type `T`, you can use {@link validateEquals} function instead.
204
- *
205
- * @template Type of the input value
206
- * @param input A value to be validated
207
- * @returns Validation result
208
- *
209
- * @author Jeongho Nam - https://github.com/samchon
210
- */
211
- export function validate<T>(input: T): IValidation<T>;
212
-
213
- /**
214
- * Validates a value type.
215
- *
216
- * Validates a parametric value type and archives all the type errors into an
217
- * {@link IValidation.errors} array, if the parametric value is not following the
218
- * type `T`. Of course, if the parametric value is following the type `T`, the
219
- * {@link IValidation.errors} array would be empty and {@link IValidation.success}
220
- * would have the `true` value.
221
- *
222
- * If what you want is not finding all the error, but asserting the parametric value
223
- * type with exception throwing, you can choose {@link assert} function instead.
224
- * Otherwise, you just want to know whether the parametric value is matched with the
225
- * type `T`, {@link is} function is the way to go.
226
- *
227
- * On the other and, if you don't want to allow any superfluous property that is not
228
- * enrolled to the type `T`, you can use {@link validateEquals} function instead.
229
- *
230
- * @template Type of the input value
231
- * @param input A value to be validated
232
- * @returns Validation result
233
- *
234
- * @author Jeongho Nam - https://github.com/samchon
235
- */
236
- export function validate<T>(input: unknown): IValidation<T>;
237
-
238
- /**
239
- * @internal
240
- */
241
- export function validate(): never {
242
- halt("validate");
243
- }
244
- Object.assign(validate, Namespace.validate());
245
-
246
- /* -----------------------------------------------------------
247
- STRICT VALIDATORS
248
- ----------------------------------------------------------- */
249
- /**
250
- * Asserts equality between a value and its type.
251
- *
252
- * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
253
- * reason, if the parametric value is not following the type `T` or some superfluous
254
- * property that is not listed on the type `T` has been found. Otherwise, the value is
255
- * following the type `T` without any superfluous property, just input parameter would
256
- * be returned.
257
- *
258
- * If what you want is not asserting but just knowing whether the parametric value is
259
- * following the type `T` or not, you can choose the {@link equals} function instead.
260
- * Otherwise, you want to know all the errors, {@link validateEquals} is the way to go.
261
- *
262
- * On the other hand, if you want to allow superfluous property that is not enrolled
263
- * to the type `T`, you can use {@link assert} function instead.
264
- *
265
- * @template T Type of the input value
266
- * @param input A value to be asserted
267
- * @returns Parametric input value
268
- * @throws A {@link TypeGuardError} instance with detailed reason
269
- *
270
- * @author Jeongho Nam - https://github.com/samchon
271
- */
272
- export function assertEquals<T>(input: T): T;
273
-
274
- /**
275
- * Asserts equality between a value and its type.
276
- *
277
- * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
278
- * reason, if the parametric value is not following the type `T` or some superfluous
279
- * property that is not listed on the type `T` has been found. Otherwise, the value is
280
- * following the type `T` without any superfluous property, just input parameter would
281
- * be returned.
282
- *
283
- * If what you want is not asserting but just knowing whether the parametric value is
284
- * following the type `T` or not, you can choose the {@link equals} function instead.
285
- * Otherwise, you want to know all the errors, {@link validateEquals} is the way to go.
286
- *
287
- * On the other hand, if you want to allow superfluous property that is not enrolled
288
- * to the type `T`, you can use {@link assert} function instead.
289
- *
290
- * @template T Type of the input value
291
- * @param input A value to be asserted
292
- * @returns Parametric input value casted as `T`
293
- * @throws A {@link TypeGuardError} instance with detailed reason
294
- *
295
- * @author Jeongho Nam - https://github.com/samchon
296
- */
297
- export function assertEquals<T>(input: unknown): T;
298
-
299
- /**
300
- * @internal
301
- */
302
- export function assertEquals(): never {
303
- halt("assertEquals");
304
- }
305
- Object.assign(assertEquals, Namespace.assert("assertEquals"));
306
-
307
- /**
308
- * Tests equality between a value and its type.
309
- *
310
- * Tests a parametric value type and returns whether it's equivalent to the type `T`
311
- * or not. If the parametric value is matched with the type `T` and there's not any
312
- * superfluous property that is not listed on the type `T`, `true` value would be
313
- * returned. Otherwise, the parametric value is not following the type `T` or some
314
- * superfluous property exists, `false` value would be returned.
315
- *
316
- * If what you want is not just knowing whether the parametric value is following the
317
- * type `T` or not, but throwing an exception with detailed reason, you can choose
318
- * {@link assertEquals} function instead. Also, if you want to know all the errors with
319
- * detailed reasons, {@link validateEquals} function would be useful.
320
- *
321
- * On the other hand, if you want to allow superfluous property that is not enrolled
322
- * to the type `T`, you can use {@link is} function instead.
323
- *
324
- * @template T Type of the input value
325
- * @param input A value to be tested
326
- * @returns Whether the parametric value is equivalent to the type `T` or not
327
- *
328
- * @author Jeongho Nam - https://github.com/samchon
329
- */
330
- export function equals<T>(input: T): input is T;
331
-
332
- /**
333
- * Tests equality between a value and its type.
334
- *
335
- * Tests a parametric value type and returns whether it's equivalent to the type `T`
336
- * or not. If the parametric value is matched with the type `T` and there's not any
337
- * superfluous property that is not listed on the type `T`, `true` value would be
338
- * returned. Otherwise, the parametric value is not following the type `T` or some
339
- * superfluous property exists, `false` value would be returned.
340
- *
341
- * If what you want is not just knowing whether the parametric value is following the
342
- * type `T` or not, but throwing an exception with detailed reason, you can choose
343
- * {@link assertEquals} function instead. Also, if you want to know all the errors with
344
- * detailed reasons, {@link validateEquals} function would be useful.
345
- *
346
- * On the other hand, if you want to allow superfluous property that is not enrolled
347
- * to the type `T`, you can use {@link is} function instead.
348
- *
349
- * @template T Type of the input value
350
- * @param input A value to be tested
351
- * @returns Whether the parametric value is equivalent to the type `T` or not
352
- *
353
- * @author Jeongho Nam - https://github.com/samchon
354
- */
355
- export function equals<T>(input: unknown): input is T;
356
-
357
- /**
358
- * @internal
359
- */
360
- export function equals(): never {
361
- halt("equals");
362
- }
363
- Object.assign(equals, Namespace.is());
364
-
365
- /**
366
- * Validates equality between a value and its type.
367
- *
368
- * Validates a parametric value type and archives all the type errors into an
369
- * {@link IValidation.errors} array, if the parametric value is not following the
370
- * type `T` or some superfluous property that is not listed on the type `T` has been
371
- * found. Of course, if the parametric value is following the type `T` and no
372
- * superfluous property exists, the {@link IValidation.errors} array would be empty
373
- * and {@link IValidation.success} would have the `true` value.
374
- *
375
- * If what you want is not finding all the error, but asserting the parametric value
376
- * type with exception throwing, you can choose {@link assert} function instead.
377
- * Otherwise, you just want to know whether the parametric value is matched with the
378
- * type `T`, {@link is} function is the way to go.
379
- *
380
- * On the other and, if you don't want to allow any superfluous property that is not
381
- * enrolled to the type `T`, you can use {@link validateEquals} function instead.
382
- *
383
- * @template Type of the input value
384
- * @param input A value to be validated
385
- * @returns Validation result
386
- *
387
- * @author Jeongho Nam - https://github.com/samchon
388
- */
389
- export function validateEquals<T>(input: T): IValidation<T>;
390
-
391
- /**
392
- * Validates equality between a value and its type.
393
- *
394
- * Validates a parametric value type and archives all the type errors into an
395
- * {@link IValidation.errors} array, if the parametric value is not following the
396
- * type `T` or some superfluous property that is not listed on the type `T` has been
397
- * found. Of course, if the parametric value is following the type `T` and no
398
- * superfluous property exists, the {@link IValidation.errors} array would be empty
399
- * and {@link IValidation.success} would have the `true` value.
400
- *
401
- * If what you want is not finding all the error, but asserting the parametric value
402
- * type with exception throwing, you can choose {@link assert} function instead.
403
- * Otherwise, you just want to know whether the parametric value is matched with the
404
- * type `T`, {@link is} function is the way to go.
405
- *
406
- * On the other and, if you don't want to allow any superfluous property that is not
407
- * enrolled to the type `T`, you can use {@link validateEquals} function instead.
408
- *
409
- * @template Type of the input value
410
- * @param input A value to be validated
411
- * @returns Validation result
412
- *
413
- * @author Jeongho Nam - https://github.com/samchon
414
- */
415
- export function validateEquals<T>(input: unknown): IValidation<T>;
416
-
417
- /**
418
- * @internal
419
- */
420
- export function validateEquals(): never {
421
- halt("validateEquals");
422
- }
423
- Object.assign(validateEquals, Namespace.validate());
424
-
425
- /* -----------------------------------------------------------
426
- RANDOM
427
- ----------------------------------------------------------- */
428
- /**
429
- * > You must configure the generic argument `T`.
430
- *
431
- * Generate random data.
432
- *
433
- * Generates a random data following type the `T`.
434
- *
435
- * For reference, this `typia.random()` function generates only primitive type.
436
- * If there're some methods in the type `T` or its nested instances, those would
437
- * be ignored. Also, when the type `T` has a `toJSON()` method, its return type
438
- * would be generated instead.
439
- *
440
- * @template T Type of data to generate
441
- * @param generator Random data generator
442
- * @return Randomly generated data
443
- *
444
- * @author Jeongho Nam - https://github.com/samchon
445
- */
446
- export function random(generator?: Partial<IRandomGenerator>): never;
447
-
448
- /**
449
- * Generate random data.
450
- *
451
- * Generates a random data following type the `T`.
452
- *
453
- * For reference, this `typia.random()` function generates only primitive type.
454
- * If there're some methods in the type `T` or its nested instances, those would
455
- * be ignored. Also, when the type `T` has a `toJSON()` method, its return type
456
- * would be generated instead.
457
- *
458
- * @template T Type of data to generate
459
- * @param generator Random data generator
460
- * @return Randomly generated data
461
- *
462
- * @author Jeongho Nam - https://github.com/samchon
463
- */
464
- export function random<T>(generator?: Partial<IRandomGenerator>): Primitive<T>;
465
-
466
- /**
467
- * @internal
468
- */
469
- export function random(): never {
470
- halt("random");
471
- }
472
- Object.assign(random, Namespace.random());
473
-
474
- /**
475
- * @internal
476
- */
477
- export function metadata(): never;
478
-
479
- /**
480
- * @internal
481
- */
482
- export function metadata<Types extends unknown[]>(): IMetadataApplication;
483
-
484
- /**
485
- * @internal
486
- */
487
- export function metadata(): never {
488
- halt("metadata");
489
- }
490
-
491
- /* -----------------------------------------------------------
492
- FACTORY FUNCTIONS
493
- ----------------------------------------------------------- */
494
- /**
495
- * Creates a reusable {@link assert} function.
496
- *
497
- * @danger You have to specify the generic argument `T`
498
- * @return Nothing until specifying the generic argument `T`
499
- * @throws compile error
500
- *
501
- * @author Jeongho Nam - https://github.com/samchon
502
- */
503
- export function createAssert(): never;
504
-
505
- /**
506
- * Creates a reusable {@link assert} function.
507
- *
508
- * @template T Type of the input value
509
- * @returns A reusable `assert` function
510
- *
511
- * @author Jeongho Nam - https://github.com/samchon
512
- */
513
- export function createAssert<T>(): (input: unknown) => T;
514
-
515
- /**
516
- * @internal
517
- */
518
- export function createAssert<T>(): (input: unknown) => T {
519
- halt("createAssert");
520
- }
521
- Object.assign(createAssert, assert);
522
-
523
- /**
524
- * Creates a reusable {@link is} function.
525
- *
526
- * @danger You have to specify the generic argument `T`
527
- * @return Nothing until specifying the generic argument `T`
528
- * @throws compile error
529
- *
530
- * @author Jeongho Nam - https://github.com/samchon
531
- */
532
- export function createIs(): never;
533
-
534
- /**
535
- * Creates a reusable {@link is} function.
536
- *
537
- * @template T Type of the input value
538
- * @returns A reusable `is` function
539
- *
540
- * @author Jeongho Nam - https://github.com/samchon
541
- */
542
- export function createIs<T>(): (input: unknown) => input is T;
543
-
544
- /**
545
- * @internal
546
- */
547
- export function createIs<T>(): (input: unknown) => input is T {
548
- halt("createIs");
549
- }
550
- Object.assign(createIs, is);
551
-
552
- /**
553
- * Creates a reusable {@link validate} function.
554
- *
555
- * @danger You have to specify the generic argument `T`
556
- * @return Nothing until specifying the generic argument `T`
557
- * @throws compile error
558
- *
559
- * @author Jeongho Nam - https://github.com/samchon
560
- */
561
- export function createValidate(): never;
562
-
563
- /**
564
- * Creates a reusable {@link validate} function.
565
- *
566
- * @template T Type of the input value
567
- * @returns A reusable `validate` function
568
- *
569
- * @author Jeongho Nam - https://github.com/samchon
570
- */
571
- export function createValidate<T>(): (input: unknown) => IValidation<T>;
572
-
573
- /**
574
- * @internal
575
- */
576
- export function createValidate(): (input: unknown) => IValidation {
577
- halt("createValidate");
578
- }
579
- Object.assign(createValidate, validate);
580
-
581
- /**
582
- * Creates a reusable {@link assertEquals} function.
583
- *
584
- * @danger You have to specify the generic argument `T`
585
- * @return Nothing until specifying the generic argument `T`
586
- * @throws compile error
587
- *
588
- * @author Jeongho Nam - https://github.com/samchon
589
- */
590
- export function createAssertEquals(): never;
591
-
592
- /**
593
- * Creates a reusable {@link assertEquals} function.
594
- *
595
- * @template T Type of the input value
596
- * @returns A reusable `assertEquals` function
597
- *
598
- * @author Jeongho Nam - https://github.com/samchon
599
- */
600
- export function createAssertEquals<T>(): (input: unknown) => T;
601
-
602
- /**
603
- * @internal
604
- */
605
- export function createAssertEquals<T>(): (input: unknown) => T {
606
- halt("createAssertEquals");
607
- }
608
- Object.assign(createAssertEquals, assertEquals);
609
-
610
- /**
611
- * Creates a reusable {@link equals} function.
612
- *
613
- * @danger You have to specify the generic argument `T`
614
- * @return Nothing until specifying the generic argument `T`
615
- * @throws compile error
616
- *
617
- * @author Jeongho Nam - https://github.com/samchon
618
- */
619
- export function createEquals(): never;
620
-
621
- /**
622
- * Creates a reusable {@link equals} function.
623
- *
624
- * @template T Type of the input value
625
- * @returns A reusable `equals` function
626
- *
627
- * @author Jeongho Nam - https://github.com/samchon
628
- */
629
- export function createEquals<T>(): (input: unknown) => input is T;
630
-
631
- /**
632
- * @internal
633
- */
634
- export function createEquals<T>(): (input: unknown) => input is T {
635
- halt("createEquals");
636
- }
637
- Object.assign(createEquals, equals);
638
-
639
- /**
640
- * Creates a reusable {@link validateEquals} function.
641
- *
642
- * @danger You have to specify the generic argument `T`
643
- * @return Nothing until specifying the generic argument `T`
644
- * @throws compile error
645
- *
646
- * @author Jeongho Nam - https://github.com/samchon
647
- */
648
- export function createValidateEquals(): never;
649
-
650
- /**
651
- * Creates a reusable {@link validateEquals} function.
652
- *
653
- * @template T Type of the input value
654
- * @returns A reusable `validateEquals` function
655
- *
656
- * @author Jeongho Nam - https://github.com/samchon
657
- */
658
- export function createValidateEquals<T>(): (input: unknown) => IValidation<T>;
659
-
660
- /**
661
- * @internal
662
- */
663
- export function createValidateEquals(): (input: unknown) => IValidation {
664
- halt("createValidateEquals");
665
- }
666
- Object.assign(createValidateEquals, validateEquals);
667
-
668
- /**
669
- * Creates a reusable {@link random} function.
670
- *
671
- * @danger You have to specify the generic argument `T`
672
- * @param generator Random data generator
673
- * @return Nothing until specifying the generic argument `T`
674
- * @throws compile error
675
- *
676
- * @author Jeongho Nam - https://github.com/samchon
677
- */
678
- export function createRandom(generator?: Partial<IRandomGenerator>): never;
679
-
680
- /**
681
- * Creates a resuable {@link random} function.
682
- *
683
- * @template T Type of the input value
684
- * @param generator Random data generator
685
- * @returns A reusable `random` function
686
- *
687
- * @author Jeongho Nam - https://github.com/samchon
688
- */
689
- export function createRandom<T>(
690
- generator?: Partial<IRandomGenerator>,
691
- ): () => Primitive<T>;
692
-
693
- /**
694
- * @internal
695
- */
696
- export function createRandom(): never {
697
- halt("createRandom");
698
- }
699
- Object.assign(createRandom, random);
700
-
701
- /**
702
- * @internal
703
- */
704
- function halt(name: string): never {
705
- throw new Error(
706
- `Error on typia.${name}(): no transform has been configured. Read and follow https://typia.io/docs/setup please.`,
707
- );
708
- }
1
+ import { $dictionary } from "./functional/$dictionary";
2
+ import { Namespace } from "./functional/Namespace";
3
+
4
+ import { IMetadataApplication } from "./schemas/metadata/IMetadataApplication";
5
+
6
+ import { MapUtil } from "./utils/MapUtil";
7
+
8
+ import { CustomValidatorMap } from "./CustomValidatorMap";
9
+ import { IRandomGenerator } from "./IRandomGenerator";
10
+ import { IValidation } from "./IValidation";
11
+ import { Resolved } from "./Resolved";
12
+
13
+ export * as json from "./json";
14
+ export * as protobuf from "./protobuf";
15
+ export * as misc from "./misc";
16
+
17
+ export * from "./schemas/json/IJsonApplication";
18
+ export * from "./schemas/json/IJsonComponents";
19
+ export * from "./schemas/json/IJsonSchema";
20
+ export * from "./IRandomGenerator";
21
+ export * from "./IValidation";
22
+ export * from "./Primitive";
23
+ export * from "./Resolved";
24
+ export * from "./TypeGuardError";
25
+
26
+ /**
27
+ * Custom validators.
28
+ *
29
+ * If you want to add a custom validation logic utilizing comment tags,
30
+ * add a closure function with its tag and type name. Below example code
31
+ * would helpful to understand how to use this instance.
32
+ *
33
+ * ```ts
34
+ * typia.customValidators.insert("powerOf")("number")(
35
+ * (text: string) => {
36
+ * const denominator: number = Math.log(Number(text));
37
+ * return (value: number) => {
38
+ * value = Math.log(value) / denominator;
39
+ * return value === Math.floor(value);
40
+ * };
41
+ * }
42
+ * );
43
+ * typia.customValidators.insert("dollar")("string")(
44
+ * () => (value: string) => value.startsWith("$"),
45
+ * );
46
+ *
47
+ * interface TagCustom {
48
+ * /**
49
+ * * @powerOf 10
50
+ * *\/
51
+ * powerOf: number;
52
+ *
53
+ * /**
54
+ * * @dollar
55
+ * *\/
56
+ * dollar: string;
57
+ * }
58
+ * ```
59
+ *
60
+ * @author Jeongho Nam - https://github.com/samchon
61
+ */
62
+ export const customValidators: CustomValidatorMap = {
63
+ size: (name?: string) =>
64
+ name ? $dictionary.get(name)?.size ?? 0 : $dictionary.size,
65
+ has: (name) => (type) => $dictionary.get(name)?.has(type) ?? false,
66
+ get: (name) => (type) => $dictionary.get(name)?.get(type),
67
+ insert: (name) => (type) => (closure) => {
68
+ const internal = MapUtil.take($dictionary)(name, () => new Map());
69
+ if (internal.has(type)) return false;
70
+ internal.set(type, closure);
71
+ return true;
72
+ },
73
+ erase: (name) => (type) => $dictionary.get(name)?.delete(type) ?? false,
74
+ };
75
+
76
+ /* -----------------------------------------------------------
77
+ BASIC VALIDATORS
78
+ ----------------------------------------------------------- */
79
+ /**
80
+ * Asserts a value type.
81
+ *
82
+ * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
83
+ * reason, if the parametric value is not following the type `T`. Otherwise, the
84
+ * value is following the type `T`, just input parameter would be returned.
85
+ *
86
+ * If what you want is not asserting but just knowing whether the parametric value is
87
+ * following the type `T` or not, you can choose the {@link is} function instead.
88
+ * Otherwise you want to know all the errors, {@link validate} is the way to go.
89
+ *
90
+ * On the other and, if you don't want to allow any superfluous property that is not
91
+ * enrolled to the type `T`, you can use {@link assertEquals} function instead.
92
+ *
93
+ * @template T Type of the input value
94
+ * @param input A value to be asserted
95
+ * @returns Parametric input value
96
+ * @throws A {@link TypeGuardError} instance with detailed reason
97
+ *
98
+ * @author Jeongho Nam - https://github.com/samchon
99
+ */
100
+ export function assert<T>(input: T): T;
101
+
102
+ /**
103
+ * Asserts a value type.
104
+ *
105
+ * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
106
+ * reason, if the parametric value is not following the type `T`. Otherwise, the
107
+ * value is following the type `T`, just input parameter would be returned.
108
+ *
109
+ * If what you want is not asserting but just knowing whether the parametric value is
110
+ * following the type `T` or not, you can choose the {@link is} function instead.
111
+ * Otherwise, you want to know all the errors, {@link validate} is the way to go.
112
+ *
113
+ * On the other and, if you don't want to allow any superfluous property that is not
114
+ * enrolled to the type `T`, you can use {@link assertEquals} function instead.
115
+ *
116
+ * @template T Type of the input value
117
+ * @param input A value to be asserted
118
+ * @returns Parametric input value casted as `T`
119
+ * @throws A {@link TypeGuardError} instance with detailed reason
120
+ *
121
+ * @author Jeongho Nam - https://github.com/samchon
122
+ */
123
+ export function assert<T>(input: unknown): T;
124
+
125
+ /**
126
+ * @internal
127
+ */
128
+ export function assert(): never {
129
+ halt("assert");
130
+ }
131
+ Object.assign(assert, Namespace.assert("assert"));
132
+
133
+ /**
134
+ * Tests a value type.
135
+ *
136
+ * Tests a parametric value type and returns whether it's following the type `T` or not.
137
+ * If the parametric value is matched with the type `T`, `true` value would be returned.
138
+ * Otherwise, the parametric value is not following the type `T`, `false` value would be
139
+ * returned.
140
+ *
141
+ * If what you want is not just knowing whether the parametric value is following the
142
+ * type `T` or not, but throwing an exception with detailed reason, you can choose
143
+ * {@link assert} function instead. Also, if you want to know all the errors with
144
+ * detailed reasons, {@link validate} function would be useful.
145
+ *
146
+ * On the other and, if you don't want to allow any superfluous property that is not
147
+ * enrolled to the type `T`, you can use {@link equals} function instead.
148
+ *
149
+ * @template T Type of the input value
150
+ * @param input A value to be tested
151
+ * @returns Whether the parametric value is following the type `T` or not
152
+ *
153
+ * @author Jeongho Nam - https://github.com/samchon
154
+ */
155
+ export function is<T>(input: T): input is T;
156
+
157
+ /**
158
+ * Tests a value type.
159
+ *
160
+ * Tests a parametric value type and returns whether it's following the type `T` or not.
161
+ * If the parametric value is matched with the type `T`, `true` value would be returned.
162
+ * Otherwise, the parametric value is not following the type `T`, `false` value would be
163
+ * returned.
164
+ *
165
+ * If what you want is not just knowing whether the parametric value is following the
166
+ * type `T` or not, but throwing an exception with detailed reason, you can choose
167
+ * {@link assert} function instead. Also, if you want to know all the errors with
168
+ * detailed reasons, {@link validate} function would be useful.
169
+ *
170
+ * On the other and, if you don't want to allow any superfluous property that is not
171
+ * enrolled to the type `T`, you can use {@link equals} function instead.
172
+ *
173
+ * @template T Type of the input value
174
+ * @param input A value to be tested
175
+ * @returns Whether the parametric value is following the type `T` or not
176
+ *
177
+ * @author Jeongho Nam - https://github.com/samchon
178
+ */
179
+ export function is<T>(input: unknown): input is T;
180
+
181
+ /**
182
+ * @internal
183
+ */
184
+ export function is(): never {
185
+ halt("is");
186
+ }
187
+ Object.assign(is, Namespace.assert("is"));
188
+
189
+ /**
190
+ * Validates a value type.
191
+ *
192
+ * Validates a parametric value type and archives all the type errors into an
193
+ * {@link IValidation.errors} array, if the parametric value is not following the
194
+ * type `T`. Of course, if the parametric value is following the type `T`, the
195
+ * {@link IValidation.errors} array would be empty and {@link IValidation.success}
196
+ * would have the `true` value.
197
+ *
198
+ * If what you want is not finding all the error, but asserting the parametric value
199
+ * type with exception throwing, you can choose {@link assert} function instead.
200
+ * Otherwise, you just want to know whether the parametric value is matched with the
201
+ * type `T`, {@link is} function is the way to go.
202
+ *
203
+ * On the other and, if you don't want to allow any superfluous property that is not
204
+ * enrolled to the type `T`, you can use {@link validateEquals} function instead.
205
+ *
206
+ * @template Type of the input value
207
+ * @param input A value to be validated
208
+ * @returns Validation result
209
+ *
210
+ * @author Jeongho Nam - https://github.com/samchon
211
+ */
212
+ export function validate<T>(input: T): IValidation<T>;
213
+
214
+ /**
215
+ * Validates a value type.
216
+ *
217
+ * Validates a parametric value type and archives all the type errors into an
218
+ * {@link IValidation.errors} array, if the parametric value is not following the
219
+ * type `T`. Of course, if the parametric value is following the type `T`, the
220
+ * {@link IValidation.errors} array would be empty and {@link IValidation.success}
221
+ * would have the `true` value.
222
+ *
223
+ * If what you want is not finding all the error, but asserting the parametric value
224
+ * type with exception throwing, you can choose {@link assert} function instead.
225
+ * Otherwise, you just want to know whether the parametric value is matched with the
226
+ * type `T`, {@link is} function is the way to go.
227
+ *
228
+ * On the other and, if you don't want to allow any superfluous property that is not
229
+ * enrolled to the type `T`, you can use {@link validateEquals} function instead.
230
+ *
231
+ * @template Type of the input value
232
+ * @param input A value to be validated
233
+ * @returns Validation result
234
+ *
235
+ * @author Jeongho Nam - https://github.com/samchon
236
+ */
237
+ export function validate<T>(input: unknown): IValidation<T>;
238
+
239
+ /**
240
+ * @internal
241
+ */
242
+ export function validate(): never {
243
+ halt("validate");
244
+ }
245
+ Object.assign(validate, Namespace.validate());
246
+
247
+ /* -----------------------------------------------------------
248
+ STRICT VALIDATORS
249
+ ----------------------------------------------------------- */
250
+ /**
251
+ * Asserts equality between a value and its type.
252
+ *
253
+ * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
254
+ * reason, if the parametric value is not following the type `T` or some superfluous
255
+ * property that is not listed on the type `T` has been found. Otherwise, the value is
256
+ * following the type `T` without any superfluous property, just input parameter would
257
+ * be returned.
258
+ *
259
+ * If what you want is not asserting but just knowing whether the parametric value is
260
+ * following the type `T` or not, you can choose the {@link equals} function instead.
261
+ * Otherwise, you want to know all the errors, {@link validateEquals} is the way to go.
262
+ *
263
+ * On the other hand, if you want to allow superfluous property that is not enrolled
264
+ * to the type `T`, you can use {@link assert} function instead.
265
+ *
266
+ * @template T Type of the input value
267
+ * @param input A value to be asserted
268
+ * @returns Parametric input value
269
+ * @throws A {@link TypeGuardError} instance with detailed reason
270
+ *
271
+ * @author Jeongho Nam - https://github.com/samchon
272
+ */
273
+ export function assertEquals<T>(input: T): T;
274
+
275
+ /**
276
+ * Asserts equality between a value and its type.
277
+ *
278
+ * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
279
+ * reason, if the parametric value is not following the type `T` or some superfluous
280
+ * property that is not listed on the type `T` has been found. Otherwise, the value is
281
+ * following the type `T` without any superfluous property, just input parameter would
282
+ * be returned.
283
+ *
284
+ * If what you want is not asserting but just knowing whether the parametric value is
285
+ * following the type `T` or not, you can choose the {@link equals} function instead.
286
+ * Otherwise, you want to know all the errors, {@link validateEquals} is the way to go.
287
+ *
288
+ * On the other hand, if you want to allow superfluous property that is not enrolled
289
+ * to the type `T`, you can use {@link assert} function instead.
290
+ *
291
+ * @template T Type of the input value
292
+ * @param input A value to be asserted
293
+ * @returns Parametric input value casted as `T`
294
+ * @throws A {@link TypeGuardError} instance with detailed reason
295
+ *
296
+ * @author Jeongho Nam - https://github.com/samchon
297
+ */
298
+ export function assertEquals<T>(input: unknown): T;
299
+
300
+ /**
301
+ * @internal
302
+ */
303
+ export function assertEquals(): never {
304
+ halt("assertEquals");
305
+ }
306
+ Object.assign(assertEquals, Namespace.assert("assertEquals"));
307
+
308
+ /**
309
+ * Tests equality between a value and its type.
310
+ *
311
+ * Tests a parametric value type and returns whether it's equivalent to the type `T`
312
+ * or not. If the parametric value is matched with the type `T` and there's not any
313
+ * superfluous property that is not listed on the type `T`, `true` value would be
314
+ * returned. Otherwise, the parametric value is not following the type `T` or some
315
+ * superfluous property exists, `false` value would be returned.
316
+ *
317
+ * If what you want is not just knowing whether the parametric value is following the
318
+ * type `T` or not, but throwing an exception with detailed reason, you can choose
319
+ * {@link assertEquals} function instead. Also, if you want to know all the errors with
320
+ * detailed reasons, {@link validateEquals} function would be useful.
321
+ *
322
+ * On the other hand, if you want to allow superfluous property that is not enrolled
323
+ * to the type `T`, you can use {@link is} function instead.
324
+ *
325
+ * @template T Type of the input value
326
+ * @param input A value to be tested
327
+ * @returns Whether the parametric value is equivalent to the type `T` or not
328
+ *
329
+ * @author Jeongho Nam - https://github.com/samchon
330
+ */
331
+ export function equals<T>(input: T): input is T;
332
+
333
+ /**
334
+ * Tests equality between a value and its type.
335
+ *
336
+ * Tests a parametric value type and returns whether it's equivalent to the type `T`
337
+ * or not. If the parametric value is matched with the type `T` and there's not any
338
+ * superfluous property that is not listed on the type `T`, `true` value would be
339
+ * returned. Otherwise, the parametric value is not following the type `T` or some
340
+ * superfluous property exists, `false` value would be returned.
341
+ *
342
+ * If what you want is not just knowing whether the parametric value is following the
343
+ * type `T` or not, but throwing an exception with detailed reason, you can choose
344
+ * {@link assertEquals} function instead. Also, if you want to know all the errors with
345
+ * detailed reasons, {@link validateEquals} function would be useful.
346
+ *
347
+ * On the other hand, if you want to allow superfluous property that is not enrolled
348
+ * to the type `T`, you can use {@link is} function instead.
349
+ *
350
+ * @template T Type of the input value
351
+ * @param input A value to be tested
352
+ * @returns Whether the parametric value is equivalent to the type `T` or not
353
+ *
354
+ * @author Jeongho Nam - https://github.com/samchon
355
+ */
356
+ export function equals<T>(input: unknown): input is T;
357
+
358
+ /**
359
+ * @internal
360
+ */
361
+ export function equals(): never {
362
+ halt("equals");
363
+ }
364
+ Object.assign(equals, Namespace.is());
365
+
366
+ /**
367
+ * Validates equality between a value and its type.
368
+ *
369
+ * Validates a parametric value type and archives all the type errors into an
370
+ * {@link IValidation.errors} array, if the parametric value is not following the
371
+ * type `T` or some superfluous property that is not listed on the type `T` has been
372
+ * found. Of course, if the parametric value is following the type `T` and no
373
+ * superfluous property exists, the {@link IValidation.errors} array would be empty
374
+ * and {@link IValidation.success} would have the `true` value.
375
+ *
376
+ * If what you want is not finding all the error, but asserting the parametric value
377
+ * type with exception throwing, you can choose {@link assert} function instead.
378
+ * Otherwise, you just want to know whether the parametric value is matched with the
379
+ * type `T`, {@link is} function is the way to go.
380
+ *
381
+ * On the other and, if you don't want to allow any superfluous property that is not
382
+ * enrolled to the type `T`, you can use {@link validateEquals} function instead.
383
+ *
384
+ * @template Type of the input value
385
+ * @param input A value to be validated
386
+ * @returns Validation result
387
+ *
388
+ * @author Jeongho Nam - https://github.com/samchon
389
+ */
390
+ export function validateEquals<T>(input: T): IValidation<T>;
391
+
392
+ /**
393
+ * Validates equality between a value and its type.
394
+ *
395
+ * Validates a parametric value type and archives all the type errors into an
396
+ * {@link IValidation.errors} array, if the parametric value is not following the
397
+ * type `T` or some superfluous property that is not listed on the type `T` has been
398
+ * found. Of course, if the parametric value is following the type `T` and no
399
+ * superfluous property exists, the {@link IValidation.errors} array would be empty
400
+ * and {@link IValidation.success} would have the `true` value.
401
+ *
402
+ * If what you want is not finding all the error, but asserting the parametric value
403
+ * type with exception throwing, you can choose {@link assert} function instead.
404
+ * Otherwise, you just want to know whether the parametric value is matched with the
405
+ * type `T`, {@link is} function is the way to go.
406
+ *
407
+ * On the other and, if you don't want to allow any superfluous property that is not
408
+ * enrolled to the type `T`, you can use {@link validateEquals} function instead.
409
+ *
410
+ * @template Type of the input value
411
+ * @param input A value to be validated
412
+ * @returns Validation result
413
+ *
414
+ * @author Jeongho Nam - https://github.com/samchon
415
+ */
416
+ export function validateEquals<T>(input: unknown): IValidation<T>;
417
+
418
+ /**
419
+ * @internal
420
+ */
421
+ export function validateEquals(): never {
422
+ halt("validateEquals");
423
+ }
424
+ Object.assign(validateEquals, Namespace.validate());
425
+
426
+ /* -----------------------------------------------------------
427
+ RANDOM
428
+ ----------------------------------------------------------- */
429
+ /**
430
+ * > You must configure the generic argument `T`.
431
+ *
432
+ * Generate random data.
433
+ *
434
+ * Generates a random data following type the `T`.
435
+ *
436
+ * For reference, this `typia.random()` function generates only primitive type.
437
+ * If there're some methods in the type `T` or its nested instances, those would
438
+ * be ignored. Also, when the type `T` has a `toJSON()` method, its return type
439
+ * would be generated instead.
440
+ *
441
+ * @template T Type of data to generate
442
+ * @param generator Random data generator
443
+ * @return Randomly generated data
444
+ *
445
+ * @author Jeongho Nam - https://github.com/samchon
446
+ */
447
+ export function random(generator?: Partial<IRandomGenerator>): never;
448
+
449
+ /**
450
+ * Generate random data.
451
+ *
452
+ * Generates a random data following type the `T`.
453
+ *
454
+ * For reference, this `typia.random()` function generates only primitive type.
455
+ * If there're some methods in the type `T` or its nested instances, those would
456
+ * be ignored. Also, when the type `T` has a `toJSON()` method, its return type
457
+ * would be generated instead.
458
+ *
459
+ * @template T Type of data to generate
460
+ * @param generator Random data generator
461
+ * @return Randomly generated data
462
+ *
463
+ * @author Jeongho Nam - https://github.com/samchon
464
+ */
465
+ export function random<T>(generator?: Partial<IRandomGenerator>): Resolved<T>;
466
+
467
+ /**
468
+ * @internal
469
+ */
470
+ export function random(): never {
471
+ halt("random");
472
+ }
473
+ Object.assign(random, Namespace.random());
474
+
475
+ /**
476
+ * @internal
477
+ */
478
+ export function metadata(): never;
479
+
480
+ /**
481
+ * @internal
482
+ */
483
+ export function metadata<Types extends unknown[]>(): IMetadataApplication;
484
+
485
+ /**
486
+ * @internal
487
+ */
488
+ export function metadata(): never {
489
+ halt("metadata");
490
+ }
491
+
492
+ /* -----------------------------------------------------------
493
+ FACTORY FUNCTIONS
494
+ ----------------------------------------------------------- */
495
+ /**
496
+ * Creates a reusable {@link assert} function.
497
+ *
498
+ * @danger You must configure the generic argument `T`
499
+ * @returns Nothing until you configure the generic argument `T`
500
+ * @throws compile error
501
+ *
502
+ * @author Jeongho Nam - https://github.com/samchon
503
+ */
504
+ export function createAssert(): never;
505
+
506
+ /**
507
+ * Creates a reusable {@link assert} function.
508
+ *
509
+ * @template T Type of the input value
510
+ * @returns A reusable `assert` function
511
+ *
512
+ * @author Jeongho Nam - https://github.com/samchon
513
+ */
514
+ export function createAssert<T>(): (input: unknown) => T;
515
+
516
+ /**
517
+ * @internal
518
+ */
519
+ export function createAssert<T>(): (input: unknown) => T {
520
+ halt("createAssert");
521
+ }
522
+ Object.assign(createAssert, assert);
523
+
524
+ /**
525
+ * Creates a reusable {@link is} function.
526
+ *
527
+ * @danger You must configure the generic argument `T`
528
+ * @returns Nothing until you configure the generic argument `T`
529
+ * @throws compile error
530
+ *
531
+ * @author Jeongho Nam - https://github.com/samchon
532
+ */
533
+ export function createIs(): never;
534
+
535
+ /**
536
+ * Creates a reusable {@link is} function.
537
+ *
538
+ * @template T Type of the input value
539
+ * @returns A reusable `is` function
540
+ *
541
+ * @author Jeongho Nam - https://github.com/samchon
542
+ */
543
+ export function createIs<T>(): (input: unknown) => input is T;
544
+
545
+ /**
546
+ * @internal
547
+ */
548
+ export function createIs<T>(): (input: unknown) => input is T {
549
+ halt("createIs");
550
+ }
551
+ Object.assign(createIs, is);
552
+
553
+ /**
554
+ * Creates a reusable {@link validate} function.
555
+ *
556
+ * @danger You must configure the generic argument `T`
557
+ * @returns Nothing until you configure the generic argument `T`
558
+ * @throws compile error
559
+ *
560
+ * @author Jeongho Nam - https://github.com/samchon
561
+ */
562
+ export function createValidate(): never;
563
+
564
+ /**
565
+ * Creates a reusable {@link validate} function.
566
+ *
567
+ * @template T Type of the input value
568
+ * @returns A reusable `validate` function
569
+ *
570
+ * @author Jeongho Nam - https://github.com/samchon
571
+ */
572
+ export function createValidate<T>(): (input: unknown) => IValidation<T>;
573
+
574
+ /**
575
+ * @internal
576
+ */
577
+ export function createValidate(): (input: unknown) => IValidation {
578
+ halt("createValidate");
579
+ }
580
+ Object.assign(createValidate, validate);
581
+
582
+ /**
583
+ * Creates a reusable {@link assertEquals} function.
584
+ *
585
+ * @danger You must configure the generic argument `T`
586
+ * @returns Nothing until you configure the generic argument `T`
587
+ * @throws compile error
588
+ *
589
+ * @author Jeongho Nam - https://github.com/samchon
590
+ */
591
+ export function createAssertEquals(): never;
592
+
593
+ /**
594
+ * Creates a reusable {@link assertEquals} function.
595
+ *
596
+ * @template T Type of the input value
597
+ * @returns A reusable `assertEquals` function
598
+ *
599
+ * @author Jeongho Nam - https://github.com/samchon
600
+ */
601
+ export function createAssertEquals<T>(): (input: unknown) => T;
602
+
603
+ /**
604
+ * @internal
605
+ */
606
+ export function createAssertEquals<T>(): (input: unknown) => T {
607
+ halt("createAssertEquals");
608
+ }
609
+ Object.assign(createAssertEquals, assertEquals);
610
+
611
+ /**
612
+ * Creates a reusable {@link equals} function.
613
+ *
614
+ * @danger You must configure the generic argument `T`
615
+ * @returns Nothing until you configure the generic argument `T`
616
+ * @throws compile error
617
+ *
618
+ * @author Jeongho Nam - https://github.com/samchon
619
+ */
620
+ export function createEquals(): never;
621
+
622
+ /**
623
+ * Creates a reusable {@link equals} function.
624
+ *
625
+ * @template T Type of the input value
626
+ * @returns A reusable `equals` function
627
+ *
628
+ * @author Jeongho Nam - https://github.com/samchon
629
+ */
630
+ export function createEquals<T>(): (input: unknown) => input is T;
631
+
632
+ /**
633
+ * @internal
634
+ */
635
+ export function createEquals<T>(): (input: unknown) => input is T {
636
+ halt("createEquals");
637
+ }
638
+ Object.assign(createEquals, equals);
639
+
640
+ /**
641
+ * Creates a reusable {@link validateEquals} function.
642
+ *
643
+ * @danger You must configure the generic argument `T`
644
+ * @returns Nothing until you configure the generic argument `T`
645
+ * @throws compile error
646
+ *
647
+ * @author Jeongho Nam - https://github.com/samchon
648
+ */
649
+ export function createValidateEquals(): never;
650
+
651
+ /**
652
+ * Creates a reusable {@link validateEquals} function.
653
+ *
654
+ * @template T Type of the input value
655
+ * @returns A reusable `validateEquals` function
656
+ *
657
+ * @author Jeongho Nam - https://github.com/samchon
658
+ */
659
+ export function createValidateEquals<T>(): (input: unknown) => IValidation<T>;
660
+
661
+ /**
662
+ * @internal
663
+ */
664
+ export function createValidateEquals(): (input: unknown) => IValidation {
665
+ halt("createValidateEquals");
666
+ }
667
+ Object.assign(createValidateEquals, validateEquals);
668
+
669
+ /**
670
+ * Creates a reusable {@link random} function.
671
+ *
672
+ * @danger You must configure the generic argument `T`
673
+ * @param generator Random data generator
674
+ * @returns Nothing until you configure the generic argument `T`
675
+ * @throws compile error
676
+ *
677
+ * @author Jeongho Nam - https://github.com/samchon
678
+ */
679
+ export function createRandom(generator?: Partial<IRandomGenerator>): never;
680
+
681
+ /**
682
+ * Creates a resuable {@link random} function.
683
+ *
684
+ * @template T Type of the input value
685
+ * @param generator Random data generator
686
+ * @returns A reusable `random` function
687
+ *
688
+ * @author Jeongho Nam - https://github.com/samchon
689
+ */
690
+ export function createRandom<T>(
691
+ generator?: Partial<IRandomGenerator>,
692
+ ): () => Resolved<T>;
693
+
694
+ /**
695
+ * @internal
696
+ */
697
+ export function createRandom(): never {
698
+ halt("createRandom");
699
+ }
700
+ Object.assign(createRandom, random);
701
+
702
+ /**
703
+ * @internal
704
+ */
705
+ function halt(name: string): never {
706
+ throw new Error(
707
+ `Error on typia.${name}(): no transform has been configured. Read and follow https://typia.io/docs/setup please.`,
708
+ );
709
+ }