typia 5.0.0-dev.20230821 → 5.0.0-dev.20230823

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 (237) hide show
  1. package/README.md +1 -1
  2. package/lib/factories/MetadataFactory.js +9 -0
  3. package/lib/factories/MetadataFactory.js.map +1 -1
  4. package/lib/factories/ProtobufFactory.js +8 -0
  5. package/lib/factories/ProtobufFactory.js.map +1 -1
  6. package/lib/functional/$ProtobufReader.d.ts +2 -0
  7. package/lib/functional/$ProtobufReader.js +14 -3
  8. package/lib/functional/$ProtobufReader.js.map +1 -1
  9. package/lib/functional/$ProtobufSizer.js +1 -1
  10. package/lib/functional/$ProtobufSizer.js.map +1 -1
  11. package/lib/functional/$ProtobufWriter.js +0 -1
  12. package/lib/functional/$ProtobufWriter.js.map +1 -1
  13. package/lib/programmers/helpers/ProtobufUtil.d.ts +3 -1
  14. package/lib/programmers/helpers/ProtobufUtil.js +5 -1
  15. package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
  16. package/lib/programmers/json/JsonValidateParseProgrammer.js +2 -3
  17. package/lib/programmers/json/JsonValidateParseProgrammer.js.map +1 -1
  18. package/lib/programmers/protobuf/ProtobufAssertDecodeProgrammer.js +2 -3
  19. package/lib/programmers/protobuf/ProtobufAssertDecodeProgrammer.js.map +1 -1
  20. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +362 -6
  21. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  22. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +21 -64
  23. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
  24. package/lib/programmers/protobuf/ProtobufIsDecodeProgrammer.js +1 -1
  25. package/lib/programmers/protobuf/ProtobufIsDecodeProgrammer.js.map +1 -1
  26. package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +1 -1
  27. package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
  28. package/lib/programmers/protobuf/ProtobufValidateDecodeProgrammer.js +3 -4
  29. package/lib/programmers/protobuf/ProtobufValidateDecodeProgrammer.js.map +1 -1
  30. package/lib/protobuf.d.ts +8 -9
  31. package/lib/protobuf.js +7 -0
  32. package/lib/protobuf.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/factories/ExpressionFactory.ts +115 -115
  35. package/src/factories/MetadataCollection.ts +269 -269
  36. package/src/factories/MetadataFactory.ts +46 -34
  37. package/src/factories/MetadataTagFactory.ts +364 -364
  38. package/src/factories/ProtobufFactory.ts +266 -251
  39. package/src/factories/StatementFactory.ts +72 -72
  40. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  41. package/src/factories/internal/metadata/emend_metadata_atomics.ts +33 -33
  42. package/src/factories/internal/metadata/emplace_metadata_alias.ts +40 -40
  43. package/src/factories/internal/metadata/emplace_metadata_array.ts +34 -34
  44. package/src/factories/internal/metadata/emplace_metadata_object.ts +136 -136
  45. package/src/factories/internal/metadata/emplace_metadata_tuple.ts +50 -50
  46. package/src/factories/internal/metadata/explore_metadata.ts +38 -38
  47. package/src/factories/internal/metadata/iterate_metadata.ts +81 -81
  48. package/src/factories/internal/metadata/iterate_metadata_alias.ts +30 -30
  49. package/src/factories/internal/metadata/iterate_metadata_array.ts +24 -24
  50. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  51. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  52. package/src/factories/internal/metadata/iterate_metadata_collection.ts +133 -133
  53. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  54. package/src/factories/internal/metadata/iterate_metadata_intersection.ts +84 -84
  55. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  56. package/src/factories/internal/metadata/iterate_metadata_native.ts +219 -219
  57. package/src/factories/internal/metadata/iterate_metadata_object.ts +43 -43
  58. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +49 -49
  59. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  60. package/src/factories/internal/metadata/iterate_metadata_sort.ts +69 -69
  61. package/src/factories/internal/metadata/iterate_metadata_tag.ts +31 -31
  62. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  63. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +24 -24
  64. package/src/factories/internal/metadata/iterate_metadata_union.ts +24 -24
  65. package/src/functional/$ProtobufReader.ts +201 -188
  66. package/src/functional/$ProtobufSizer.ts +147 -144
  67. package/src/functional/$ProtobufWriter.ts +151 -152
  68. package/src/functional/$number.ts +13 -13
  69. package/src/functional/$strlen.ts +7 -7
  70. package/src/functional/$varint.ts +130 -130
  71. package/src/functional/$zigzag.ts +39 -39
  72. package/src/functional/IProtobufWriter.ts +18 -18
  73. package/src/functional/Namespace.ts +149 -149
  74. package/src/json.ts +648 -648
  75. package/src/misc.ts +651 -651
  76. package/src/module.ts +708 -708
  77. package/src/programmers/CheckerProgrammer.ts +1173 -1173
  78. package/src/programmers/FeatureProgrammer.ts +497 -497
  79. package/src/programmers/IsProgrammer.ts +239 -239
  80. package/src/programmers/IsPruneProgrammer.ts +73 -73
  81. package/src/programmers/RandomProgrammer.ts +578 -578
  82. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  83. package/src/programmers/helpers/CloneJoiner.ts +107 -107
  84. package/src/programmers/helpers/FunctionImporeter.ts +89 -89
  85. package/src/programmers/helpers/IExpressionEntry.ts +12 -12
  86. package/src/programmers/helpers/ProtobufUtil.ts +29 -24
  87. package/src/programmers/helpers/ProtobufWire.ts +34 -34
  88. package/src/programmers/helpers/PruneJoiner.ts +143 -143
  89. package/src/programmers/helpers/RandomJoiner.ts +173 -173
  90. package/src/programmers/helpers/RandomRanger.ts +208 -208
  91. package/src/programmers/helpers/StringifyPredicator.ts +13 -13
  92. package/src/programmers/helpers/UnionExplorer.ts +310 -310
  93. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  94. package/src/programmers/helpers/disable_function_importer_declare.ts +27 -27
  95. package/src/programmers/internal/application_alias.ts +66 -66
  96. package/src/programmers/internal/application_array.ts +30 -30
  97. package/src/programmers/internal/application_constant.ts +26 -26
  98. package/src/programmers/internal/application_default.ts +17 -17
  99. package/src/programmers/internal/application_default_string.ts +33 -33
  100. package/src/programmers/internal/application_native.ts +39 -39
  101. package/src/programmers/internal/application_number.ts +81 -81
  102. package/src/programmers/internal/application_object.ts +165 -165
  103. package/src/programmers/internal/application_resolved.ts +55 -55
  104. package/src/programmers/internal/application_schema.ts +157 -157
  105. package/src/programmers/internal/application_string.ts +44 -44
  106. package/src/programmers/internal/application_templates.ts +25 -25
  107. package/src/programmers/internal/application_tuple.ts +57 -57
  108. package/src/programmers/internal/check_array.ts +30 -30
  109. package/src/programmers/internal/check_array_length.ts +35 -35
  110. package/src/programmers/internal/check_bigint.ts +110 -110
  111. package/src/programmers/internal/check_custom.ts +31 -31
  112. package/src/programmers/internal/check_number.ts +258 -258
  113. package/src/programmers/internal/check_string.ts +25 -25
  114. package/src/programmers/internal/check_string_tags.ts +67 -67
  115. package/src/programmers/internal/check_template.ts +56 -56
  116. package/src/programmers/internal/check_union_array_like.ts +329 -329
  117. package/src/programmers/internal/decode_union_object.ts +84 -84
  118. package/src/programmers/internal/feature_object_entries.ts +63 -63
  119. package/src/programmers/internal/get_comment_tags.ts +23 -23
  120. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  121. package/src/programmers/internal/prune_object_properties.ts +60 -60
  122. package/src/programmers/internal/random_custom.ts +29 -29
  123. package/src/programmers/internal/stringify_regular_properties.ts +83 -83
  124. package/src/programmers/internal/template_to_pattern.ts +15 -15
  125. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +16 -16
  126. package/src/programmers/json/JsonApplicationProgrammer.ts +47 -47
  127. package/src/programmers/json/JsonAssertParseProgrammer.ts +66 -66
  128. package/src/programmers/json/JsonAssertStringifyProgrammer.ts +66 -66
  129. package/src/programmers/json/JsonIsParseProgrammer.ts +72 -72
  130. package/src/programmers/json/JsonIsStringifyProgrammer.ts +76 -76
  131. package/src/programmers/json/JsonStringifyProgrammer.ts +987 -987
  132. package/src/programmers/json/JsonValidateParseProgrammer.ts +63 -70
  133. package/src/programmers/json/JsonValidateStringifyProgrammer.ts +84 -84
  134. package/src/programmers/misc/MiscAssertCloneProgrammer.ts +71 -71
  135. package/src/programmers/misc/MiscAssertPruneProgrammer.ts +68 -68
  136. package/src/programmers/misc/MiscCloneProgrammer.ts +587 -587
  137. package/src/programmers/misc/MiscIsCloneProgrammer.ts +78 -78
  138. package/src/programmers/misc/MiscLiteralsProgrammer.ts +64 -64
  139. package/src/programmers/misc/MiscPruneProgrammer.ts +542 -542
  140. package/src/programmers/misc/MiscValidateCloneProgrammer.ts +85 -85
  141. package/src/programmers/misc/MiscValidatePruneProgrammer.ts +78 -78
  142. package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +66 -69
  143. package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +66 -66
  144. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +669 -38
  145. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +814 -920
  146. package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +75 -75
  147. package/src/programmers/protobuf/ProtobufIsEncodeProgrammer.ts +76 -76
  148. package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +178 -178
  149. package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +75 -83
  150. package/src/programmers/protobuf/ProtobufValidateEncodeProgrammer.ts +86 -86
  151. package/src/protobuf.ts +249 -239
  152. package/src/schemas/json/IJsonApplication.ts +8 -8
  153. package/src/schemas/json/IJsonComponents.ts +33 -33
  154. package/src/schemas/json/IJsonSchema.ts +133 -133
  155. package/src/schemas/metadata/ICommentTag.ts +4 -4
  156. package/src/schemas/metadata/IJsDocTagInfo.ts +10 -10
  157. package/src/schemas/metadata/IMetadata.ts +28 -28
  158. package/src/schemas/metadata/IMetadataAlias.ts +14 -14
  159. package/src/schemas/metadata/IMetadataApplication.ts +7 -7
  160. package/src/schemas/metadata/IMetadataArray.ts +10 -10
  161. package/src/schemas/metadata/IMetadataCollection.ts +11 -11
  162. package/src/schemas/metadata/IMetadataConstant.ts +16 -16
  163. package/src/schemas/metadata/IMetadataDictionary.ts +14 -14
  164. package/src/schemas/metadata/IMetadataEntry.ts +6 -6
  165. package/src/schemas/metadata/IMetadataObject.ts +18 -18
  166. package/src/schemas/metadata/IMetadataProperty.ts +11 -11
  167. package/src/schemas/metadata/IMetadataResolved.ts +6 -6
  168. package/src/schemas/metadata/IMetadataTag.ts +112 -112
  169. package/src/schemas/metadata/IMetadataTuple.ts +10 -10
  170. package/src/schemas/metadata/Metadata.ts +637 -637
  171. package/src/schemas/metadata/MetadataAlias.ts +66 -66
  172. package/src/schemas/metadata/MetadataArray.ts +55 -55
  173. package/src/schemas/metadata/MetadataConstant.ts +3 -3
  174. package/src/schemas/metadata/MetadataObject.ts +139 -139
  175. package/src/schemas/metadata/MetadataProperty.ts +64 -64
  176. package/src/schemas/metadata/MetadataResolved.ts +51 -51
  177. package/src/schemas/metadata/MetadataTuple.ts +58 -58
  178. package/src/transformers/CallExpressionTransformer.ts +240 -240
  179. package/src/transformers/features/AssertTransformer.ts +11 -11
  180. package/src/transformers/features/CreateAssertTransformer.ts +13 -13
  181. package/src/transformers/features/CreateIsTransformer.ts +11 -11
  182. package/src/transformers/features/CreateRandomTransformer.ts +39 -39
  183. package/src/transformers/features/CreateValidateTransformer.ts +13 -13
  184. package/src/transformers/features/IsTransformer.ts +11 -11
  185. package/src/transformers/features/RandomTransformer.ts +42 -42
  186. package/src/transformers/features/ValidateTransformer.ts +11 -11
  187. package/src/transformers/features/json/JsonApplicationTransformer.ts +111 -111
  188. package/src/transformers/features/json/JsonAssertParseTransformer.ts +10 -10
  189. package/src/transformers/features/json/JsonAssertStringifyTransformer.ts +10 -10
  190. package/src/transformers/features/json/JsonCreateAssertParseTransformer.ts +10 -10
  191. package/src/transformers/features/json/JsonCreateAssertStringifyTransformer.ts +12 -12
  192. package/src/transformers/features/json/JsonCreateIsParseTransformer.ts +9 -9
  193. package/src/transformers/features/json/JsonCreateIsStringifyTransformer.ts +10 -10
  194. package/src/transformers/features/json/JsonCreateStringifyTransformer.ts +9 -9
  195. package/src/transformers/features/json/JsonCreateValidateParseTransformer.ts +10 -10
  196. package/src/transformers/features/json/JsonCreateValidateStringifyProgrammer.ts +12 -12
  197. package/src/transformers/features/json/JsonIsParseTransformer.ts +9 -9
  198. package/src/transformers/features/json/JsonIsStringifyTransformer.ts +10 -10
  199. package/src/transformers/features/json/JsonStringifyTransformer.ts +9 -9
  200. package/src/transformers/features/json/JsonValidateParseTransformer.ts +10 -10
  201. package/src/transformers/features/json/JsonValidateStringifyTransformer.ts +10 -10
  202. package/src/transformers/features/misc/MetadataTransformer.ts +53 -53
  203. package/src/transformers/features/misc/MiscAssertCloneTransformer.ts +10 -10
  204. package/src/transformers/features/misc/MiscAssertPruneTransformer.ts +10 -10
  205. package/src/transformers/features/misc/MiscCloneTransformer.ts +9 -9
  206. package/src/transformers/features/misc/MiscCreateAssertCloneTransformer.ts +10 -10
  207. package/src/transformers/features/misc/MiscCreateAssertPruneTransformer.ts +10 -10
  208. package/src/transformers/features/misc/MiscCreateCloneTransformer.ts +9 -9
  209. package/src/transformers/features/misc/MiscCreateIsCloneTransformer.ts +9 -9
  210. package/src/transformers/features/misc/MiscCreateIsPruneTransformer.ts +9 -9
  211. package/src/transformers/features/misc/MiscCreatePruneTransformer.ts +9 -9
  212. package/src/transformers/features/misc/MiscCreateValidateCloneTransformer.ts +10 -10
  213. package/src/transformers/features/misc/MiscCreateValidatePruneTransformer.ts +10 -10
  214. package/src/transformers/features/misc/MiscIsCloneTransformer.ts +9 -9
  215. package/src/transformers/features/misc/MiscIsPruneTransformer.ts +9 -9
  216. package/src/transformers/features/misc/MiscLiteralsTransformer.ts +28 -28
  217. package/src/transformers/features/misc/MiscPruneTransformer.ts +9 -9
  218. package/src/transformers/features/misc/MiscValidateCloneTransformer.ts +10 -10
  219. package/src/transformers/features/misc/MiscValidatePruneTransformer.ts +10 -10
  220. package/src/transformers/features/protobuf/CreateProtobufAssertDecodeTransformer.ts +12 -12
  221. package/src/transformers/features/protobuf/CreateProtobufAssertEncodeTransformer.ts +12 -12
  222. package/src/transformers/features/protobuf/CreateProtobufDecodeTransformer.ts +9 -9
  223. package/src/transformers/features/protobuf/CreateProtobufEncodeTransformer.ts +9 -9
  224. package/src/transformers/features/protobuf/CreateProtobufIsDecodeTransformer.ts +12 -12
  225. package/src/transformers/features/protobuf/CreateProtobufIsEncodeTransformer.ts +12 -12
  226. package/src/transformers/features/protobuf/CreateProtobufValidateDecodeTransformer.ts +12 -12
  227. package/src/transformers/features/protobuf/CreateProtobufValidateEncodeTransformer.ts +12 -12
  228. package/src/transformers/features/protobuf/ProtobufAssertDecodeTransformer.ts +10 -10
  229. package/src/transformers/features/protobuf/ProtobufAssertEncodeTransformer.ts +10 -10
  230. package/src/transformers/features/protobuf/ProtobufDecodeTransformer.ts +10 -10
  231. package/src/transformers/features/protobuf/ProtobufEncodeTransformer.ts +10 -10
  232. package/src/transformers/features/protobuf/ProtobufIsDecodeTransformer.ts +10 -10
  233. package/src/transformers/features/protobuf/ProtobufIsEncodeTransformer.ts +10 -10
  234. package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +31 -31
  235. package/src/transformers/features/protobuf/ProtobufValidateDecodeTransformer.ts +12 -12
  236. package/src/transformers/features/protobuf/ProtobufValidateEncodeTransformer.ts +12 -12
  237. package/src/utils/NameEncoder.ts +32 -32
package/src/module.ts CHANGED
@@ -1,708 +1,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 { 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 { 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
+ }