nestia 2.1.0-dev.20220413 → 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 +1 -0
  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} +9 -14
  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 +19 -13
  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 -138
  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 -113
  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 type 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 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,113 +0,0 @@
1
- export interface CompilerOptions
2
- {
3
- target: string;
4
- module: string;
5
- lib: string[];
6
- strict: boolean;
7
- downlevelIteration: boolean;
8
- esModuleInterop?: boolean;
9
- plugins?: Array<{
10
- transform?: string
11
- }>;
12
- types?: string[];
13
- experimentalDecorators?: boolean;
14
- emitDecoratorMetadata?: boolean;
15
- }
16
- export namespace CompilerOptions
17
- {
18
- export const DEPENDENCIES: string[] = [
19
- "nestia-fetcher",
20
- "typescript-is"
21
- ];
22
-
23
- export const TRANSFORMERS: string[] = [
24
- "typescript-is/lib/transform-inline/transformer",
25
- "typescript-transform-paths"
26
- ];
27
-
28
- export const TYPES: string[] = []
29
-
30
- export const DEFAULT = {
31
- target: "es5",
32
- module: "commonjs",
33
- lib: [
34
- "DOM",
35
- "ES2015"
36
- ],
37
- strict: true,
38
- downlevelIteration: true,
39
- esModuleInterop: true,
40
- plugins: TRANSFORMERS.map(transform => ({ transform })),
41
- types: [
42
- "node",
43
- "reflect-metadata"
44
- ],
45
- experimentalDecorators: true,
46
- emitDecoratorMetadata: true,
47
- };
48
-
49
- export function emend(options: CompilerOptions): boolean
50
- {
51
- // FILL ARRAY DATA
52
- if (!options.plugins)
53
- options.plugins = [];
54
- if (!options.types)
55
- options.types = [];
56
-
57
- // CONSTRUCT CHECKERS
58
- const emended: Required<CompilerOptions> = options as Required<CompilerOptions>;
59
- const checkers: Array<() => boolean> = [
60
- () =>
61
- {
62
- let changed: boolean = false;
63
- for (const transform of CompilerOptions.TRANSFORMERS)
64
- {
65
- if (emended.plugins.find(elem => elem.transform === transform) !== undefined)
66
- continue;
67
-
68
- changed = true;
69
- emended.plugins.push({ transform });
70
- }
71
- return changed;
72
- },
73
- () =>
74
- {
75
- let changed: boolean = false;
76
- for (const type of CompilerOptions.TYPES)
77
- {
78
- if (emended.types.find(elem => elem === type) !== undefined)
79
- continue;
80
-
81
- changed = true;
82
- emended.types.push(type);
83
- }
84
- return changed;
85
- },
86
- () =>
87
- {
88
- const changed: boolean = emended.experimentalDecorators !== true;
89
- if (changed)
90
- emended.experimentalDecorators = true;
91
- return changed;
92
- },
93
- () =>
94
- {
95
- const changed: boolean = emended.emitDecoratorMetadata !== true;
96
- if (changed)
97
- emended.emitDecoratorMetadata = true;
98
- return changed;
99
- },
100
- () =>
101
- {
102
- const changed: boolean = emended.esModuleInterop !== true;
103
- if (changed)
104
- emended.esModuleInterop = true;
105
- return changed;
106
- }
107
- ];
108
-
109
- // DO CHECK IT
110
- const checks: boolean[] = checkers.map(func => func());
111
- return checks.some(flag => flag);
112
- }
113
- }
@@ -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 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 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
- }
package/tsconfig.json DELETED
@@ -1,82 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
-
5
- /* Basic Options */
6
- // "incremental": true, /* Enable incremental compilation */
7
- "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8
- "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9
- "lib": [
10
- "DOM",
11
- "ES2015"
12
- ], /* Specify library files to be included in the compilation. */
13
- // "allowJs": true, /* Allow javascript files to be compiled. */
14
- // "checkJs": true, /* Report errors in .js files. */
15
- // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
16
- // "declaration": true, /* Generates corresponding '.d.ts' file. */
17
- // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
18
- // "sourceMap": true, /* Generates corresponding '.map' file. */
19
- // "outFile": "./", /* Concatenate and emit output to single file. */
20
- // "outDir": "./lib", /* Redirect output structure to the directory. */
21
- // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
22
- // "composite": true, /* Enable project compilation */
23
- // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
24
- // "removeComments": true, /* Do not emit comments to output. */
25
- "noEmit": true, /* Do not emit outputs. */
26
- // "importHelpers": true, /* Import emit helpers from 'tslib'. */
27
- "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
28
- // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
29
-
30
- /* Strict Type-Checking Options */
31
- "strict": true, /* Enable all strict type-checking options. */
32
- // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
33
- // "strictNullChecks": true, /* Enable strict null checks. */
34
- // "strictFunctionTypes": true, /* Enable strict checking of function types. */
35
- // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
36
- // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
37
- // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
38
- // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
39
-
40
- /* Additional Checks */
41
- "noUnusedLocals": true, /* Report errors on unused locals. */
42
- "noUnusedParameters": true, /* Report errors on unused parameters. */
43
- "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
44
- "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
45
- // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
46
-
47
- /* Module Resolution Options */
48
- // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
49
- // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
50
- // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
51
- // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
52
- // "typeRoots": [], /* List of folders to include type definitions from. */
53
- "types": [
54
- "node",
55
- "reflect-metadata"
56
- ], /* Type declaration files to be included in compilation. */
57
- // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
58
- "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
59
- // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
60
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
61
-
62
- /* Source Map Options */
63
- // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
64
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
65
- // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
66
- // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
67
-
68
- /* Experimental Options */
69
- "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
70
- "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
71
- "stripInternal": true,
72
-
73
- /* Advanced Options */
74
- "skipLibCheck": true, /* Skip type checking of declaration files. */
75
- "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
76
- "plugins": [
77
- { "transform": "typescript-is/lib/transform-inline/transformer" },
78
- { "transform": "typescript-transform-paths" }
79
- ]
80
- },
81
- "include": ["src"]
82
- }