typia 3.7.5 → 3.7.6

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 (221) hide show
  1. package/README.md +35 -260
  2. package/lib/factories/TypiaFileFactory.js +9 -4
  3. package/lib/factories/TypiaFileFactory.js.map +1 -1
  4. package/lib/module.js +1 -1
  5. package/lib/module.js.map +1 -1
  6. package/lib/programmers/internal/check_string_tags.js +2 -2
  7. package/lib/programmers/internal/check_string_tags.js.map +1 -1
  8. package/lib/programmers/internal/check_template.js +1 -1
  9. package/lib/programmers/internal/check_template.js.map +1 -1
  10. package/package.json +1 -1
  11. package/src/CustomValidatorMap.ts +126 -126
  12. package/src/IRandomGenerator.ts +33 -33
  13. package/src/IValidation.ts +21 -21
  14. package/src/Primitive.ts +104 -104
  15. package/src/TypeGuardError.ts +36 -36
  16. package/src/executable/TypiaGenerateWizard.ts +85 -85
  17. package/src/executable/setup/ArgumentParser.ts +45 -45
  18. package/src/executable/setup/CommandExecutor.ts +8 -8
  19. package/src/executable/setup/FileRetriever.ts +22 -22
  20. package/src/executable/setup/PluginConfigurator.ts +59 -59
  21. package/src/executable/typia.ts +54 -54
  22. package/src/factories/CommentFactory.ts +10 -10
  23. package/src/factories/ExpressionFactory.ts +77 -77
  24. package/src/factories/IdentifierFactory.ts +81 -81
  25. package/src/factories/LiteralFactory.ts +44 -44
  26. package/src/factories/MetadataCollection.ts +122 -122
  27. package/src/factories/MetadataFactory.ts +51 -51
  28. package/src/factories/MetadataTagFactory.ts +302 -302
  29. package/src/factories/StatementFactory.ts +60 -60
  30. package/src/factories/TemplateFactory.ts +56 -56
  31. package/src/factories/TypeFactory.ts +129 -129
  32. package/src/factories/TypiaFileFactory.ts +12 -3
  33. package/src/factories/ValueFactory.ts +12 -12
  34. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  35. package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -142
  36. package/src/factories/internal/metadata/explore_metadata.ts +92 -92
  37. package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
  38. package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
  39. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  40. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  41. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  42. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  43. package/src/factories/internal/metadata/iterate_metadata_native.ts +222 -222
  44. package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
  45. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  46. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  47. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  48. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
  49. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  50. package/src/functional/$any.ts +3 -3
  51. package/src/functional/$dictionary.ts +20 -20
  52. package/src/functional/$every.ts +11 -11
  53. package/src/functional/$guard.ts +35 -35
  54. package/src/functional/$is_between.ts +7 -7
  55. package/src/functional/$is_custom.ts +14 -14
  56. package/src/functional/$is_date.ts +4 -4
  57. package/src/functional/$is_datetime.ts +3 -3
  58. package/src/functional/$is_email.ts +5 -5
  59. package/src/functional/$is_ipv4.ts +5 -5
  60. package/src/functional/$is_ipv6.ts +5 -5
  61. package/src/functional/$is_url.ts +5 -5
  62. package/src/functional/$is_uuid.ts +5 -5
  63. package/src/functional/$join.ts +50 -50
  64. package/src/functional/$number.ts +12 -12
  65. package/src/functional/$report.ts +15 -15
  66. package/src/functional/$rest.ts +3 -3
  67. package/src/functional/$string.ts +37 -37
  68. package/src/functional/$tail.ts +6 -6
  69. package/src/functional/Namespace.ts +127 -127
  70. package/src/index.ts +4 -4
  71. package/src/metadata/ICommentTag.ts +4 -4
  72. package/src/metadata/IJsDocTagInfo.ts +10 -10
  73. package/src/metadata/IMetadata.ts +25 -25
  74. package/src/metadata/IMetadataApplication.ts +7 -7
  75. package/src/metadata/IMetadataConstant.ts +16 -16
  76. package/src/metadata/IMetadataEntry.ts +6 -6
  77. package/src/metadata/IMetadataObject.ts +29 -29
  78. package/src/metadata/IMetadataProperty.ts +11 -11
  79. package/src/metadata/IMetadataTag.ts +105 -105
  80. package/src/metadata/Metadata.ts +534 -534
  81. package/src/metadata/MetadataConstant.ts +3 -3
  82. package/src/metadata/MetadataObject.ts +131 -131
  83. package/src/metadata/MetadataProperty.ts +64 -64
  84. package/src/module.ts +2043 -2043
  85. package/src/programmers/ApplicationProgrammer.ts +55 -55
  86. package/src/programmers/AssertCloneProgrammer.ts +70 -70
  87. package/src/programmers/AssertParseProgrammer.ts +65 -65
  88. package/src/programmers/AssertProgrammer.ts +284 -284
  89. package/src/programmers/AssertPruneProgrammer.ts +67 -67
  90. package/src/programmers/AssertStringifyProgrammer.ts +71 -71
  91. package/src/programmers/CheckerProgrammer.ts +922 -922
  92. package/src/programmers/CloneProgrammer.ts +388 -388
  93. package/src/programmers/FeatureProgrammer.ts +512 -512
  94. package/src/programmers/IsCloneProgrammer.ts +80 -80
  95. package/src/programmers/IsParseProgrammer.ts +74 -74
  96. package/src/programmers/IsProgrammer.ts +206 -206
  97. package/src/programmers/IsPruneProgrammer.ts +75 -75
  98. package/src/programmers/IsStringifyProgrammer.ts +81 -81
  99. package/src/programmers/LiteralsProgrammer.ts +65 -65
  100. package/src/programmers/PruneProgrammer.ts +343 -343
  101. package/src/programmers/RandomProgrammer.ts +413 -413
  102. package/src/programmers/StringifyProgrammer.ts +801 -801
  103. package/src/programmers/ValidateCloneProgrammer.ts +90 -90
  104. package/src/programmers/ValidateParseProgrammer.ts +69 -69
  105. package/src/programmers/ValidateProgrammer.ts +317 -317
  106. package/src/programmers/ValidatePruneProgrammer.ts +83 -83
  107. package/src/programmers/ValidateStringifyProgrammer.ts +89 -89
  108. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  109. package/src/programmers/helpers/CloneJoiner.ts +134 -134
  110. package/src/programmers/helpers/FunctionImporeter.ts +55 -55
  111. package/src/programmers/helpers/ICheckEntry.ts +12 -12
  112. package/src/programmers/helpers/IExpressionEntry.ts +12 -12
  113. package/src/programmers/helpers/OptionPredicator.ts +19 -19
  114. package/src/programmers/helpers/PruneJoiner.ts +52 -52
  115. package/src/programmers/helpers/RandomJoiner.ts +161 -161
  116. package/src/programmers/helpers/RandomRanger.ts +216 -216
  117. package/src/programmers/helpers/StringifyJoinder.ts +114 -114
  118. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  119. package/src/programmers/helpers/UnionExplorer.ts +281 -281
  120. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  121. package/src/programmers/internal/application_array.ts +37 -37
  122. package/src/programmers/internal/application_boolean.ts +17 -17
  123. package/src/programmers/internal/application_constant.ts +29 -29
  124. package/src/programmers/internal/application_default.ts +17 -17
  125. package/src/programmers/internal/application_default_string.ts +32 -32
  126. package/src/programmers/internal/application_native.ts +32 -32
  127. package/src/programmers/internal/application_number.ts +73 -73
  128. package/src/programmers/internal/application_object.ts +153 -153
  129. package/src/programmers/internal/application_schema.ts +184 -184
  130. package/src/programmers/internal/application_string.ts +45 -45
  131. package/src/programmers/internal/application_templates.ts +27 -27
  132. package/src/programmers/internal/application_tuple.ts +29 -29
  133. package/src/programmers/internal/check_array.ts +30 -30
  134. package/src/programmers/internal/check_array_length.ts +35 -35
  135. package/src/programmers/internal/check_bigint.ts +82 -82
  136. package/src/programmers/internal/check_custom.ts +33 -33
  137. package/src/programmers/internal/check_dynamic_properties.ts +197 -197
  138. package/src/programmers/internal/check_everything.ts +28 -28
  139. package/src/programmers/internal/check_native.ts +21 -21
  140. package/src/programmers/internal/check_number.ts +177 -177
  141. package/src/programmers/internal/check_object.ts +55 -55
  142. package/src/programmers/internal/check_string.ts +25 -25
  143. package/src/programmers/internal/check_string_tags.ts +9 -15
  144. package/src/programmers/internal/check_template.ts +6 -9
  145. package/src/programmers/internal/check_union_array_like.ts +272 -272
  146. package/src/programmers/internal/check_union_tuple.ts +35 -35
  147. package/src/programmers/internal/decode_union_object.ts +73 -73
  148. package/src/programmers/internal/feature_object_entries.ts +63 -63
  149. package/src/programmers/internal/get_comment_tags.ts +23 -23
  150. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  151. package/src/programmers/internal/prune_object_properties.ts +60 -60
  152. package/src/programmers/internal/random_custom.ts +30 -30
  153. package/src/programmers/internal/stringify_dynamic_properties.ts +168 -168
  154. package/src/programmers/internal/stringify_native.ts +8 -8
  155. package/src/programmers/internal/stringify_regular_properties.ts +84 -84
  156. package/src/programmers/internal/template_to_pattern.ts +15 -15
  157. package/src/schemas/IJsonApplication.ts +9 -9
  158. package/src/schemas/IJsonComponents.ts +26 -26
  159. package/src/schemas/IJsonSchema.ts +121 -121
  160. package/src/transform.ts +21 -21
  161. package/src/transformers/CallExpressionTransformer.ts +174 -174
  162. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  163. package/src/transformers/FileTransformer.ts +49 -49
  164. package/src/transformers/IProject.ts +11 -11
  165. package/src/transformers/ITransformOptions.ts +62 -62
  166. package/src/transformers/ImportTransformer.ts +66 -66
  167. package/src/transformers/NodeTransformer.ts +19 -19
  168. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +119 -119
  169. package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
  170. package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
  171. package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
  172. package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
  173. package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
  174. package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
  175. package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
  176. package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
  177. package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
  178. package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +41 -41
  179. package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
  180. package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
  181. package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
  182. package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
  183. package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +30 -30
  184. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +54 -54
  185. package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
  186. package/src/transformers/features/miscellaneous/RandomTransformer.ts +46 -46
  187. package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
  188. package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
  189. package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
  190. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
  191. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
  192. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
  193. package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
  194. package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
  195. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
  196. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +9 -9
  197. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
  198. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
  199. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +11 -11
  200. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
  201. package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
  202. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
  203. package/src/transformers/features/validators/AssertTransformer.ts +11 -11
  204. package/src/transformers/features/validators/CreateAssertTransformer.ts +12 -12
  205. package/src/transformers/features/validators/CreateIsTransformer.ts +10 -10
  206. package/src/transformers/features/validators/CreateValidateTransformer.ts +12 -12
  207. package/src/transformers/features/validators/IsTransformer.ts +10 -10
  208. package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
  209. package/src/transformers/internal/GenericTransformer.ts +99 -99
  210. package/src/typings/Atomic.ts +17 -17
  211. package/src/typings/ClassProperties.ts +5 -5
  212. package/src/typings/Customizable.ts +5 -5
  213. package/src/typings/OmitNever.ts +3 -3
  214. package/src/typings/SpecialFields.ts +3 -3
  215. package/src/typings/Writable.ts +11 -11
  216. package/src/utils/ArrayUtil.ts +49 -49
  217. package/src/utils/Escaper.ts +50 -50
  218. package/src/utils/MapUtil.ts +14 -14
  219. package/src/utils/PatternUtil.ts +30 -30
  220. package/src/utils/RandomGenerator.ts +96 -96
  221. package/src/utils/Singleton.ts +17 -17
@@ -1,126 +1,126 @@
1
- import { Customizable } from "./typings/Customizable";
2
-
3
- /**
4
- * Map of custom validators.
5
- *
6
- * Map of custom validator functions, storing tag name and type of target value
7
- * as key, and custom validator function as value.
8
- *
9
- * When you want to add a custom validation logic utilizing comment tags, you
10
- * can insert a custom validator function with specific tag name and type of
11
- * the target value like below.
12
- *
13
- * ```ts
14
- * typia.customValidators.insert("powerOf")("number")(
15
- * (text: string) => {
16
- * const denominator: number = Math.log(Number(text));
17
- * return (value: number) => {
18
- * value = Math.log(value) / denominator;
19
- * return value === Math.floor(value);
20
- * };
21
- * }
22
- * );
23
- * typia.customValidators.insert("dollar")("string")(
24
- * () => (value: string) => value.startsWith("$"),
25
- * );
26
- *
27
- * interface TagCustom {
28
- * /**
29
- * * @powerOf 10
30
- * *\/
31
- * powerOf: number;
32
- *
33
- * /**
34
- * * @dollar
35
- * *\/
36
- * dollar: string;
37
- * }
38
- * ```
39
- *
40
- * @author Jeongho Nam - https://github.com/samchon
41
- */
42
- export interface CustomValidatorMap {
43
- /**
44
- * Get number of stored tags.
45
- *
46
- * @return Number of stored tags
47
- */
48
- size(): number;
49
-
50
- /**
51
- * Get number of stored types of the specified tag name.
52
- *
53
- * In other words, number of stored custom validator functions of
54
- * the specified tag name.
55
- *
56
- * @param name Tag name
57
- * @return Number of stored types function
58
- */
59
- size(name: string): number;
60
-
61
- /**
62
- * Test whether custom validator function exists or not.
63
- *
64
- * @param name Tag name
65
- * @param type Type of the target value
66
- * @returns Whether exists or not
67
- */
68
- has: (name: string) => (type: keyof Customizable) => boolean;
69
-
70
- /**
71
- * Get custom validator function.
72
- *
73
- * @param name Tag name
74
- * @param type Type of the target value
75
- * @returns Custom validator function or undefined value
76
- */
77
- get(
78
- name: string,
79
- ): <Type extends keyof Customizable>(
80
- type: Type,
81
- ) => CustomValidatorMap.Closure<Type> | undefined;
82
-
83
- /**
84
- * Insert a new custom validator function.
85
- *
86
- * You can add a custom validation logic utilizing comment tags,
87
- * by inserting a function which returns a boolean value, with specific
88
- * tag name and type of the target value.
89
- *
90
- * However, if you try to insert a duplicated tag name and type, the
91
- * closure function would not be enrolled and `false` value would be
92
- * returned.
93
- *
94
- * @param name Tag name
95
- * @param type Type of the target value
96
- * @param closure Custom validator function
97
- * @returns Whether succeeded to insert or not
98
- */
99
- insert(
100
- name: string,
101
- ): <Type extends keyof Customizable>(
102
- type: Type,
103
- ) => (closure: CustomValidatorMap.Closure<Type>) => boolean;
104
-
105
- /**
106
- * Erase custom validator function.
107
- *
108
- * @param name Tag name
109
- * @param type Type of the target value
110
- * @returns Whether succeeded to erase or not
111
- */
112
- erase(name: string): (type: keyof Customizable) => boolean;
113
- }
114
- export namespace CustomValidatorMap {
115
- /**
116
- * Type of closure function of custom validation.
117
- *
118
- * @template Type Type of the target value
119
- * @param text Text of the tag. For example, if the tag is `@powerOf 10`, `text` is 10.
120
- * @param value Value to validate
121
- * @returns Whether the value is valid or not
122
- */
123
- export type Closure<Type extends keyof Customizable> = (
124
- text: string,
125
- ) => (value: Customizable[Type]) => boolean;
126
- }
1
+ import { Customizable } from "./typings/Customizable";
2
+
3
+ /**
4
+ * Map of custom validators.
5
+ *
6
+ * Map of custom validator functions, storing tag name and type of target value
7
+ * as key, and custom validator function as value.
8
+ *
9
+ * When you want to add a custom validation logic utilizing comment tags, you
10
+ * can insert a custom validator function with specific tag name and type of
11
+ * the target value like below.
12
+ *
13
+ * ```ts
14
+ * typia.customValidators.insert("powerOf")("number")(
15
+ * (text: string) => {
16
+ * const denominator: number = Math.log(Number(text));
17
+ * return (value: number) => {
18
+ * value = Math.log(value) / denominator;
19
+ * return value === Math.floor(value);
20
+ * };
21
+ * }
22
+ * );
23
+ * typia.customValidators.insert("dollar")("string")(
24
+ * () => (value: string) => value.startsWith("$"),
25
+ * );
26
+ *
27
+ * interface TagCustom {
28
+ * /**
29
+ * * @powerOf 10
30
+ * *\/
31
+ * powerOf: number;
32
+ *
33
+ * /**
34
+ * * @dollar
35
+ * *\/
36
+ * dollar: string;
37
+ * }
38
+ * ```
39
+ *
40
+ * @author Jeongho Nam - https://github.com/samchon
41
+ */
42
+ export interface CustomValidatorMap {
43
+ /**
44
+ * Get number of stored tags.
45
+ *
46
+ * @return Number of stored tags
47
+ */
48
+ size(): number;
49
+
50
+ /**
51
+ * Get number of stored types of the specified tag name.
52
+ *
53
+ * In other words, number of stored custom validator functions of
54
+ * the specified tag name.
55
+ *
56
+ * @param name Tag name
57
+ * @return Number of stored types function
58
+ */
59
+ size(name: string): number;
60
+
61
+ /**
62
+ * Test whether custom validator function exists or not.
63
+ *
64
+ * @param name Tag name
65
+ * @param type Type of the target value
66
+ * @returns Whether exists or not
67
+ */
68
+ has: (name: string) => (type: keyof Customizable) => boolean;
69
+
70
+ /**
71
+ * Get custom validator function.
72
+ *
73
+ * @param name Tag name
74
+ * @param type Type of the target value
75
+ * @returns Custom validator function or undefined value
76
+ */
77
+ get(
78
+ name: string,
79
+ ): <Type extends keyof Customizable>(
80
+ type: Type,
81
+ ) => CustomValidatorMap.Closure<Type> | undefined;
82
+
83
+ /**
84
+ * Insert a new custom validator function.
85
+ *
86
+ * You can add a custom validation logic utilizing comment tags,
87
+ * by inserting a function which returns a boolean value, with specific
88
+ * tag name and type of the target value.
89
+ *
90
+ * However, if you try to insert a duplicated tag name and type, the
91
+ * closure function would not be enrolled and `false` value would be
92
+ * returned.
93
+ *
94
+ * @param name Tag name
95
+ * @param type Type of the target value
96
+ * @param closure Custom validator function
97
+ * @returns Whether succeeded to insert or not
98
+ */
99
+ insert(
100
+ name: string,
101
+ ): <Type extends keyof Customizable>(
102
+ type: Type,
103
+ ) => (closure: CustomValidatorMap.Closure<Type>) => boolean;
104
+
105
+ /**
106
+ * Erase custom validator function.
107
+ *
108
+ * @param name Tag name
109
+ * @param type Type of the target value
110
+ * @returns Whether succeeded to erase or not
111
+ */
112
+ erase(name: string): (type: keyof Customizable) => boolean;
113
+ }
114
+ export namespace CustomValidatorMap {
115
+ /**
116
+ * Type of closure function of custom validation.
117
+ *
118
+ * @template Type Type of the target value
119
+ * @param text Text of the tag. For example, if the tag is `@powerOf 10`, `text` is 10.
120
+ * @param value Value to validate
121
+ * @returns Whether the value is valid or not
122
+ */
123
+ export type Closure<Type extends keyof Customizable> = (
124
+ text: string,
125
+ ) => (value: Customizable[Type]) => boolean;
126
+ }
@@ -1,33 +1,33 @@
1
- import { Customizable } from "./typings/Customizable";
2
-
3
- export interface IRandomGenerator {
4
- boolean(): boolean;
5
- integer(minimum?: number, maximum?: number): number;
6
- number(minimum?: number, maximum?: number): number;
7
- bigint(minimum?: bigint, maximum?: bigint): bigint;
8
- string(length?: number): string;
9
- array<T>(closure: (index: number) => T, count?: number): T[];
10
-
11
- uuid(): string;
12
- email(): string;
13
- url(): string;
14
- ipv4(): string;
15
- ipv6(): string;
16
- pattern(regex: RegExp): string;
17
- date(minimum?: number, maximum?: number): string;
18
- datetime(minimum?: number, maximum?: number): string;
19
-
20
- customs?: IRandomGenerator.CustomMap;
21
- }
22
- export namespace IRandomGenerator {
23
- export type CustomMap = {
24
- [Type in keyof Customizable]?: (
25
- tags: ICommentTag[],
26
- ) => Customizable[Type] | undefined;
27
- };
28
-
29
- export interface ICommentTag {
30
- name: string;
31
- value?: string;
32
- }
33
- }
1
+ import { Customizable } from "./typings/Customizable";
2
+
3
+ export interface IRandomGenerator {
4
+ boolean(): boolean;
5
+ integer(minimum?: number, maximum?: number): number;
6
+ number(minimum?: number, maximum?: number): number;
7
+ bigint(minimum?: bigint, maximum?: bigint): bigint;
8
+ string(length?: number): string;
9
+ array<T>(closure: (index: number) => T, count?: number): T[];
10
+
11
+ uuid(): string;
12
+ email(): string;
13
+ url(): string;
14
+ ipv4(): string;
15
+ ipv6(): string;
16
+ pattern(regex: RegExp): string;
17
+ date(minimum?: number, maximum?: number): string;
18
+ datetime(minimum?: number, maximum?: number): string;
19
+
20
+ customs?: IRandomGenerator.CustomMap;
21
+ }
22
+ export namespace IRandomGenerator {
23
+ export type CustomMap = {
24
+ [Type in keyof Customizable]?: (
25
+ tags: ICommentTag[],
26
+ ) => Customizable[Type] | undefined;
27
+ };
28
+
29
+ export interface ICommentTag {
30
+ name: string;
31
+ value?: string;
32
+ }
33
+ }
@@ -1,21 +1,21 @@
1
- export type IValidation<T = unknown> =
2
- | IValidation.ISuccess<T>
3
- | IValidation.IFailure;
4
- export namespace IValidation {
5
- export interface ISuccess<T = unknown> {
6
- success: true;
7
- data: T;
8
- errors: [];
9
- }
10
-
11
- export interface IFailure {
12
- success: false;
13
- errors: IError[];
14
- }
15
-
16
- export interface IError {
17
- path: string;
18
- expected: string;
19
- value: any;
20
- }
21
- }
1
+ export type IValidation<T = unknown> =
2
+ | IValidation.ISuccess<T>
3
+ | IValidation.IFailure;
4
+ export namespace IValidation {
5
+ export interface ISuccess<T = unknown> {
6
+ success: true;
7
+ data: T;
8
+ errors: [];
9
+ }
10
+
11
+ export interface IFailure {
12
+ success: false;
13
+ errors: IError[];
14
+ }
15
+
16
+ export interface IError {
17
+ path: string;
18
+ expected: string;
19
+ value: any;
20
+ }
21
+ }
package/src/Primitive.ts CHANGED
@@ -1,104 +1,104 @@
1
- /**
2
- * Primitive type.
3
- *
4
- * `Primitive` is a type of TMP (Type Meta Programming) type who converts its argument as a
5
- * primitive type.
6
- *
7
- * If the target argument is a built-in class who returns its origin primitive type through
8
- * the `valueOf()` method like the `String` or `Number`, its return type would be the
9
- * `string` or `number`.
10
- *
11
- * Otherwise, the target argument is a type of custom class, all of its custom method would
12
- * be erased and its prototype would be changed to the primitive `object`. Therefore, return
13
- * type of the TMP type finally be the primitive object.
14
- *
15
- * In addition, if the target argument is a type of custom class and it has a special
16
- * method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
17
- * but `Primitive<ReturnType<Instance.toJSON>>`.
18
- *
19
- * Before | After
20
- * ------------------------|----------------------------------------
21
- * `Boolean` | `boolean`
22
- * `Number` | `number`
23
- * `String` | `string`
24
- * `Class` | `object`
25
- * `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
26
- * Others | No change
27
- *
28
- * @template Instance Target argument type.
29
- * @author Jenogho Nam - https://github.com/samchon
30
- */
31
- export type Primitive<T> = _Equal<T, _Primitive<T>> extends true
32
- ? T
33
- : _Primitive<T>;
34
-
35
- type _Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
36
-
37
- type _Primitive<Instance> = _ValueOf<Instance> extends object
38
- ? Instance extends object
39
- ? Instance extends _Native
40
- ? {}
41
- : Instance extends IJsonable<infer Raw>
42
- ? _ValueOf<Raw> extends object
43
- ? Raw extends object
44
- ? _PrimitiveObject<Raw> // object would be primitified
45
- : never // cannot be
46
- : _ValueOf<Raw> // atomic value
47
- : _PrimitiveObject<Instance> // object would be primitified
48
- : never // cannot be
49
- : _ValueOf<Instance>;
50
-
51
- type _PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
52
- ? _Primitive<T>[]
53
- : {
54
- [P in keyof Instance]: Instance[P] extends Function
55
- ? never
56
- : _Primitive<Instance[P]>;
57
- };
58
-
59
- type _ValueOf<Instance> = _IsValueOf<Instance, Boolean> extends true
60
- ? boolean
61
- : _IsValueOf<Instance, Number> extends true
62
- ? number
63
- : _IsValueOf<Instance, String> extends true
64
- ? string
65
- : Instance;
66
-
67
- type _Native =
68
- | Set<any>
69
- | Map<any, any>
70
- | WeakSet<any>
71
- | WeakMap<any, any>
72
- | Uint8Array
73
- | Uint8ClampedArray
74
- | Uint16Array
75
- | Uint32Array
76
- | BigUint64Array
77
- | Int8Array
78
- | Int16Array
79
- | Int32Array
80
- | BigInt64Array
81
- | Float32Array
82
- | Float64Array
83
- | ArrayBuffer
84
- | SharedArrayBuffer
85
- | DataView;
86
-
87
- type _IsValueOf<
88
- Instance,
89
- Object extends IValueOf<any>,
90
- > = Instance extends Object
91
- ? Object extends IValueOf<infer Primitive>
92
- ? Instance extends Primitive
93
- ? false
94
- : true // not Primitive, but Object
95
- : false // cannot be
96
- : false;
97
-
98
- interface IValueOf<T> {
99
- valueOf(): T;
100
- }
101
-
102
- interface IJsonable<T> {
103
- toJSON(): T;
104
- }
1
+ /**
2
+ * Primitive type.
3
+ *
4
+ * `Primitive` is a type of TMP (Type Meta Programming) type who converts its argument as a
5
+ * primitive type.
6
+ *
7
+ * If the target argument is a built-in class who returns its origin primitive type through
8
+ * the `valueOf()` method like the `String` or `Number`, its return type would be the
9
+ * `string` or `number`.
10
+ *
11
+ * Otherwise, the target argument is a type of custom class, all of its custom method would
12
+ * be erased and its prototype would be changed to the primitive `object`. Therefore, return
13
+ * type of the TMP type finally be the primitive object.
14
+ *
15
+ * In addition, if the target argument is a type of custom class and it has a special
16
+ * method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
17
+ * but `Primitive<ReturnType<Instance.toJSON>>`.
18
+ *
19
+ * Before | After
20
+ * ------------------------|----------------------------------------
21
+ * `Boolean` | `boolean`
22
+ * `Number` | `number`
23
+ * `String` | `string`
24
+ * `Class` | `object`
25
+ * `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
26
+ * Others | No change
27
+ *
28
+ * @template Instance Target argument type.
29
+ * @author Jenogho Nam - https://github.com/samchon
30
+ */
31
+ export type Primitive<T> = _Equal<T, _Primitive<T>> extends true
32
+ ? T
33
+ : _Primitive<T>;
34
+
35
+ type _Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
36
+
37
+ type _Primitive<Instance> = _ValueOf<Instance> extends object
38
+ ? Instance extends object
39
+ ? Instance extends _Native
40
+ ? {}
41
+ : Instance extends IJsonable<infer Raw>
42
+ ? _ValueOf<Raw> extends object
43
+ ? Raw extends object
44
+ ? _PrimitiveObject<Raw> // object would be primitified
45
+ : never // cannot be
46
+ : _ValueOf<Raw> // atomic value
47
+ : _PrimitiveObject<Instance> // object would be primitified
48
+ : never // cannot be
49
+ : _ValueOf<Instance>;
50
+
51
+ type _PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
52
+ ? _Primitive<T>[]
53
+ : {
54
+ [P in keyof Instance]: Instance[P] extends Function
55
+ ? never
56
+ : _Primitive<Instance[P]>;
57
+ };
58
+
59
+ type _ValueOf<Instance> = _IsValueOf<Instance, Boolean> extends true
60
+ ? boolean
61
+ : _IsValueOf<Instance, Number> extends true
62
+ ? number
63
+ : _IsValueOf<Instance, String> extends true
64
+ ? string
65
+ : Instance;
66
+
67
+ type _Native =
68
+ | Set<any>
69
+ | Map<any, any>
70
+ | WeakSet<any>
71
+ | WeakMap<any, any>
72
+ | Uint8Array
73
+ | Uint8ClampedArray
74
+ | Uint16Array
75
+ | Uint32Array
76
+ | BigUint64Array
77
+ | Int8Array
78
+ | Int16Array
79
+ | Int32Array
80
+ | BigInt64Array
81
+ | Float32Array
82
+ | Float64Array
83
+ | ArrayBuffer
84
+ | SharedArrayBuffer
85
+ | DataView;
86
+
87
+ type _IsValueOf<
88
+ Instance,
89
+ Object extends IValueOf<any>,
90
+ > = Instance extends Object
91
+ ? Object extends IValueOf<infer Primitive>
92
+ ? Instance extends Primitive
93
+ ? false
94
+ : true // not Primitive, but Object
95
+ : false // cannot be
96
+ : false;
97
+
98
+ interface IValueOf<T> {
99
+ valueOf(): T;
100
+ }
101
+
102
+ interface IJsonable<T> {
103
+ toJSON(): T;
104
+ }
@@ -1,36 +1,36 @@
1
- export class TypeGuardError extends Error {
2
- public readonly method: string;
3
- public readonly path: string | undefined;
4
- public readonly expected: string;
5
- public readonly value: any;
6
-
7
- public constructor(props: TypeGuardError.IProps) {
8
- // MESSAGE CONSTRUCTION
9
- super(
10
- props.message ||
11
- `Error on ${props.method}(): invalid type${
12
- props.path ? ` on ${props.path}` : ""
13
- }, expect to be ${props.expected}`,
14
- );
15
-
16
- // INHERITANCE POLYFILL
17
- const proto = new.target.prototype;
18
- if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
19
- else (this as any).__proto__ = proto;
20
-
21
- // ASSIGN MEMBERS
22
- this.method = props.method;
23
- this.path = props.path;
24
- this.expected = props.expected;
25
- this.value = props.value;
26
- }
27
- }
28
- export namespace TypeGuardError {
29
- export interface IProps {
30
- method: string;
31
- path?: string;
32
- expected: string;
33
- value: any;
34
- message?: string;
35
- }
36
- }
1
+ export class TypeGuardError extends Error {
2
+ public readonly method: string;
3
+ public readonly path: string | undefined;
4
+ public readonly expected: string;
5
+ public readonly value: any;
6
+
7
+ public constructor(props: TypeGuardError.IProps) {
8
+ // MESSAGE CONSTRUCTION
9
+ super(
10
+ props.message ||
11
+ `Error on ${props.method}(): invalid type${
12
+ props.path ? ` on ${props.path}` : ""
13
+ }, expect to be ${props.expected}`,
14
+ );
15
+
16
+ // INHERITANCE POLYFILL
17
+ const proto = new.target.prototype;
18
+ if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
19
+ else (this as any).__proto__ = proto;
20
+
21
+ // ASSIGN MEMBERS
22
+ this.method = props.method;
23
+ this.path = props.path;
24
+ this.expected = props.expected;
25
+ this.value = props.value;
26
+ }
27
+ }
28
+ export namespace TypeGuardError {
29
+ export interface IProps {
30
+ method: string;
31
+ path?: string;
32
+ expected: string;
33
+ value: any;
34
+ message?: string;
35
+ }
36
+ }