@nestia/migrate 10.0.2 → 11.0.0-dev.20260305

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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +93 -93
  3. package/package.json +32 -46
  4. package/src/NestiaMigrateApplication.ts +161 -159
  5. package/src/analyzers/NestiaMigrateControllerAnalyzer.ts +51 -51
  6. package/src/archivers/NestiaMigrateFileArchiver.ts +28 -28
  7. package/src/bundles/NEST_TEMPLATE.ts +48 -48
  8. package/src/bundles/SDK_TEMPLATE.ts +21 -21
  9. package/src/executable/NestiaMigrateCommander.ts +98 -98
  10. package/src/executable/NestiaMigrateInquirer.ts +106 -106
  11. package/src/executable/bundle.js +125 -125
  12. package/src/executable/migrate.ts +7 -7
  13. package/src/factories/TypeLiteralFactory.ts +57 -57
  14. package/src/index.ts +4 -4
  15. package/src/module.ts +6 -2
  16. package/src/programmers/NestiaMigrateApiFileProgrammer.ts +55 -55
  17. package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +347 -344
  18. package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +517 -514
  19. package/src/programmers/NestiaMigrateApiProgrammer.ts +107 -107
  20. package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +308 -309
  21. package/src/programmers/NestiaMigrateApiStartProgrammer.ts +197 -198
  22. package/src/programmers/NestiaMigrateDtoProgrammer.ts +98 -98
  23. package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +153 -153
  24. package/src/programmers/NestiaMigrateE2eProgrammer.ts +48 -48
  25. package/src/programmers/NestiaMigrateImportProgrammer.ts +118 -118
  26. package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +69 -69
  27. package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +409 -406
  28. package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +65 -65
  29. package/src/programmers/NestiaMigrateNestProgrammer.ts +88 -88
  30. package/src/programmers/NestiaMigrateSchemaProgrammer.ts +465 -467
  31. package/src/structures/INestiaMigrateConfig.ts +19 -19
  32. package/src/structures/INestiaMigrateContext.ts +9 -9
  33. package/src/structures/INestiaMigrateController.ts +8 -8
  34. package/src/structures/INestiaMigrateDto.ts +8 -8
  35. package/src/structures/INestiaMigrateFile.ts +5 -5
  36. package/src/structures/INestiaMigrateProgram.ts +11 -11
  37. package/src/structures/INestiaMigrateSchema.ts +4 -4
  38. package/src/utils/FilePrinter.ts +49 -49
  39. package/src/utils/MapUtil.ts +13 -13
  40. package/src/utils/SetupWizard.ts +12 -12
  41. package/src/utils/StringUtil.ts +114 -113
  42. package/src/utils/openapi-down-convert/RefVisitor.ts +134 -134
  43. package/src/utils/openapi-down-convert/converter.ts +536 -536
  44. package/lib/NestiaMigrateApplication.d.ts +0 -24
  45. package/lib/NestiaMigrateApplication.js +0 -18757
  46. package/lib/NestiaMigrateApplication.js.map +0 -1
  47. package/lib/analyzers/NestiaMigrateControllerAnalyzer.d.ts +0 -5
  48. package/lib/analyzers/NestiaMigrateControllerAnalyzer.js +0 -46
  49. package/lib/analyzers/NestiaMigrateControllerAnalyzer.js.map +0 -1
  50. package/lib/archivers/NestiaMigrateFileArchiver.d.ts +0 -8
  51. package/lib/archivers/NestiaMigrateFileArchiver.js +0 -36
  52. package/lib/archivers/NestiaMigrateFileArchiver.js.map +0 -1
  53. package/lib/bundles/NEST_TEMPLATE.d.ts +0 -1
  54. package/lib/bundles/NEST_TEMPLATE.js +0 -55
  55. package/lib/bundles/NEST_TEMPLATE.js.map +0 -1
  56. package/lib/bundles/SDK_TEMPLATE.d.ts +0 -1
  57. package/lib/bundles/SDK_TEMPLATE.js +0 -27
  58. package/lib/bundles/SDK_TEMPLATE.js.map +0 -1
  59. package/lib/executable/NestiaMigrateCommander.d.ts +0 -4
  60. package/lib/executable/NestiaMigrateCommander.js +0 -125
  61. package/lib/executable/NestiaMigrateCommander.js.map +0 -1
  62. package/lib/executable/NestiaMigrateInquirer.d.ts +0 -12
  63. package/lib/executable/NestiaMigrateInquirer.js +0 -94
  64. package/lib/executable/NestiaMigrateInquirer.js.map +0 -1
  65. package/lib/executable/migrate.d.ts +0 -2
  66. package/lib/executable/migrate.js +0 -9
  67. package/lib/executable/migrate.js.map +0 -1
  68. package/lib/factories/TypeLiteralFactory.d.ts +0 -4
  69. package/lib/factories/TypeLiteralFactory.js +0 -35
  70. package/lib/factories/TypeLiteralFactory.js.map +0 -1
  71. package/lib/index.d.ts +0 -3
  72. package/lib/index.js +0 -42
  73. package/lib/index.js.map +0 -1
  74. package/lib/index.mjs +0 -19359
  75. package/lib/index.mjs.map +0 -1
  76. package/lib/module.d.ts +0 -2
  77. package/lib/module.js +0 -19
  78. package/lib/module.js.map +0 -1
  79. package/lib/programmers/NestiaMigrateApiFileProgrammer.d.ts +0 -13
  80. package/lib/programmers/NestiaMigrateApiFileProgrammer.js +0 -40
  81. package/lib/programmers/NestiaMigrateApiFileProgrammer.js.map +0 -1
  82. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.d.ts +0 -14
  83. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +0 -179
  84. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +0 -1
  85. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.d.ts +0 -14
  86. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js +0 -226
  87. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js.map +0 -1
  88. package/lib/programmers/NestiaMigrateApiProgrammer.d.ts +0 -4
  89. package/lib/programmers/NestiaMigrateApiProgrammer.js +0 -82
  90. package/lib/programmers/NestiaMigrateApiProgrammer.js.map +0 -1
  91. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.d.ts +0 -14
  92. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js +0 -142
  93. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js.map +0 -1
  94. package/lib/programmers/NestiaMigrateApiStartProgrammer.d.ts +0 -4
  95. package/lib/programmers/NestiaMigrateApiStartProgrammer.js +0 -80
  96. package/lib/programmers/NestiaMigrateApiStartProgrammer.js.map +0 -1
  97. package/lib/programmers/NestiaMigrateDtoProgrammer.d.ts +0 -15
  98. package/lib/programmers/NestiaMigrateDtoProgrammer.js +0 -65
  99. package/lib/programmers/NestiaMigrateDtoProgrammer.js.map +0 -1
  100. package/lib/programmers/NestiaMigrateE2eFileProgrammer.d.ts +0 -14
  101. package/lib/programmers/NestiaMigrateE2eFileProgrammer.js +0 -81
  102. package/lib/programmers/NestiaMigrateE2eFileProgrammer.js.map +0 -1
  103. package/lib/programmers/NestiaMigrateE2eProgrammer.d.ts +0 -4
  104. package/lib/programmers/NestiaMigrateE2eProgrammer.js +0 -32
  105. package/lib/programmers/NestiaMigrateE2eProgrammer.js.map +0 -1
  106. package/lib/programmers/NestiaMigrateImportProgrammer.d.ts +0 -18
  107. package/lib/programmers/NestiaMigrateImportProgrammer.js +0 -65
  108. package/lib/programmers/NestiaMigrateImportProgrammer.js.map +0 -1
  109. package/lib/programmers/NestiaMigrateNestControllerProgrammer.d.ts +0 -12
  110. package/lib/programmers/NestiaMigrateNestControllerProgrammer.js +0 -46
  111. package/lib/programmers/NestiaMigrateNestControllerProgrammer.js.map +0 -1
  112. package/lib/programmers/NestiaMigrateNestMethodProgrammer.d.ts +0 -15
  113. package/lib/programmers/NestiaMigrateNestMethodProgrammer.js +0 -224
  114. package/lib/programmers/NestiaMigrateNestMethodProgrammer.js.map +0 -1
  115. package/lib/programmers/NestiaMigrateNestModuleProgrammer.d.ts +0 -5
  116. package/lib/programmers/NestiaMigrateNestModuleProgrammer.js +0 -29
  117. package/lib/programmers/NestiaMigrateNestModuleProgrammer.js.map +0 -1
  118. package/lib/programmers/NestiaMigrateNestProgrammer.d.ts +0 -4
  119. package/lib/programmers/NestiaMigrateNestProgrammer.js +0 -65
  120. package/lib/programmers/NestiaMigrateNestProgrammer.js.map +0 -1
  121. package/lib/programmers/NestiaMigrateSchemaProgrammer.d.ts +0 -10
  122. package/lib/programmers/NestiaMigrateSchemaProgrammer.js +0 -341
  123. package/lib/programmers/NestiaMigrateSchemaProgrammer.js.map +0 -1
  124. package/lib/structures/INestiaMigrateConfig.d.ts +0 -15
  125. package/lib/structures/INestiaMigrateConfig.js +0 -3
  126. package/lib/structures/INestiaMigrateConfig.js.map +0 -1
  127. package/lib/structures/INestiaMigrateContext.d.ts +0 -7
  128. package/lib/structures/INestiaMigrateContext.js +0 -3
  129. package/lib/structures/INestiaMigrateContext.js.map +0 -1
  130. package/lib/structures/INestiaMigrateController.d.ts +0 -7
  131. package/lib/structures/INestiaMigrateController.js +0 -3
  132. package/lib/structures/INestiaMigrateController.js.map +0 -1
  133. package/lib/structures/INestiaMigrateDto.d.ts +0 -7
  134. package/lib/structures/INestiaMigrateDto.js +0 -3
  135. package/lib/structures/INestiaMigrateDto.js.map +0 -1
  136. package/lib/structures/INestiaMigrateFile.d.ts +0 -5
  137. package/lib/structures/INestiaMigrateFile.js +0 -3
  138. package/lib/structures/INestiaMigrateFile.js.map +0 -1
  139. package/lib/structures/INestiaMigrateProgram.d.ts +0 -9
  140. package/lib/structures/INestiaMigrateProgram.js +0 -3
  141. package/lib/structures/INestiaMigrateProgram.js.map +0 -1
  142. package/lib/structures/INestiaMigrateSchema.d.ts +0 -4
  143. package/lib/structures/INestiaMigrateSchema.js +0 -3
  144. package/lib/structures/INestiaMigrateSchema.js.map +0 -1
  145. package/lib/utils/FilePrinter.d.ts +0 -9
  146. package/lib/utils/FilePrinter.js +0 -35
  147. package/lib/utils/FilePrinter.js.map +0 -1
  148. package/lib/utils/MapUtil.d.ts +0 -3
  149. package/lib/utils/MapUtil.js +0 -15
  150. package/lib/utils/MapUtil.js.map +0 -1
  151. package/lib/utils/SetupWizard.d.ts +0 -3
  152. package/lib/utils/SetupWizard.js +0 -18
  153. package/lib/utils/SetupWizard.js.map +0 -1
  154. package/lib/utils/StringUtil.d.ts +0 -6
  155. package/lib/utils/StringUtil.js +0 -108
  156. package/lib/utils/StringUtil.js.map +0 -1
  157. package/lib/utils/openapi-down-convert/RefVisitor.d.ts +0 -52
  158. package/lib/utils/openapi-down-convert/RefVisitor.js +0 -102
  159. package/lib/utils/openapi-down-convert/RefVisitor.js.map +0 -1
  160. package/lib/utils/openapi-down-convert/converter.d.ts +0 -146
  161. package/lib/utils/openapi-down-convert/converter.js +0 -441
  162. package/lib/utils/openapi-down-convert/converter.js.map +0 -1
@@ -1,19 +1,19 @@
1
- import ts from "typescript";
2
-
3
- import { NestiaMigrateNestMethodProgrammer } from "../programmers/NestiaMigrateNestMethodProgrammer";
4
-
5
- export interface INestiaMigrateConfig {
6
- simulate: boolean;
7
- e2e: boolean;
8
- package?: string;
9
- keyword?: boolean;
10
- author?: {
11
- tag: string;
12
- value: string;
13
- };
14
- programmer?: {
15
- controllerMethod?: (
16
- ctx: NestiaMigrateNestMethodProgrammer.IContext,
17
- ) => ts.MethodDeclaration;
18
- };
19
- }
1
+ import ts from "typescript";
2
+
3
+ import { NestiaMigrateNestMethodProgrammer } from "../programmers/NestiaMigrateNestMethodProgrammer";
4
+
5
+ export interface INestiaMigrateConfig {
6
+ simulate: boolean;
7
+ e2e: boolean;
8
+ package?: string;
9
+ keyword?: boolean;
10
+ author?: {
11
+ tag: string;
12
+ value: string;
13
+ };
14
+ programmer?: {
15
+ controllerMethod?: (
16
+ ctx: NestiaMigrateNestMethodProgrammer.IContext,
17
+ ) => ts.MethodDeclaration;
18
+ };
19
+ }
@@ -1,9 +1,9 @@
1
- import { IHttpMigrateApplication } from "@samchon/openapi";
2
-
3
- import { INestiaMigrateConfig } from "./INestiaMigrateConfig";
4
-
5
- export interface INestiaMigrateContext {
6
- mode: "nest" | "sdk";
7
- application: IHttpMigrateApplication;
8
- config: INestiaMigrateConfig;
9
- }
1
+ import { IHttpMigrateApplication } from "@typia/interface";
2
+
3
+ import { INestiaMigrateConfig } from "./INestiaMigrateConfig";
4
+
5
+ export interface INestiaMigrateContext {
6
+ mode: "nest" | "sdk";
7
+ application: IHttpMigrateApplication;
8
+ config: INestiaMigrateConfig;
9
+ }
@@ -1,8 +1,8 @@
1
- import { IHttpMigrateRoute } from "@samchon/openapi";
2
-
3
- export interface INestiaMigrateController {
4
- name: string;
5
- path: string;
6
- location: string;
7
- routes: IHttpMigrateRoute[];
8
- }
1
+ import { IHttpMigrateRoute } from "@typia/interface";
2
+
3
+ export interface INestiaMigrateController {
4
+ name: string;
5
+ path: string;
6
+ location: string;
7
+ routes: IHttpMigrateRoute[];
8
+ }
@@ -1,8 +1,8 @@
1
- import { OpenApi } from "@samchon/openapi";
2
-
3
- export interface INestiaMigrateDto {
4
- name: string;
5
- location: string;
6
- schema: OpenApi.IJsonSchema | null;
7
- children: INestiaMigrateDto[];
8
- }
1
+ import { OpenApi } from "@typia/interface";
2
+
3
+ export interface INestiaMigrateDto {
4
+ name: string;
5
+ location: string;
6
+ schema: OpenApi.IJsonSchema | null;
7
+ children: INestiaMigrateDto[];
8
+ }
@@ -1,5 +1,5 @@
1
- export interface INestiaMigrateFile {
2
- location: string;
3
- file: string;
4
- content: string;
5
- }
1
+ export interface INestiaMigrateFile {
2
+ location: string;
3
+ file: string;
4
+ content: string;
5
+ }
@@ -1,11 +1,11 @@
1
- import { IHttpMigrateApplication, OpenApi } from "@samchon/openapi";
2
-
3
- import { INestiaMigrateConfig } from "./INestiaMigrateConfig";
4
-
5
- export interface INestiaMigrateProgram {
6
- mode: "nest" | "sdk";
7
- document: OpenApi.IDocument;
8
- config: INestiaMigrateConfig;
9
- files: Record<string, string>;
10
- errors: IHttpMigrateApplication.IError[];
11
- }
1
+ import { IHttpMigrateApplication, OpenApi } from "@typia/interface";
2
+
3
+ import { INestiaMigrateConfig } from "./INestiaMigrateConfig";
4
+
5
+ export interface INestiaMigrateProgram {
6
+ mode: "nest" | "sdk";
7
+ document: OpenApi.IDocument;
8
+ config: INestiaMigrateConfig;
9
+ files: Record<string, string>;
10
+ errors: IHttpMigrateApplication.IError[];
11
+ }
@@ -1,4 +1,4 @@
1
- export interface INestiaMigrateSchema {
2
- name: string;
3
- children: INestiaMigrateSchema[];
4
- }
1
+ export interface INestiaMigrateSchema {
2
+ name: string;
3
+ children: INestiaMigrateSchema[];
4
+ }
@@ -1,49 +1,49 @@
1
- import ts from "typescript";
2
-
3
- export namespace FilePrinter {
4
- export const description = <Node extends ts.Node>(
5
- node: Node,
6
- comment: string,
7
- ): Node => {
8
- if (comment.length === 0) return node;
9
- ts.addSyntheticLeadingComment(
10
- node,
11
- ts.SyntaxKind.MultiLineCommentTrivia,
12
- [
13
- "*",
14
- ...comment
15
- .split("\r\n")
16
- .join("\n")
17
- .split("\n")
18
- .map(
19
- (str) =>
20
- ` * ${str.split("*/").join("*\\\\/").split("*\\/").join("*\\\\/")}`,
21
- ),
22
- "",
23
- ].join("\n"),
24
- true,
25
- );
26
- return node;
27
- };
28
-
29
- export const newLine = () =>
30
- ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
31
-
32
- export const write = (props: {
33
- statements: ts.Statement[];
34
- top?: string;
35
- }): string => {
36
- const script: string = ts
37
- .createPrinter({
38
- newLine: ts.NewLineKind.LineFeed,
39
- })
40
- .printFile(
41
- ts.factory.createSourceFile(
42
- props.statements,
43
- ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
44
- ts.NodeFlags.None,
45
- ),
46
- );
47
- return (props.top ?? "") + script;
48
- };
49
- }
1
+ import ts from "typescript";
2
+
3
+ export namespace FilePrinter {
4
+ export const description = <Node extends ts.Node>(
5
+ node: Node,
6
+ comment: string,
7
+ ): Node => {
8
+ if (comment.length === 0) return node;
9
+ ts.addSyntheticLeadingComment(
10
+ node,
11
+ ts.SyntaxKind.MultiLineCommentTrivia,
12
+ [
13
+ "*",
14
+ ...comment
15
+ .split("\r\n")
16
+ .join("\n")
17
+ .split("\n")
18
+ .map(
19
+ (str) =>
20
+ ` * ${str.split("*/").join("*\\\\/").split("*\\/").join("*\\\\/")}`,
21
+ ),
22
+ "",
23
+ ].join("\n"),
24
+ true,
25
+ );
26
+ return node;
27
+ };
28
+
29
+ export const newLine = () =>
30
+ ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
31
+
32
+ export const write = (props: {
33
+ statements: ts.Statement[];
34
+ top?: string;
35
+ }): string => {
36
+ const script: string = ts
37
+ .createPrinter({
38
+ newLine: ts.NewLineKind.LineFeed,
39
+ })
40
+ .printFile(
41
+ ts.factory.createSourceFile(
42
+ props.statements,
43
+ ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
44
+ ts.NodeFlags.None,
45
+ ),
46
+ );
47
+ return (props.top ?? "") + script;
48
+ };
49
+ }
@@ -1,13 +1,13 @@
1
- export namespace MapUtil {
2
- export const take =
3
- <Key, T>(dict: Map<Key, T>) =>
4
- (key: Key) =>
5
- (generator: () => T): T => {
6
- const oldbie: T | undefined = dict.get(key);
7
- if (oldbie) return oldbie;
8
-
9
- const value: T = generator();
10
- dict.set(key, value);
11
- return value;
12
- };
13
- }
1
+ export namespace MapUtil {
2
+ export const take =
3
+ <Key, T>(dict: Map<Key, T>) =>
4
+ (key: Key) =>
5
+ (generator: () => T): T => {
6
+ const oldbie: T | undefined = dict.get(key);
7
+ if (oldbie) return oldbie;
8
+
9
+ const value: T = generator();
10
+ dict.set(key, value);
11
+ return value;
12
+ };
13
+ }
@@ -1,12 +1,12 @@
1
- import cp from "child_process";
2
-
3
- export namespace SetupWizard {
4
- export const setup = (output: string) => {
5
- execute(output)("npm install");
6
- };
7
-
8
- const execute = (cwd: string) => (command: string, fake?: string) => {
9
- console.log(fake ?? command);
10
- cp.execSync(command, { cwd, stdio: "inherit" });
11
- };
12
- }
1
+ import cp from "child_process";
2
+
3
+ export namespace SetupWizard {
4
+ export const setup = (output: string) => {
5
+ execute(output)("npm install");
6
+ };
7
+
8
+ const execute = (cwd: string) => (command: string, fake?: string) => {
9
+ console.log(fake ?? command);
10
+ cp.execSync(command, { cwd, stdio: "inherit" });
11
+ };
12
+ }
@@ -1,113 +1,114 @@
1
- export namespace StringUtil {
2
- export const capitalize = (str: string) =>
3
- str[0].toUpperCase() + str.slice(1).toLowerCase();
4
-
5
- export const splitWithNormalization = (path: string) =>
6
- path
7
- .split("/")
8
- .map((str) => normalize(str.trim()))
9
- .filter((str) => !!str.length);
10
-
11
- export const escapeDuplicate =
12
- (keep: string[]) =>
13
- (change: string): string =>
14
- keep.includes(change) ? escapeDuplicate(keep)(`_${change}`) : change;
15
-
16
- export const escapeNonVariable = (str: string): string => {
17
- str = escape(str);
18
- for (const [before, after] of VARIABLE_REPLACERS)
19
- str = str.split(before).join(after);
20
- for (let i: number = 0; i <= 9; ++i)
21
- if (str[0] === i.toString()) {
22
- str = "_" + str;
23
- break;
24
- }
25
- if (str === "") return "_empty_";
26
- return str;
27
- };
28
- }
29
-
30
- const escape = (str: string): string => {
31
- str = str.trim();
32
- if (RESERVED.has(str)) return `_${str}`;
33
- else if (str.length !== 0 && "0" <= str[0] && str[0] <= "9") str = `_${str}`;
34
- return str;
35
- };
36
-
37
- const normalize = (str: string): string =>
38
- escape(str.split(".").join("_").split("-").join("_"));
39
-
40
- const RESERVED: Set<string> = new Set([
41
- "break",
42
- "case",
43
- "catch",
44
- "class",
45
- "const",
46
- "continue",
47
- "debugger",
48
- "default",
49
- "delete",
50
- "do",
51
- "else",
52
- "enum",
53
- "export",
54
- "extends",
55
- "false",
56
- "finally",
57
- "for",
58
- "function",
59
- "if",
60
- "import",
61
- "in",
62
- "instanceof",
63
- "module",
64
- "new",
65
- "null",
66
- "package",
67
- "public",
68
- "private",
69
- "protected",
70
- "return",
71
- "super",
72
- "switch",
73
- "this",
74
- "throw",
75
- "true",
76
- "try",
77
- "typeof",
78
- "var",
79
- "void",
80
- "while",
81
- "with",
82
- ]);
83
-
84
- const VARIABLE_REPLACERS: [string, string][] = [
85
- ["`", "_backquote_"],
86
- ["!", "_exclamation_"],
87
- ["@", "_at_"],
88
- ["#", "_hash_"],
89
- ["$", "_dollar_"],
90
- ["%", "_percent_"],
91
- ["^", "_caret_"],
92
- ["&", "_and_"],
93
- ["*", "_star_"],
94
- ["(", "_lparen_"],
95
- [")", "_rparen_"],
96
- ["-", "_"],
97
- ["+", "_plus_"],
98
- ["|", "_or_"],
99
- ["{", "_blt_"],
100
- ["}", "_bgt_"],
101
- ["<", "_lt_"],
102
- [">", "_gt_"],
103
- ["[", "_alt_"],
104
- ["]", "_agt_"],
105
- [",", "_comma_"],
106
- ["'", "_singlequote_"],
107
- ['"', "_doublequote_"],
108
- [" ", "_space_"],
109
- ["?", "_question_"],
110
- [":", "_colon_"],
111
- [";", "_semicolon_"],
112
- ["...", "_rest_"],
113
- ];
1
+ export namespace StringUtil {
2
+ export const capitalize = (str: string) =>
3
+ str[0]!.toUpperCase() + str.slice(1).toLowerCase();
4
+
5
+ export const splitWithNormalization = (path: string) =>
6
+ path
7
+ .split("/")
8
+ .map((str) => normalize(str.trim()))
9
+ .filter((str) => !!str.length);
10
+
11
+ export const escapeDuplicate =
12
+ (keep: string[]) =>
13
+ (change: string): string =>
14
+ keep.includes(change) ? escapeDuplicate(keep)(`_${change}`) : change;
15
+
16
+ export const escapeNonVariable = (str: string): string => {
17
+ str = escape(str);
18
+ for (const [before, after] of VARIABLE_REPLACERS)
19
+ str = str.split(before).join(after);
20
+ for (let i: number = 0; i <= 9; ++i)
21
+ if (str[0] === i.toString()) {
22
+ str = "_" + str;
23
+ break;
24
+ }
25
+ if (str === "") return "_empty_";
26
+ return str;
27
+ };
28
+ }
29
+
30
+ const escape = (str: string): string => {
31
+ str = str.trim();
32
+ if (RESERVED.has(str)) return `_${str}`;
33
+ else if (str.length !== 0 && "0" <= str[0]! && str[0]! <= "9")
34
+ str = `_${str}`;
35
+ return str;
36
+ };
37
+
38
+ const normalize = (str: string): string =>
39
+ escape(str.split(".").join("_").split("-").join("_"));
40
+
41
+ const RESERVED: Set<string> = new Set([
42
+ "break",
43
+ "case",
44
+ "catch",
45
+ "class",
46
+ "const",
47
+ "continue",
48
+ "debugger",
49
+ "default",
50
+ "delete",
51
+ "do",
52
+ "else",
53
+ "enum",
54
+ "export",
55
+ "extends",
56
+ "false",
57
+ "finally",
58
+ "for",
59
+ "function",
60
+ "if",
61
+ "import",
62
+ "in",
63
+ "instanceof",
64
+ "module",
65
+ "new",
66
+ "null",
67
+ "package",
68
+ "public",
69
+ "private",
70
+ "protected",
71
+ "return",
72
+ "super",
73
+ "switch",
74
+ "this",
75
+ "throw",
76
+ "true",
77
+ "try",
78
+ "typeof",
79
+ "var",
80
+ "void",
81
+ "while",
82
+ "with",
83
+ ]);
84
+
85
+ const VARIABLE_REPLACERS: [string, string][] = [
86
+ ["`", "_backquote_"],
87
+ ["!", "_exclamation_"],
88
+ ["@", "_at_"],
89
+ ["#", "_hash_"],
90
+ ["$", "_dollar_"],
91
+ ["%", "_percent_"],
92
+ ["^", "_caret_"],
93
+ ["&", "_and_"],
94
+ ["*", "_star_"],
95
+ ["(", "_lparen_"],
96
+ [")", "_rparen_"],
97
+ ["-", "_"],
98
+ ["+", "_plus_"],
99
+ ["|", "_or_"],
100
+ ["{", "_blt_"],
101
+ ["}", "_bgt_"],
102
+ ["<", "_lt_"],
103
+ [">", "_gt_"],
104
+ ["[", "_alt_"],
105
+ ["]", "_agt_"],
106
+ [",", "_comma_"],
107
+ ["'", "_singlequote_"],
108
+ ['"', "_doublequote_"],
109
+ [" ", "_space_"],
110
+ ["?", "_question_"],
111
+ [":", "_colon_"],
112
+ [";", "_semicolon_"],
113
+ ["...", "_rest_"],
114
+ ];