typia 4.0.0-dev.20230519-3 → 4.0.0-dev.20230527

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 (222) hide show
  1. package/lib/transform.js +1 -1
  2. package/lib/transform.js.map +1 -1
  3. package/lib/utils/TsSymbolUtil.js +2 -1
  4. package/lib/utils/TsSymbolUtil.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/CustomValidatorMap.ts +126 -126
  7. package/src/IRandomGenerator.ts +33 -33
  8. package/src/IValidation.ts +21 -21
  9. package/src/Primitive.ts +123 -123
  10. package/src/TypeGuardError.ts +36 -36
  11. package/src/executable/TypiaGenerateWizard.ts +85 -85
  12. package/src/executable/TypiaSetupWizard.ts +133 -133
  13. package/src/executable/setup/ArgumentParser.ts +45 -45
  14. package/src/executable/setup/CommandExecutor.ts +8 -8
  15. package/src/executable/setup/FileRetriever.ts +22 -22
  16. package/src/executable/setup/PackageManager.ts +71 -71
  17. package/src/executable/setup/PluginConfigurator.ts +70 -70
  18. package/src/executable/typia.ts +52 -52
  19. package/src/factories/CommentFactory.ts +14 -14
  20. package/src/factories/ExpressionFactory.ts +77 -77
  21. package/src/factories/IdentifierFactory.ts +62 -62
  22. package/src/factories/LiteralFactory.ts +57 -57
  23. package/src/factories/MetadataCollection.ts +123 -123
  24. package/src/factories/MetadataFactory.ts +53 -53
  25. package/src/factories/MetadataTagFactory.ts +295 -295
  26. package/src/factories/StatementFactory.ts +20 -20
  27. package/src/factories/TemplateFactory.ts +64 -64
  28. package/src/factories/TypeFactory.ts +145 -145
  29. package/src/factories/ValueFactory.ts +15 -15
  30. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  31. package/src/factories/internal/metadata/emplace_metadata_object.ts +152 -152
  32. package/src/factories/internal/metadata/explore_metadata.ts +93 -93
  33. package/src/factories/internal/metadata/iterate_metadata.ts +63 -63
  34. package/src/factories/internal/metadata/iterate_metadata_array.ts +32 -32
  35. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  36. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  37. package/src/factories/internal/metadata/iterate_metadata_constant.ts +62 -62
  38. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  39. package/src/factories/internal/metadata/iterate_metadata_native.ts +217 -217
  40. package/src/factories/internal/metadata/iterate_metadata_object.ts +51 -51
  41. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +30 -30
  42. package/src/factories/internal/metadata/iterate_metadata_set.ts +36 -36
  43. package/src/factories/internal/metadata/iterate_metadata_template.ts +40 -40
  44. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +51 -51
  45. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  46. package/src/functional/$any.ts +2 -2
  47. package/src/functional/$dictionary.ts +25 -25
  48. package/src/functional/$every.ts +11 -11
  49. package/src/functional/$guard.ts +35 -35
  50. package/src/functional/$is_between.ts +2 -2
  51. package/src/functional/$is_custom.ts +14 -14
  52. package/src/functional/$is_date.ts +3 -3
  53. package/src/functional/$is_datetime.ts +2 -2
  54. package/src/functional/$is_email.ts +4 -4
  55. package/src/functional/$is_ipv4.ts +4 -4
  56. package/src/functional/$is_ipv6.ts +4 -4
  57. package/src/functional/$is_url.ts +4 -4
  58. package/src/functional/$is_uuid.ts +4 -4
  59. package/src/functional/$join.ts +46 -46
  60. package/src/functional/$number.ts +12 -12
  61. package/src/functional/$report.ts +15 -15
  62. package/src/functional/$rest.ts +3 -3
  63. package/src/functional/$string.ts +37 -37
  64. package/src/functional/$tail.ts +5 -5
  65. package/src/functional/Namespace.ts +127 -127
  66. package/src/index.ts +4 -4
  67. package/src/metadata/ICommentTag.ts +4 -4
  68. package/src/metadata/IJsDocTagInfo.ts +10 -10
  69. package/src/metadata/IMetadata.ts +26 -26
  70. package/src/metadata/IMetadataApplication.ts +7 -7
  71. package/src/metadata/IMetadataConstant.ts +16 -16
  72. package/src/metadata/IMetadataEntry.ts +6 -6
  73. package/src/metadata/IMetadataObject.ts +29 -29
  74. package/src/metadata/IMetadataProperty.ts +11 -11
  75. package/src/metadata/IMetadataTag.ts +105 -105
  76. package/src/metadata/Metadata.ts +539 -539
  77. package/src/metadata/MetadataConstant.ts +3 -3
  78. package/src/metadata/MetadataObject.ts +127 -127
  79. package/src/metadata/MetadataProperty.ts +64 -64
  80. package/src/module.ts +2038 -2038
  81. package/src/programmers/ApplicationProgrammer.ts +48 -48
  82. package/src/programmers/AssertCloneProgrammer.ts +68 -68
  83. package/src/programmers/AssertParseProgrammer.ts +66 -66
  84. package/src/programmers/AssertProgrammer.ts +274 -274
  85. package/src/programmers/AssertPruneProgrammer.ts +73 -73
  86. package/src/programmers/AssertStringifyProgrammer.ts +66 -66
  87. package/src/programmers/CheckerProgrammer.ts +897 -897
  88. package/src/programmers/CloneProgrammer.ts +387 -387
  89. package/src/programmers/FeatureProgrammer.ts +510 -510
  90. package/src/programmers/IsCloneProgrammer.ts +79 -79
  91. package/src/programmers/IsParseProgrammer.ts +72 -72
  92. package/src/programmers/IsProgrammer.ts +223 -223
  93. package/src/programmers/IsPruneProgrammer.ts +83 -83
  94. package/src/programmers/IsStringifyProgrammer.ts +77 -77
  95. package/src/programmers/LiteralsProgrammer.ts +65 -65
  96. package/src/programmers/PruneProgrammer.ts +348 -348
  97. package/src/programmers/RandomProgrammer.ts +444 -444
  98. package/src/programmers/StringifyProgrammer.ts +758 -758
  99. package/src/programmers/TypiaProgrammer.ts +141 -141
  100. package/src/programmers/ValidateCloneProgrammer.ts +93 -93
  101. package/src/programmers/ValidateParseProgrammer.ts +78 -78
  102. package/src/programmers/ValidateProgrammer.ts +317 -317
  103. package/src/programmers/ValidatePruneProgrammer.ts +86 -86
  104. package/src/programmers/ValidateStringifyProgrammer.ts +93 -93
  105. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  106. package/src/programmers/helpers/CloneJoiner.ts +138 -138
  107. package/src/programmers/helpers/FunctionImporeter.ts +56 -56
  108. package/src/programmers/helpers/ICheckEntry.ts +12 -12
  109. package/src/programmers/helpers/IExpressionEntry.ts +12 -12
  110. package/src/programmers/helpers/OptionPredicator.ts +15 -15
  111. package/src/programmers/helpers/PruneJoiner.ts +156 -156
  112. package/src/programmers/helpers/RandomJoiner.ts +165 -165
  113. package/src/programmers/helpers/RandomRanger.ts +218 -218
  114. package/src/programmers/helpers/StringifyJoinder.ts +118 -118
  115. package/src/programmers/helpers/StringifyPredicator.ts +12 -12
  116. package/src/programmers/helpers/UnionExplorer.ts +281 -281
  117. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  118. package/src/programmers/helpers/disable_function_importer_declare.ts +21 -21
  119. package/src/programmers/internal/JSON_SCHEMA_PREFIX.ts +1 -1
  120. package/src/programmers/internal/application_array.ts +32 -32
  121. package/src/programmers/internal/application_boolean.ts +15 -15
  122. package/src/programmers/internal/application_constant.ts +26 -26
  123. package/src/programmers/internal/application_default.ts +17 -17
  124. package/src/programmers/internal/application_default_string.ts +33 -33
  125. package/src/programmers/internal/application_native.ts +36 -36
  126. package/src/programmers/internal/application_number.ts +71 -71
  127. package/src/programmers/internal/application_object.ts +162 -162
  128. package/src/programmers/internal/application_schema.ts +198 -198
  129. package/src/programmers/internal/application_string.ts +44 -44
  130. package/src/programmers/internal/application_templates.ts +25 -25
  131. package/src/programmers/internal/application_tuple.ts +27 -27
  132. package/src/programmers/internal/check_array.ts +31 -31
  133. package/src/programmers/internal/check_array_length.ts +35 -35
  134. package/src/programmers/internal/check_bigint.ts +95 -95
  135. package/src/programmers/internal/check_custom.ts +32 -32
  136. package/src/programmers/internal/check_dynamic_properties.ts +198 -198
  137. package/src/programmers/internal/check_everything.ts +28 -28
  138. package/src/programmers/internal/check_native.ts +22 -22
  139. package/src/programmers/internal/check_number.ts +177 -177
  140. package/src/programmers/internal/check_object.ts +65 -65
  141. package/src/programmers/internal/check_string.ts +27 -27
  142. package/src/programmers/internal/check_string_tags.ts +68 -68
  143. package/src/programmers/internal/check_template.ts +57 -57
  144. package/src/programmers/internal/check_union_array_like.ts +273 -273
  145. package/src/programmers/internal/check_union_tuple.ts +34 -34
  146. package/src/programmers/internal/decode_union_object.ts +75 -75
  147. package/src/programmers/internal/feature_object_entries.ts +64 -64
  148. package/src/programmers/internal/get_comment_tags.ts +23 -23
  149. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  150. package/src/programmers/internal/prune_object_properties.ts +63 -63
  151. package/src/programmers/internal/random_custom.ts +30 -30
  152. package/src/programmers/internal/stringify_dynamic_properties.ts +173 -173
  153. package/src/programmers/internal/stringify_native.ts +7 -7
  154. package/src/programmers/internal/stringify_regular_properties.ts +89 -89
  155. package/src/programmers/internal/template_to_pattern.ts +15 -15
  156. package/src/schemas/IJsonApplication.ts +13 -13
  157. package/src/schemas/IJsonComponents.ts +33 -33
  158. package/src/schemas/IJsonSchema.ts +134 -134
  159. package/src/transform.ts +39 -39
  160. package/src/transformers/CallExpressionTransformer.ts +183 -183
  161. package/src/transformers/FileTransformer.ts +50 -50
  162. package/src/transformers/IProject.ts +18 -18
  163. package/src/transformers/ITransformOptions.ts +62 -62
  164. package/src/transformers/ImportTransformer.ts +74 -74
  165. package/src/transformers/NodeTransformer.ts +13 -13
  166. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +107 -107
  167. package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
  168. package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
  169. package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
  170. package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
  171. package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
  172. package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
  173. package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
  174. package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
  175. package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
  176. package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +43 -43
  177. package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
  178. package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
  179. package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
  180. package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
  181. package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +31 -31
  182. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +56 -56
  183. package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
  184. package/src/transformers/features/miscellaneous/RandomTransformer.ts +46 -46
  185. package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
  186. package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
  187. package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
  188. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
  189. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
  190. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
  191. package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
  192. package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
  193. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
  194. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +12 -12
  195. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
  196. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
  197. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +12 -12
  198. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
  199. package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
  200. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
  201. package/src/transformers/features/validators/AssertTransformer.ts +11 -11
  202. package/src/transformers/features/validators/CreateAssertTransformer.ts +13 -13
  203. package/src/transformers/features/validators/CreateIsTransformer.ts +11 -11
  204. package/src/transformers/features/validators/CreateValidateTransformer.ts +13 -13
  205. package/src/transformers/features/validators/IsTransformer.ts +11 -11
  206. package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
  207. package/src/transformers/internal/GenericTransformer.ts +101 -101
  208. package/src/typings/Atomic.ts +17 -17
  209. package/src/typings/ClassProperties.ts +5 -5
  210. package/src/typings/Customizable.ts +5 -5
  211. package/src/typings/OmitNever.ts +3 -3
  212. package/src/typings/SpecialFields.ts +3 -3
  213. package/src/typings/Writable.ts +11 -11
  214. package/src/utils/ArrayUtil.ts +44 -44
  215. package/src/utils/Escaper.ts +45 -45
  216. package/src/utils/MapUtil.ts +12 -12
  217. package/src/utils/PatternUtil.ts +30 -30
  218. package/src/utils/RandomGenerator.ts +81 -81
  219. package/src/utils/Singleton.ts +17 -17
  220. package/src/utils/TsNodeUtil.ts +17 -17
  221. package/src/utils/TsSymbolUtil.ts +153 -152
  222. package/src/utils/TsTypeUtil.ts +38 -38
@@ -1,70 +1,70 @@
1
- import comments from "comment-json";
2
- import fs from "fs";
3
-
4
- import { TypiaSetupWizard } from "../TypiaSetupWizard";
5
-
6
- export namespace PluginConfigurator {
7
- export async function configure(
8
- args: TypiaSetupWizard.IArguments,
9
- ): Promise<void> {
10
- // GET COMPILER-OPTIONS
11
- const config: comments.CommentObject = comments.parse(
12
- await fs.promises.readFile(args.project!, "utf8"),
13
- ) as comments.CommentObject;
14
- const compilerOptions = config.compilerOptions as
15
- | comments.CommentObject
16
- | undefined;
17
- if (compilerOptions === undefined)
18
- throw new Error(
19
- `${args.project} file does not have "compilerOptions" property.`,
20
- );
21
-
22
- // PREPARE PLUGINS
23
- const plugins: comments.CommentArray<comments.CommentObject> = (() => {
24
- const plugins = compilerOptions.plugins as
25
- | comments.CommentArray<comments.CommentObject>
26
- | undefined;
27
- if (plugins === undefined)
28
- return (compilerOptions.plugins = [] as any);
29
- else if (!Array.isArray(plugins))
30
- throw new Error(
31
- `"plugins" property of ${args.project} must be array type.`,
32
- );
33
- return plugins;
34
- })();
35
-
36
- const strict: boolean | undefined = compilerOptions.strict as
37
- | boolean
38
- | undefined;
39
- const strictNullChecks: boolean | undefined =
40
- compilerOptions.strictNullChecks as boolean | undefined;
41
- const oldbie: comments.CommentObject | undefined = plugins.find(
42
- (p) =>
43
- typeof p === "object" &&
44
- p !== null &&
45
- p.transform === "typia/lib/transform",
46
- );
47
- if (
48
- strictNullChecks !== false &&
49
- (strict === true || strictNullChecks === true) &&
50
- oldbie !== undefined
51
- )
52
- return;
53
-
54
- // DO CONFIGURE
55
- compilerOptions.strictNullChecks = true;
56
- if (strict === undefined && strictNullChecks === undefined)
57
- compilerOptions.strict = true;
58
- if (oldbie === undefined)
59
- plugins.push(
60
- comments.parse(`
61
- {
62
- "transform": "typia/lib/transform"
63
- }`) as comments.CommentObject,
64
- );
65
- await fs.promises.writeFile(
66
- args.project!,
67
- comments.stringify(config, null, 2),
68
- );
69
- }
70
- }
1
+ import comments from "comment-json";
2
+ import fs from "fs";
3
+
4
+ import { TypiaSetupWizard } from "../TypiaSetupWizard";
5
+
6
+ export namespace PluginConfigurator {
7
+ export async function configure(
8
+ args: TypiaSetupWizard.IArguments,
9
+ ): Promise<void> {
10
+ // GET COMPILER-OPTIONS
11
+ const config: comments.CommentObject = comments.parse(
12
+ await fs.promises.readFile(args.project!, "utf8"),
13
+ ) as comments.CommentObject;
14
+ const compilerOptions = config.compilerOptions as
15
+ | comments.CommentObject
16
+ | undefined;
17
+ if (compilerOptions === undefined)
18
+ throw new Error(
19
+ `${args.project} file does not have "compilerOptions" property.`,
20
+ );
21
+
22
+ // PREPARE PLUGINS
23
+ const plugins: comments.CommentArray<comments.CommentObject> = (() => {
24
+ const plugins = compilerOptions.plugins as
25
+ | comments.CommentArray<comments.CommentObject>
26
+ | undefined;
27
+ if (plugins === undefined)
28
+ return (compilerOptions.plugins = [] as any);
29
+ else if (!Array.isArray(plugins))
30
+ throw new Error(
31
+ `"plugins" property of ${args.project} must be array type.`,
32
+ );
33
+ return plugins;
34
+ })();
35
+
36
+ const strict: boolean | undefined = compilerOptions.strict as
37
+ | boolean
38
+ | undefined;
39
+ const strictNullChecks: boolean | undefined =
40
+ compilerOptions.strictNullChecks as boolean | undefined;
41
+ const oldbie: comments.CommentObject | undefined = plugins.find(
42
+ (p) =>
43
+ typeof p === "object" &&
44
+ p !== null &&
45
+ p.transform === "typia/lib/transform",
46
+ );
47
+ if (
48
+ strictNullChecks !== false &&
49
+ (strict === true || strictNullChecks === true) &&
50
+ oldbie !== undefined
51
+ )
52
+ return;
53
+
54
+ // DO CONFIGURE
55
+ compilerOptions.strictNullChecks = true;
56
+ if (strict === undefined && strictNullChecks === undefined)
57
+ compilerOptions.strict = true;
58
+ if (oldbie === undefined)
59
+ plugins.push(
60
+ comments.parse(`
61
+ {
62
+ "transform": "typia/lib/transform"
63
+ }`) as comments.CommentObject,
64
+ );
65
+ await fs.promises.writeFile(
66
+ args.project!,
67
+ comments.stringify(config, null, 2),
68
+ );
69
+ }
70
+ }
@@ -1,52 +1,52 @@
1
- #!/usr/bin/env node
2
- const USAGE = `Wrong command has been detected. Use like below:
3
-
4
- npx typia setup \\
5
- --manager (npm|pnpm|yarn) \\
6
- --project {tsconfig.json file path}
7
-
8
- - npx typia setup
9
- - npx typia setup --manager pnpm
10
- - npx typia setup --project tsconfig.test.json
11
-
12
- npx typia generate
13
- --input {directory} \\
14
- --output {directory}
15
-
16
- --npx typia generate --input src/templates --output src/functinoal
17
- `;
18
-
19
- const halt = (desc: string): never => {
20
- console.error(desc);
21
- process.exit(-1);
22
- };
23
-
24
- const main = async (): Promise<void> => {
25
- try {
26
- await import("comment-json");
27
- await import("inquirer");
28
- await import("commander");
29
- } catch {
30
- halt(`typia has not been installed. Run "npm i typia" before.`);
31
- }
32
-
33
- const type: string | undefined = process.argv[2];
34
- if (type === "setup") {
35
- const { TypiaSetupWizard } = await import("./TypiaSetupWizard");
36
- await TypiaSetupWizard.setup();
37
- } else if (type === "generate") {
38
- try {
39
- await import("typescript");
40
- } catch {
41
- halt(
42
- `typescript has not been installed. Run "npm i -D typescript" before.`,
43
- );
44
- }
45
- const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard");
46
- await TypiaGenerateWizard.generate();
47
- } else halt(USAGE);
48
- };
49
- main().catch((exp) => {
50
- console.error(exp);
51
- process.exit(-1);
52
- });
1
+ #!/usr/bin/env node
2
+ const USAGE = `Wrong command has been detected. Use like below:
3
+
4
+ npx typia setup \\
5
+ --manager (npm|pnpm|yarn) \\
6
+ --project {tsconfig.json file path}
7
+
8
+ - npx typia setup
9
+ - npx typia setup --manager pnpm
10
+ - npx typia setup --project tsconfig.test.json
11
+
12
+ npx typia generate
13
+ --input {directory} \\
14
+ --output {directory}
15
+
16
+ --npx typia generate --input src/templates --output src/functinoal
17
+ `;
18
+
19
+ const halt = (desc: string): never => {
20
+ console.error(desc);
21
+ process.exit(-1);
22
+ };
23
+
24
+ const main = async (): Promise<void> => {
25
+ try {
26
+ await import("comment-json");
27
+ await import("inquirer");
28
+ await import("commander");
29
+ } catch {
30
+ halt(`typia has not been installed. Run "npm i typia" before.`);
31
+ }
32
+
33
+ const type: string | undefined = process.argv[2];
34
+ if (type === "setup") {
35
+ const { TypiaSetupWizard } = await import("./TypiaSetupWizard");
36
+ await TypiaSetupWizard.setup();
37
+ } else if (type === "generate") {
38
+ try {
39
+ await import("typescript");
40
+ } catch {
41
+ halt(
42
+ `typescript has not been installed. Run "npm i -D typescript" before.`,
43
+ );
44
+ }
45
+ const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard");
46
+ await TypiaGenerateWizard.generate();
47
+ } else halt(USAGE);
48
+ };
49
+ main().catch((exp) => {
50
+ console.error(exp);
51
+ process.exit(-1);
52
+ });
@@ -1,14 +1,14 @@
1
- import { SymbolDisplayPart } from "typescript";
2
-
3
- export namespace CommentFactory {
4
- export const string = (comments: SymbolDisplayPart[]): string =>
5
- comments
6
- .map((part) => part.text)
7
- .map((str) => str.split("\r\n").join("\n"))
8
- .join("");
9
-
10
- /**
11
- * @deprecated
12
- */
13
- export const generate = string;
14
- }
1
+ import { SymbolDisplayPart } from "typescript";
2
+
3
+ export namespace CommentFactory {
4
+ export const string = (comments: SymbolDisplayPart[]): string =>
5
+ comments
6
+ .map((part) => part.text)
7
+ .map((str) => str.split("\r\n").join("\n"))
8
+ .join("");
9
+
10
+ /**
11
+ * @deprecated
12
+ */
13
+ export const generate = string;
14
+ }
@@ -1,77 +1,77 @@
1
- import type ts from "typescript/lib/tsclibrary";
2
-
3
- export namespace ExpressionFactory {
4
- export const isRequired =
5
- (tsc: typeof ts) =>
6
- (input: ts.Expression): ts.Expression =>
7
- tsc.factory.createStrictInequality(
8
- tsc.factory.createIdentifier("undefined"),
9
- input,
10
- );
11
-
12
- export const isArray =
13
- (tsc: typeof ts) =>
14
- (input: ts.Expression): ts.Expression =>
15
- tsc.factory.createCallExpression(
16
- tsc.factory.createIdentifier("Array.isArray"),
17
- undefined,
18
- [input],
19
- );
20
-
21
- export const isObject =
22
- (tsc: typeof ts) =>
23
- (options: { checkNull: boolean; checkArray: boolean }) =>
24
- (input: ts.Expression): ts.Expression => {
25
- const conditions: ts.Expression[] = [
26
- tsc.factory.createStrictEquality(
27
- tsc.factory.createStringLiteral("object"),
28
- tsc.factory.createTypeOfExpression(input),
29
- ),
30
- ];
31
- if (options.checkNull === true)
32
- conditions.push(
33
- tsc.factory.createStrictInequality(
34
- tsc.factory.createNull(),
35
- input,
36
- ),
37
- );
38
- if (options.checkArray === true)
39
- conditions.push(
40
- tsc.factory.createStrictEquality(
41
- tsc.factory.createFalse(),
42
- tsc.factory.createCallExpression(
43
- tsc.factory.createIdentifier("Array.isArray"),
44
- undefined,
45
- [input],
46
- ),
47
- ),
48
- );
49
-
50
- return conditions.length === 1
51
- ? conditions[0]!
52
- : conditions.reduce((x, y) =>
53
- tsc.factory.createLogicalAnd(x, y),
54
- );
55
- };
56
-
57
- export const isInstanceOf =
58
- (tsc: typeof ts) =>
59
- (type: string) =>
60
- (input: ts.Expression): ts.Expression => {
61
- return tsc.factory.createBinaryExpression(
62
- input,
63
- tsc.factory.createToken(tsc.SyntaxKind.InstanceOfKeyword),
64
- tsc.factory.createIdentifier(type),
65
- );
66
- };
67
-
68
- export const coalesce =
69
- (tsc: typeof ts) =>
70
- (x: ts.Expression) =>
71
- (y: ts.Expression): ts.Expression =>
72
- tsc.factory.createBinaryExpression(
73
- x,
74
- tsc.factory.createToken(tsc.SyntaxKind.QuestionQuestionToken),
75
- y,
76
- );
77
- }
1
+ import type ts from "typescript/lib/tsclibrary";
2
+
3
+ export namespace ExpressionFactory {
4
+ export const isRequired =
5
+ (tsc: typeof ts) =>
6
+ (input: ts.Expression): ts.Expression =>
7
+ tsc.factory.createStrictInequality(
8
+ tsc.factory.createIdentifier("undefined"),
9
+ input,
10
+ );
11
+
12
+ export const isArray =
13
+ (tsc: typeof ts) =>
14
+ (input: ts.Expression): ts.Expression =>
15
+ tsc.factory.createCallExpression(
16
+ tsc.factory.createIdentifier("Array.isArray"),
17
+ undefined,
18
+ [input],
19
+ );
20
+
21
+ export const isObject =
22
+ (tsc: typeof ts) =>
23
+ (options: { checkNull: boolean; checkArray: boolean }) =>
24
+ (input: ts.Expression): ts.Expression => {
25
+ const conditions: ts.Expression[] = [
26
+ tsc.factory.createStrictEquality(
27
+ tsc.factory.createStringLiteral("object"),
28
+ tsc.factory.createTypeOfExpression(input),
29
+ ),
30
+ ];
31
+ if (options.checkNull === true)
32
+ conditions.push(
33
+ tsc.factory.createStrictInequality(
34
+ tsc.factory.createNull(),
35
+ input,
36
+ ),
37
+ );
38
+ if (options.checkArray === true)
39
+ conditions.push(
40
+ tsc.factory.createStrictEquality(
41
+ tsc.factory.createFalse(),
42
+ tsc.factory.createCallExpression(
43
+ tsc.factory.createIdentifier("Array.isArray"),
44
+ undefined,
45
+ [input],
46
+ ),
47
+ ),
48
+ );
49
+
50
+ return conditions.length === 1
51
+ ? conditions[0]!
52
+ : conditions.reduce((x, y) =>
53
+ tsc.factory.createLogicalAnd(x, y),
54
+ );
55
+ };
56
+
57
+ export const isInstanceOf =
58
+ (tsc: typeof ts) =>
59
+ (type: string) =>
60
+ (input: ts.Expression): ts.Expression => {
61
+ return tsc.factory.createBinaryExpression(
62
+ input,
63
+ tsc.factory.createToken(tsc.SyntaxKind.InstanceOfKeyword),
64
+ tsc.factory.createIdentifier(type),
65
+ );
66
+ };
67
+
68
+ export const coalesce =
69
+ (tsc: typeof ts) =>
70
+ (x: ts.Expression) =>
71
+ (y: ts.Expression): ts.Expression =>
72
+ tsc.factory.createBinaryExpression(
73
+ x,
74
+ tsc.factory.createToken(tsc.SyntaxKind.QuestionQuestionToken),
75
+ y,
76
+ );
77
+ }
@@ -1,62 +1,62 @@
1
- import type ts from "typescript/lib/tsclibrary";
2
-
3
- import { Escaper } from "../utils/Escaper";
4
-
5
- export namespace IdentifierFactory {
6
- export const identifier = (tsc: typeof ts) => (name: string) =>
7
- Escaper.variable(name)
8
- ? tsc.factory.createIdentifier(name)
9
- : tsc.factory.createStringLiteral(name);
10
-
11
- export const access =
12
- (tsc: typeof ts) => (target: ts.Expression) => (property: string) => {
13
- const postfix = identifier(tsc)(property);
14
- return tsc.isStringLiteral(postfix)
15
- ? tsc.factory.createElementAccessExpression(target, postfix)
16
- : tsc.factory.createPropertyAccessExpression(target, postfix);
17
- };
18
-
19
- export const postfix = (str: string): string =>
20
- Escaper.variable(str)
21
- ? `".${str}"`
22
- : `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
23
-
24
- export const parameter =
25
- (tsc: typeof ts) =>
26
- (
27
- name: string | ts.BindingName,
28
- type?: ts.TypeNode,
29
- init?:
30
- | ts.Expression
31
- | ts.PunctuationToken<ts.SyntaxKind.QuestionToken>,
32
- ) => {
33
- // instead of ts.version >= "4.8"
34
- if (tsc.getDecorators !== undefined)
35
- return tsc.factory.createParameterDeclaration(
36
- undefined,
37
- undefined,
38
- name,
39
- init?.kind === tsc.SyntaxKind.QuestionToken
40
- ? tsc.factory.createToken(tsc.SyntaxKind.QuestionToken)
41
- : undefined,
42
- type,
43
- init && init.kind !== tsc.SyntaxKind.QuestionToken
44
- ? init
45
- : undefined,
46
- );
47
- // eslint-disable-next-line
48
- return (tsc.factory.createParameterDeclaration as any)(
49
- undefined,
50
- undefined,
51
- undefined,
52
- name,
53
- init?.kind === tsc.SyntaxKind.QuestionToken
54
- ? tsc.factory.createToken(tsc.SyntaxKind.QuestionToken)
55
- : undefined,
56
- type,
57
- init && init.kind !== tsc.SyntaxKind.QuestionToken
58
- ? init
59
- : undefined,
60
- );
61
- };
62
- }
1
+ import type ts from "typescript/lib/tsclibrary";
2
+
3
+ import { Escaper } from "../utils/Escaper";
4
+
5
+ export namespace IdentifierFactory {
6
+ export const identifier = (tsc: typeof ts) => (name: string) =>
7
+ Escaper.variable(name)
8
+ ? tsc.factory.createIdentifier(name)
9
+ : tsc.factory.createStringLiteral(name);
10
+
11
+ export const access =
12
+ (tsc: typeof ts) => (target: ts.Expression) => (property: string) => {
13
+ const postfix = identifier(tsc)(property);
14
+ return tsc.isStringLiteral(postfix)
15
+ ? tsc.factory.createElementAccessExpression(target, postfix)
16
+ : tsc.factory.createPropertyAccessExpression(target, postfix);
17
+ };
18
+
19
+ export const postfix = (str: string): string =>
20
+ Escaper.variable(str)
21
+ ? `".${str}"`
22
+ : `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
23
+
24
+ export const parameter =
25
+ (tsc: typeof ts) =>
26
+ (
27
+ name: string | ts.BindingName,
28
+ type?: ts.TypeNode,
29
+ init?:
30
+ | ts.Expression
31
+ | ts.PunctuationToken<ts.SyntaxKind.QuestionToken>,
32
+ ) => {
33
+ // instead of ts.version >= "4.8"
34
+ if (tsc.getDecorators !== undefined)
35
+ return tsc.factory.createParameterDeclaration(
36
+ undefined,
37
+ undefined,
38
+ name,
39
+ init?.kind === tsc.SyntaxKind.QuestionToken
40
+ ? tsc.factory.createToken(tsc.SyntaxKind.QuestionToken)
41
+ : undefined,
42
+ type,
43
+ init && init.kind !== tsc.SyntaxKind.QuestionToken
44
+ ? init
45
+ : undefined,
46
+ );
47
+ // eslint-disable-next-line
48
+ return (tsc.factory.createParameterDeclaration as any)(
49
+ undefined,
50
+ undefined,
51
+ undefined,
52
+ name,
53
+ init?.kind === tsc.SyntaxKind.QuestionToken
54
+ ? tsc.factory.createToken(tsc.SyntaxKind.QuestionToken)
55
+ : undefined,
56
+ type,
57
+ init && init.kind !== tsc.SyntaxKind.QuestionToken
58
+ ? init
59
+ : undefined,
60
+ );
61
+ };
62
+ }