nestia 2.1.0-dev.20220414 → 2.1.0-dev.20220430

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 (116) hide show
  1. package/.github/workflows/build.yml +2 -4
  2. package/README.md +84 -14
  3. package/{src/bundle → bundle}/HttpError.ts +0 -0
  4. package/{src/bundle → bundle}/IConnection.ts +0 -0
  5. package/{src/bundle → bundle}/Primitive.ts +0 -0
  6. package/{src/bundle → bundle}/__internal/AesPkcs5.ts +0 -0
  7. package/{src/bundle → bundle}/__internal/Fetcher.ts +0 -0
  8. package/lib/IConfiguration.d.ts +71 -0
  9. package/lib/IConfiguration.d.ts.map +1 -0
  10. package/lib/IConfiguration.js +3 -0
  11. package/lib/NestiaApplication.d.ts +12 -0
  12. package/lib/NestiaApplication.d.ts.map +1 -0
  13. package/lib/NestiaApplication.js +340 -0
  14. package/lib/analyses/ControllerAnalyzer.d.ts +7 -0
  15. package/lib/analyses/ControllerAnalyzer.d.ts.map +1 -0
  16. package/lib/analyses/ControllerAnalyzer.js +191 -0
  17. package/lib/analyses/GenericAnalyzer.d.ts +6 -0
  18. package/lib/analyses/GenericAnalyzer.d.ts.map +1 -0
  19. package/lib/analyses/GenericAnalyzer.js +100 -0
  20. package/lib/analyses/ImportAnalyzer.d.ts +14 -0
  21. package/lib/analyses/ImportAnalyzer.d.ts.map +1 -0
  22. package/lib/analyses/ImportAnalyzer.js +79 -0
  23. package/lib/analyses/ReflectAnalyzer.d.ts +5 -0
  24. package/lib/analyses/ReflectAnalyzer.d.ts.map +1 -0
  25. package/lib/analyses/ReflectAnalyzer.js +313 -0
  26. package/lib/analyses/SourceFinder.d.ts +5 -0
  27. package/lib/analyses/SourceFinder.d.ts.map +1 -0
  28. package/lib/analyses/SourceFinder.js +260 -0
  29. package/lib/executable/internal/CompilerOptions.d.ts +14 -0
  30. package/lib/executable/internal/CompilerOptions.d.ts.map +1 -0
  31. package/lib/executable/internal/CompilerOptions.js +126 -0
  32. package/lib/executable/internal/NestiaCommand.d.ts +5 -0
  33. package/lib/executable/internal/NestiaCommand.d.ts.map +1 -0
  34. package/lib/executable/internal/NestiaCommand.js +228 -0
  35. package/lib/executable/internal/NestiaConfig.d.ts +5 -0
  36. package/lib/executable/internal/NestiaConfig.d.ts.map +1 -0
  37. package/lib/executable/internal/NestiaConfig.js +277 -0
  38. package/lib/executable/internal/nestia.config.getter.d.ts +2 -0
  39. package/lib/executable/internal/nestia.config.getter.d.ts.map +1 -0
  40. package/lib/executable/internal/nestia.config.getter.js +60 -0
  41. package/lib/executable/nestia.d.ts +3 -0
  42. package/lib/executable/nestia.d.ts.map +1 -0
  43. package/lib/executable/nestia.js +129 -0
  44. package/lib/generates/FileGenerator.d.ts +6 -0
  45. package/lib/generates/FileGenerator.d.ts.map +1 -0
  46. package/lib/generates/FileGenerator.js +326 -0
  47. package/lib/generates/FunctionGenerator.d.ts +6 -0
  48. package/lib/generates/FunctionGenerator.d.ts.map +1 -0
  49. package/lib/generates/FunctionGenerator.js +217 -0
  50. package/lib/generates/SdkGenerator.d.ts +8 -0
  51. package/lib/generates/SdkGenerator.d.ts.map +1 -0
  52. package/lib/generates/SdkGenerator.js +128 -0
  53. package/lib/generates/SwaggerGenerator.d.ts +7 -0
  54. package/lib/generates/SwaggerGenerator.d.ts.map +1 -0
  55. package/lib/generates/SwaggerGenerator.js +258 -0
  56. package/lib/index.d.ts +3 -0
  57. package/lib/index.d.ts.map +1 -0
  58. package/lib/index.js +28 -0
  59. package/lib/module.d.ts +3 -0
  60. package/lib/module.d.ts.map +1 -0
  61. package/lib/module.js +19 -0
  62. package/{src/structures/IController.ts → lib/structures/IController.d.ts} +6 -13
  63. package/lib/structures/IController.d.ts.map +1 -0
  64. package/lib/structures/IController.js +3 -0
  65. package/{src/structures/IRoute.ts → lib/structures/IRoute.d.ts} +8 -13
  66. package/lib/structures/IRoute.d.ts.map +1 -0
  67. package/lib/structures/IRoute.js +3 -0
  68. package/lib/structures/ISwagger.d.ts +36 -0
  69. package/lib/structures/ISwagger.d.ts.map +1 -0
  70. package/lib/structures/ISwagger.js +3 -0
  71. package/lib/structures/IType.d.ts +6 -0
  72. package/lib/structures/IType.d.ts.map +1 -0
  73. package/lib/structures/IType.js +3 -0
  74. package/lib/structures/MethodType.d.ts +5 -0
  75. package/lib/structures/MethodType.d.ts.map +1 -0
  76. package/lib/structures/MethodType.js +8 -0
  77. package/lib/structures/ParamCategory.d.ts +2 -0
  78. package/lib/structures/ParamCategory.d.ts.map +1 -0
  79. package/lib/structures/ParamCategory.js +3 -0
  80. package/lib/utils/ArrayUtil.d.ts +6 -0
  81. package/lib/utils/ArrayUtil.d.ts.map +1 -0
  82. package/lib/utils/ArrayUtil.js +144 -0
  83. package/lib/utils/DirectoryUtil.d.ts +6 -0
  84. package/lib/utils/DirectoryUtil.d.ts.map +1 -0
  85. package/lib/utils/DirectoryUtil.js +190 -0
  86. package/lib/utils/ImportDictionary.d.ts +7 -0
  87. package/lib/utils/ImportDictionary.d.ts.map +1 -0
  88. package/lib/utils/ImportDictionary.js +83 -0
  89. package/lib/utils/MapUtil.d.ts +4 -0
  90. package/lib/utils/MapUtil.d.ts.map +1 -0
  91. package/lib/utils/MapUtil.js +16 -0
  92. package/lib/utils/StringUtil.d.ts +4 -0
  93. package/lib/utils/StringUtil.d.ts.map +1 -0
  94. package/lib/utils/StringUtil.js +13 -0
  95. package/package.json +17 -10
  96. package/src/IConfiguration.ts +0 -17
  97. package/src/NestiaApplication.ts +0 -96
  98. package/src/analyses/ControllerAnalyzer.ts +0 -154
  99. package/src/analyses/GenericAnalyzer.ts +0 -52
  100. package/src/analyses/ImportAnalyzer.ts +0 -93
  101. package/src/analyses/ReflectAnalyzer.ts +0 -221
  102. package/src/analyses/SourceFinder.ts +0 -73
  103. package/src/bin/nestia.ts +0 -125
  104. package/src/executable/sdk.ts +0 -89
  105. package/src/generates/FileGenerator.ts +0 -150
  106. package/src/generates/FunctionGenerator.ts +0 -201
  107. package/src/generates/SdkGenerator.ts +0 -39
  108. package/src/internal/CompilerOptions.ts +0 -142
  109. package/src/structures/MethodType.ts +0 -6
  110. package/src/structures/ParamCategory.ts +0 -1
  111. package/src/utils/ArrayUtil.ts +0 -26
  112. package/src/utils/DirectoryUtil.ts +0 -48
  113. package/src/utils/ImportDictionary.ts +0 -44
  114. package/src/utils/StringUtil.ts +0 -10
  115. package/src/utils/stripJsonComments.ts +0 -79
  116. package/tsconfig.json +0 -82
@@ -1,201 +0,0 @@
1
- import * as tsc from "typescript";
2
- import { Pair } from "tstl/utility/Pair";
3
- import { Vector } from "tstl/container/Vector";
4
-
5
- import { IRoute } from "../structures/IRoute";
6
-
7
- export namespace FunctionGenerator
8
- {
9
- export function generate(assert: boolean, route: IRoute): string
10
- {
11
- const query: IRoute.IParameter | undefined = route.parameters.find(param => param.category === "query");
12
- const input: IRoute.IParameter | undefined = route.parameters.find(param => param.category === "body");
13
-
14
- return [head, body, tail]
15
- .map(closure => closure(route, query, input, assert))
16
- .filter(str => !!str)
17
- .join("\n");
18
- }
19
-
20
- /* ---------------------------------------------------------
21
- BODY
22
- --------------------------------------------------------- */
23
- function body
24
- (
25
- route: IRoute,
26
- query: IRoute.IParameter | undefined,
27
- input: IRoute.IParameter | undefined,
28
- assert: boolean
29
- ): string
30
- {
31
- // FETCH ARGUMENTS WITH REQUST BODY
32
- const parameters = filter_parameters(route, query);
33
- const fetchArguments: string[] =
34
- [
35
- "connection",
36
- `${route.name}.ENCRYPTED`,
37
- `${route.name}.METHOD`,
38
- `${route.name}.path(${parameters.map(p => p.name).join(", ")})`
39
- ];
40
- if (input !== undefined)
41
- fetchArguments.push(input.name);
42
-
43
- const assertions: string = assert === true && route.parameters.length !== 0
44
- ? route.parameters
45
- .map(param => ` assertType<typeof ${param.name}>(${param.name});`)
46
- .join("\n") + "\n\n"
47
- : "";
48
-
49
- // RETURNS WITH FINALIZATION
50
- return "{\n"
51
- + assertions
52
- + " return Fetcher.fetch\n"
53
- + " (\n"
54
- + fetchArguments.map(param => ` ${param}`).join(",\n") + "\n"
55
- + " );\n"
56
- + "}";
57
- }
58
-
59
- function filter_parameters(route: IRoute, query: IRoute.IParameter | undefined): IRoute.IParameter[]
60
- {
61
- const parameters = route.parameters.filter(param => param.category === "param");
62
- if (query)
63
- parameters.push(query);
64
- return parameters;
65
- }
66
-
67
- /* ---------------------------------------------------------
68
- HEAD & TAIL
69
- --------------------------------------------------------- */
70
- function head
71
- (
72
- route: IRoute,
73
- query: IRoute.IParameter | undefined,
74
- input: IRoute.IParameter | undefined
75
- ): string
76
- {
77
- //----
78
- // CONSTRUCT COMMENT
79
- //----
80
- // MAIN DESCRIPTION
81
- let comment: string = route.comments.map(comment => `${comment.kind === "linkText" ? " " : ""}${comment.text}`).join("");
82
- if (comment !== "")
83
- comment += "\n\n";
84
-
85
- // FILTER TAGS (VULNERABLE PARAMETERS WOULD BE REMOVED)
86
- const tagList: tsc.JSDocTagInfo[] = route.tags.filter(tag => tag.text !== undefined);
87
- if (tagList.length !== 0)
88
- {
89
- const index: number = tagList.findIndex(t => t.name === "param");
90
- if (index !== -1)
91
- {
92
- const capsule: Vector<tsc.JSDocTagInfo> = Vector.wrap(tagList);
93
- capsule.insert(capsule.nth(index), {
94
- name: "param",
95
- text: [
96
- {
97
- kind: "parameterName",
98
- text: "connection"
99
- },
100
- {
101
- kind: "space",
102
- text: " "
103
- },
104
- {
105
- kind: "text",
106
- text: "connection Information of the remote HTTP(s) server with headers (+encryption password)"
107
- }
108
- ]
109
- });
110
- }
111
- comment += tagList
112
- .map(tag => `@${tag.name} ${tag.text!.map(elem => elem.text).join("")}`)
113
- .join("\n") + "\n\n";
114
- }
115
-
116
- // COMPLETE THE COMMENT
117
- comment += `@nestia Generated by Nestia - https://github.com/samchon/nestia\n`;
118
- comment += `@controller ${route.symbol}\n`;
119
- comment += `@path ${route.method} ${route.path}`;
120
-
121
- //----
122
- // FINALIZATION
123
- //----
124
- // REFORM PARAMETERS TEXT
125
- const parameters: string[] =
126
- [
127
- "connection: IConnection",
128
- ...route.parameters.map(param =>
129
- {
130
- const type: string = (param === query || param === input)
131
- ? `Primitive<${route.name}.${param === query ? "Query" : "Input"}>`
132
- : param.type
133
- return `${param.name}: ${type}`;
134
- })
135
- ];
136
-
137
- // OUTPUT TYPE
138
- const output: string = route.output === "void"
139
- ? "void"
140
- : `${route.name}.Output`;
141
-
142
- // RETURNS WITH CONSTRUCTION
143
- return ""
144
- + "/**\n"
145
- + comment.split("\r\n").join("\n").split("\n").map(str => ` * ${str}`).join("\n") + "\n"
146
- + " */\n"
147
- + `export function ${route.name}\n`
148
- + ` (\n`
149
- + `${parameters.map(str => ` ${str}`).join(",\n")}\n`
150
- + ` ): Promise<${output}>`;
151
- }
152
-
153
- function tail
154
- (
155
- route: IRoute,
156
- query: IRoute.IParameter | undefined,
157
- input: IRoute.IParameter | undefined
158
- ): string | null
159
- {
160
- // LIST UP TYPES
161
- const types: Pair<string, string>[] = [];
162
- if (query !== undefined)
163
- types.push(new Pair("Query", query.type));
164
- if (input !== undefined)
165
- types.push(new Pair("Input", input.type));
166
- if (route.output !== "void")
167
- types.push(new Pair("Output", route.output));
168
-
169
- // PATH WITH PARAMETERS
170
- const parameters = filter_parameters(route, query);
171
- let path: string = route.path;
172
- for (const param of parameters)
173
- if (param.category === "param")
174
- path = path.replace(`:${param.field}`, `\${${param.name}}`);
175
- path = (query !== undefined)
176
- ? `\`${path}?\${new URLSearchParams(${query.name} as any).toString()}\``
177
- : `\`${path}\``;
178
-
179
- return `export namespace ${route.name}\n`
180
- + "{\n"
181
- +
182
- (
183
- types.length !== 0
184
- ? types.map(tuple => ` export type ${tuple.first} = Primitive<${tuple.second}>;`).join("\n") + "\n"
185
- : ""
186
- )
187
- + "\n"
188
- + ` export const METHOD = "${route.method}" as const;\n`
189
- + ` export const PATH: string = "${route.path}";\n`
190
- + ` export const ENCRYPTED: Fetcher.IEncrypted = {\n`
191
- + ` request: ${input !== undefined && input.encrypted},\n`
192
- + ` response: ${route.encrypted},\n`
193
- + ` };\n`
194
- + "\n"
195
- + ` export function path(${parameters.map(param => `${param.name}: ${param.type}`).join(", ")}): string\n`
196
- + ` {\n`
197
- + ` return ${path};\n`
198
- + ` }\n`
199
- + "}";
200
- }
201
- }
@@ -1,39 +0,0 @@
1
- import * as fs from "fs";
2
- import { DirectoryUtil } from "../utils/DirectoryUtil";
3
-
4
- import { IRoute } from "../structures/IRoute";
5
- import { FileGenerator } from "./FileGenerator";
6
- import { IConfiguration } from "../IConfiguration";
7
-
8
- export namespace SdkGenerator
9
- {
10
- export async function generate
11
- (
12
- config: IConfiguration,
13
- routeList: IRoute[],
14
- ): Promise<void>
15
- {
16
- // PREPARE NEW DIRECTORIES
17
- try { await fs.promises.mkdir(config.output); } catch {}
18
-
19
- // BUNDLING
20
- const bundle: string[] = await fs.promises.readdir(BUNDLE);
21
- for (const file of bundle)
22
- {
23
- const current: string = `${BUNDLE}/${file}`;
24
- const stats: fs.Stats = await fs.promises.stat(current);
25
-
26
- if (stats.isFile() === true)
27
- {
28
- const content: string = await fs.promises.readFile(current, "utf8");
29
- await fs.promises.writeFile(`${config.output}/${file}`, content, "utf8");
30
- }
31
- }
32
- await DirectoryUtil.copy(BUNDLE + "/__internal", config.output + "/__internal");
33
-
34
- // FUNCTIONAL
35
- await FileGenerator.generate(config, routeList);
36
- }
37
- }
38
-
39
- const BUNDLE = __dirname + "/../bundle";
@@ -1,142 +0,0 @@
1
- import * as fs from "fs";
2
-
3
- export interface CompilerOptions
4
- {
5
- target: string;
6
- module: string;
7
- lib: string[];
8
- strict: boolean;
9
- downlevelIteration: boolean;
10
- esModuleInterop?: boolean;
11
- plugins?: Array<{
12
- transform?: string
13
- }>;
14
- types?: string[];
15
- experimentalDecorators?: boolean;
16
- emitDecoratorMetadata?: boolean;
17
- }
18
- export namespace CompilerOptions
19
- {
20
- /* -----------------------------------------------------------
21
- DEFAULT VALUES
22
- ----------------------------------------------------------- */
23
- export const DEPENDENCIES: string[] = [
24
- "nestia-fetcher",
25
- "typescript-is"
26
- ];
27
-
28
- export const TRANSFORMERS: string[] = [
29
- "typescript-is/lib/transform-inline/transformer",
30
- "typescript-transform-paths"
31
- ];
32
-
33
- export const TYPES: string[] = []
34
-
35
- export const DEFAULT = {
36
- target: "es5",
37
- module: "commonjs",
38
- lib: [
39
- "DOM",
40
- "ES2015"
41
- ],
42
- strict: true,
43
- downlevelIteration: true,
44
- esModuleInterop: true,
45
- plugins: TRANSFORMERS.map(transform => ({ transform })),
46
- types: [
47
- "node",
48
- "reflect-metadata"
49
- ],
50
- experimentalDecorators: true,
51
- emitDecoratorMetadata: true,
52
- };
53
-
54
- export function emend(options: CompilerOptions): boolean
55
- {
56
- // FILL ARRAY DATA
57
- if (!options.plugins)
58
- options.plugins = [];
59
- if (!options.types)
60
- options.types = [];
61
-
62
- // CONSTRUCT CHECKERS
63
- const emended: Required<CompilerOptions> = options as Required<CompilerOptions>;
64
- const checkers: Array<() => boolean> = [
65
- () =>
66
- {
67
- let changed: boolean = false;
68
- for (const transform of CompilerOptions.TRANSFORMERS)
69
- {
70
- if (emended.plugins.find(elem => elem.transform === transform) !== undefined)
71
- continue;
72
-
73
- changed = true;
74
- emended.plugins.push({ transform });
75
- }
76
- return changed;
77
- },
78
- () =>
79
- {
80
- let changed: boolean = false;
81
- for (const type of CompilerOptions.TYPES)
82
- {
83
- if (emended.types.find(elem => elem === type) !== undefined)
84
- continue;
85
-
86
- changed = true;
87
- emended.types.push(type);
88
- }
89
- return changed;
90
- },
91
- () =>
92
- {
93
- const changed: boolean = emended.experimentalDecorators !== true;
94
- if (changed)
95
- emended.experimentalDecorators = true;
96
- return changed;
97
- },
98
- () =>
99
- {
100
- const changed: boolean = emended.emitDecoratorMetadata !== true;
101
- if (changed)
102
- emended.emitDecoratorMetadata = true;
103
- return changed;
104
- },
105
- () =>
106
- {
107
- const changed: boolean = emended.esModuleInterop !== true;
108
- if (changed)
109
- emended.esModuleInterop = true;
110
- return changed;
111
- }
112
- ];
113
-
114
- // DO CHECK IT
115
- const checks: boolean[] = checkers.map(func => func());
116
- return checks.some(flag => flag);
117
- }
118
-
119
- /* -----------------------------------------------------------
120
- PROCEDURES
121
- ----------------------------------------------------------- */
122
- export function temporary(config: IConfig): () => Promise<[string, () => Promise<void>]>
123
- {
124
- return async () =>
125
- {
126
- const file: string = `nestia.temporary.tsconfig.${Math.random().toString().substr(2)}.json`;
127
-
128
- await fs.promises.writeFile
129
- (
130
- file,
131
- JSON.stringify(config, null, 2),
132
- "utf8"
133
- );
134
- return [file, () => fs.promises.unlink(file)];
135
- };
136
- }
137
- }
138
-
139
- interface IConfig
140
- {
141
- compilerOptions?: CompilerOptions;
142
- }
@@ -1,6 +0,0 @@
1
- export type MethodType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
2
-
3
- export namespace MethodType
4
- {
5
- export const VALUES: MethodType[] = ["GET", "POST", "PUT", "PATCH", "DELETE"];
6
- }
@@ -1 +0,0 @@
1
- export type ParamCategory = "param" | "query" | "body";
@@ -1,26 +0,0 @@
1
- export namespace ArrayUtil
2
- {
3
- export function has<T>(array: T[], ...items: T[]): boolean
4
- {
5
- return items.every(elem => array.find(org => org === elem) !== undefined);
6
- }
7
-
8
- export async function asyncMap<Input, Output>
9
- (array: Input[], closure: (input: Input) => Promise<Output>): Promise<Output[]>
10
- {
11
- const ret: Output[] = [];
12
- for (const elem of array)
13
- ret.push(await closure(elem));
14
- return ret;
15
- }
16
-
17
- export async function asyncFilter<Input>
18
- (array: Input[], closure: (input: Input) => Promise<boolean>): Promise<Input[]>
19
- {
20
- const ret: Input[] = [];
21
- for (const elem of array)
22
- if (await closure(elem) === true)
23
- ret.push(elem);
24
- return ret;
25
- }
26
- }
@@ -1,48 +0,0 @@
1
- import del from "del";
2
- import * as fs from "fs";
3
-
4
- export namespace DirectoryUtil
5
- {
6
- export async function remove(path: string): Promise<void>
7
- {
8
- try
9
- {
10
- await del(path);
11
- }
12
- catch {}
13
- }
14
-
15
- export async function remake(path: string): Promise<void>
16
- {
17
- await remove(path);
18
- await fs.promises.mkdir(path);
19
- }
20
-
21
- export async function copy(from: string, to: string): Promise<void>
22
- {
23
- await remake(to);
24
- await _Copy(from, to);
25
- }
26
-
27
- async function _Copy(from: string, to: string): Promise<void>
28
- {
29
- const directory: string[] = await fs.promises.readdir(from);
30
- for (const file of directory)
31
- {
32
- const fromPath: string = `${from}/${file}`;
33
- const toPath: string = `${to}/${file}`;
34
- const stats: fs.Stats = await fs.promises.stat(fromPath);
35
-
36
- if (stats.isDirectory() === true)
37
- {
38
- await fs.promises.mkdir(toPath);
39
- await _Copy(fromPath, toPath);
40
- }
41
- else
42
- {
43
- const content: string = await fs.promises.readFile(fromPath, "utf8");
44
- await fs.promises.writeFile(toPath, content.split("\r\n").join("\n"), "utf8");
45
- }
46
- }
47
- }
48
- }
@@ -1,44 +0,0 @@
1
- import * as path from "path";
2
-
3
- import { HashMap } from "tstl/container/HashMap";
4
- import { HashSet } from "tstl/container/HashSet";
5
- import { Pair } from "tstl/utility/Pair";
6
-
7
- export class ImportDictionary
8
- {
9
- private readonly dict_: HashMap<string, Pair<boolean, HashSet<string>>> = new HashMap();
10
-
11
- public empty(): boolean
12
- {
13
- return this.dict_.empty();
14
- }
15
-
16
- public emplace(file: string, realistic: boolean, instance: string): void
17
- {
18
- if (file.substr(-5) === ".d.ts")
19
- file = file.substr(0, file.length - 5);
20
- else if (file.substr(-3) === ".ts")
21
- file = file.substr(0, file.length - 3);
22
- else
23
- throw new Error(`Error on ImportDictionary.emplace(): extension of the target file "${file}" is not "ts".`);
24
-
25
- let it = this.dict_.find(file);
26
- if (it.equals(this.dict_.end()) === true)
27
- it = this.dict_.emplace(file, new Pair(realistic, new HashSet())).first;
28
- it.second.second.insert(instance);
29
- }
30
-
31
- public toScript(outDir: string): string
32
- {
33
- const statements: string[] = [];
34
- for (const it of this.dict_)
35
- {
36
- const file: string = path.relative(outDir, it.first).split("\\").join("/");
37
- const realistic: boolean = it.second.first;
38
- const instances: string[] = it.second.second.toJSON();
39
-
40
- statements.push(`import ${!realistic ? "type " : ""}{ ${instances.join(", ")} } from "./${file}";`);
41
- }
42
- return statements.join("\n");
43
- }
44
- }
@@ -1,10 +0,0 @@
1
- export namespace StringUtil
2
- {
3
- export function betweens(str: string, start: string, end: string): string[]
4
- {
5
- const ret: string[] = str.split(start);
6
- ret.splice(0, 1);
7
-
8
- return ret.map(str => str.split(end)[0]);
9
- }
10
- }
@@ -1,79 +0,0 @@
1
- // https://github.com/sindresorhus/strip-json-comments
2
-
3
- const singleComment: any = Symbol('singleComment');
4
- const multiComment: any = Symbol('multiComment');
5
-
6
- const stripWithoutWhitespace = () => '';
7
- const stripWithWhitespace = (string: string, start: number, end: number) => string.slice(start, end).replace(/\S/g, ' ');
8
-
9
- const isEscaped = (jsonString: string, quotePosition: number) => {
10
- let index = quotePosition - 1;
11
- let backslashCount = 0;
12
-
13
- while (jsonString[index] === '\\') {
14
- index -= 1;
15
- backslashCount += 1;
16
- }
17
-
18
- return Boolean(backslashCount % 2);
19
- };
20
-
21
- export function stripJsonComments(jsonString: string, {whitespace = true} = {}) {
22
- if (typeof jsonString !== 'string') {
23
- throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``);
24
- }
25
-
26
- const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
27
-
28
- let isInsideString = false;
29
- let isInsideComment = false;
30
- let offset = 0;
31
- let result = '';
32
-
33
- for (let index = 0; index < jsonString.length; index++) {
34
- const currentCharacter = jsonString[index];
35
- const nextCharacter = jsonString[index + 1];
36
-
37
- if (!isInsideComment && currentCharacter === '"') {
38
- const escaped = isEscaped(jsonString, index);
39
- if (!escaped) {
40
- isInsideString = !isInsideString;
41
- }
42
- }
43
-
44
- if (isInsideString) {
45
- continue;
46
- }
47
-
48
- if (!isInsideComment && currentCharacter + nextCharacter === '//') {
49
- result += jsonString.slice(offset, index);
50
- offset = index;
51
- isInsideComment = singleComment;
52
- index++;
53
- } else if (isInsideComment === singleComment && currentCharacter + nextCharacter === '\r\n') {
54
- index++;
55
- isInsideComment = false;
56
- result += strip(jsonString, offset, index);
57
- offset = index;
58
- continue;
59
- } else if (isInsideComment === singleComment && currentCharacter === '\n') {
60
- isInsideComment = false;
61
- result += strip(jsonString, offset, index);
62
- offset = index;
63
- } else if (!isInsideComment && currentCharacter + nextCharacter === '/*') {
64
- result += jsonString.slice(offset, index);
65
- offset = index;
66
- isInsideComment = multiComment;
67
- index++;
68
- continue;
69
- } else if (isInsideComment === multiComment && currentCharacter + nextCharacter === '*/') {
70
- index++;
71
- isInsideComment = false;
72
- result += strip(jsonString, offset, index + 1);
73
- offset = index + 1;
74
- continue;
75
- }
76
- }
77
-
78
- return result + (isInsideComment ? (strip as any)(jsonString.slice(offset)) : jsonString.slice(offset));
79
- }