typia 6.7.2 → 6.8.0-dev.20240811

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 (63) hide show
  1. package/lib/programmers/internal/application_bigint.d.ts +1 -0
  2. package/lib/programmers/internal/application_bigint.js +14 -0
  3. package/lib/programmers/internal/application_bigint.js.map +1 -0
  4. package/lib/programmers/internal/application_v30_schema.js +10 -12
  5. package/lib/programmers/internal/application_v30_schema.js.map +1 -1
  6. package/lib/programmers/internal/application_v31_constant.js +3 -1
  7. package/lib/programmers/internal/application_v31_constant.js.map +1 -1
  8. package/lib/programmers/internal/application_v31_schema.js +10 -12
  9. package/lib/programmers/internal/application_v31_schema.js.map +1 -1
  10. package/lib/tags/Constant.d.ts +2 -2
  11. package/lib/tags/Default.d.ts +5 -1
  12. package/lib/tags/ExclusiveMaximum.d.ts +9 -5
  13. package/lib/tags/ExclusiveMinimum.d.ts +9 -5
  14. package/lib/tags/JsonSchemaPlugin.d.ts +1 -1
  15. package/lib/tags/Maximum.d.ts +8 -5
  16. package/lib/tags/Minimum.d.ts +8 -5
  17. package/lib/tags/MultipleOf.d.ts +7 -4
  18. package/package.json +2 -2
  19. package/src/factories/CommentFactory.ts +79 -79
  20. package/src/factories/MetadataCollection.ts +274 -274
  21. package/src/factories/MetadataFactory.ts +272 -272
  22. package/src/factories/StatementFactory.ts +74 -74
  23. package/src/factories/TypeFactory.ts +118 -118
  24. package/src/factories/internal/metadata/emplace_metadata_array_type.ts +42 -42
  25. package/src/factories/internal/metadata/emplace_metadata_object.ts +176 -176
  26. package/src/factories/internal/metadata/iterate_metadata.ts +94 -94
  27. package/src/factories/internal/metadata/iterate_metadata_array.ts +63 -63
  28. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +62 -62
  29. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  30. package/src/factories/internal/metadata/iterate_metadata_constant.ts +76 -76
  31. package/src/factories/internal/metadata/iterate_metadata_intersection.ts +213 -213
  32. package/src/factories/internal/metadata/iterate_metadata_map.ts +50 -50
  33. package/src/factories/internal/metadata/iterate_metadata_native.ts +220 -220
  34. package/src/factories/internal/metadata/iterate_metadata_object.ts +33 -33
  35. package/src/factories/internal/metadata/iterate_metadata_set.ts +41 -41
  36. package/src/factories/internal/metadata/iterate_metadata_template.ts +44 -44
  37. package/src/factories/internal/metadata/iterate_metadata_union.ts +27 -27
  38. package/src/programmers/internal/application_bigint.ts +25 -0
  39. package/src/programmers/internal/application_v30_alias.ts +52 -52
  40. package/src/programmers/internal/application_v30_object.ts +149 -149
  41. package/src/programmers/internal/application_v30_schema.ts +162 -159
  42. package/src/programmers/internal/application_v30_tuple.ts +33 -33
  43. package/src/programmers/internal/application_v31_constant.ts +4 -1
  44. package/src/programmers/internal/application_v31_schema.ts +159 -157
  45. package/src/programmers/json/JsonApplicationProgrammer.ts +82 -82
  46. package/src/schemas/metadata/IMetadataConstantValue.ts +11 -11
  47. package/src/schemas/metadata/IMetadataTemplate.ts +7 -7
  48. package/src/tags/Constant.ts +2 -2
  49. package/src/tags/Default.ts +7 -3
  50. package/src/tags/ExclusiveMaximum.ts +12 -6
  51. package/src/tags/ExclusiveMinimum.ts +12 -6
  52. package/src/tags/JsonSchemaPlugin.ts +1 -1
  53. package/src/tags/Maximum.ts +9 -8
  54. package/src/tags/Minimum.ts +9 -8
  55. package/src/tags/MultipleOf.ts +9 -8
  56. package/src/tags/Type.ts +32 -32
  57. package/src/transformers/FileTransformer.ts +91 -91
  58. package/src/transformers/features/CreateRandomTransformer.ts +40 -40
  59. package/src/transformers/features/RandomTransformer.ts +44 -44
  60. package/src/transformers/features/json/JsonApplicationTransformer.ts +124 -124
  61. package/src/transformers/features/misc/MiscLiteralsTransformer.ts +32 -32
  62. package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +33 -33
  63. package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +62 -62
@@ -1,274 +1,274 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataComponents } from "../schemas/metadata/IMetadataComponents";
4
- import { Metadata } from "../schemas/metadata/Metadata";
5
- import { MetadataAlias } from "../schemas/metadata/MetadataAlias";
6
- import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
7
- import { MetadataObject } from "../schemas/metadata/MetadataObject";
8
- import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
9
-
10
- import { Writable } from "../typings/Writable";
11
-
12
- import { MapUtil } from "../utils/MapUtil";
13
-
14
- import { CommentFactory } from "./CommentFactory";
15
- import { TypeFactory } from "./TypeFactory";
16
-
17
- export class MetadataCollection {
18
- private objects_: Map<ts.Type, MetadataObject>;
19
- private object_unions_: Map<string, MetadataObject[]>;
20
- private aliases_: Map<ts.Type, MetadataAlias>;
21
- private arrays_: Map<ts.Type, MetadataArrayType>;
22
- private tuples_: Map<ts.Type, MetadataTupleType>;
23
-
24
- private names_: Map<string, Map<ts.Type, string>>;
25
- private object_index_: number;
26
- private recursive_array_index_: number;
27
- private recursive_tuple_index_: number;
28
-
29
- public constructor(
30
- private readonly options?: Partial<MetadataCollection.IOptions>,
31
- ) {
32
- this.objects_ = new Map();
33
- this.object_unions_ = new Map();
34
- this.aliases_ = new Map();
35
- this.arrays_ = new Map();
36
- this.tuples_ = new Map();
37
-
38
- this.names_ = new Map();
39
- this.object_index_ = 0;
40
- this.recursive_array_index_ = 0;
41
- this.recursive_tuple_index_ = 0;
42
- }
43
-
44
- public clone(): MetadataCollection {
45
- const output: MetadataCollection = new MetadataCollection();
46
- output.objects_ = new Map(this.objects_);
47
- output.object_unions_ = new Map(this.object_unions_);
48
- output.aliases_ = new Map(this.aliases_);
49
- output.arrays_ = new Map(this.arrays_);
50
- output.tuples_ = new Map(this.tuples_);
51
- output.names_ = new Map(this.names_);
52
- output.object_index_ = this.object_index_;
53
- output.recursive_array_index_ = this.recursive_array_index_;
54
- output.recursive_tuple_index_ = this.recursive_tuple_index_;
55
- return output;
56
- }
57
-
58
- /* -----------------------------------------------------------
59
- ACCESSORS
60
- ----------------------------------------------------------- */
61
- public aliases(): MetadataAlias[] {
62
- return [...this.aliases_.values()];
63
- }
64
-
65
- public objects(): MetadataObject[] {
66
- return [...this.objects_.values()];
67
- }
68
-
69
- public unions(): MetadataObject[][] {
70
- return [...this.object_unions_.values()];
71
- }
72
-
73
- public arrays(): MetadataArrayType[] {
74
- return [...this.arrays_.values()];
75
- }
76
-
77
- public tuples(): MetadataTupleType[] {
78
- return [...this.tuples_.values()];
79
- }
80
-
81
- private getName(checker: ts.TypeChecker, type: ts.Type): string {
82
- const name: string = (() => {
83
- const str: string = TypeFactory.getFullName(checker)(type);
84
- return this.options?.replace ? this.options.replace(str) : str;
85
- })();
86
-
87
- const duplicates: Map<ts.Type, string> = MapUtil.take(this.names_)(
88
- name,
89
- () => new Map(),
90
- );
91
- const oldbie: string | undefined = duplicates.get(type);
92
- if (oldbie !== undefined) return oldbie;
93
-
94
- const addicted: string = duplicates.size
95
- ? `${name}.o${duplicates.size}`
96
- : name;
97
- duplicates.set(type, addicted);
98
- return addicted;
99
- }
100
-
101
- /**
102
- * @internal
103
- */
104
- public getUnionIndex(meta: Metadata): number {
105
- const key: string = meta.objects.map((obj) => obj.name).join(" | ");
106
- MapUtil.take(this.object_unions_)(key, () => meta.objects);
107
- return [...this.object_unions_.keys()].indexOf(key);
108
- }
109
-
110
- /* -----------------------------------------------------------
111
- INSTANCES
112
- ----------------------------------------------------------- */
113
- public emplace(
114
- checker: ts.TypeChecker,
115
- type: ts.Type,
116
- ): [MetadataObject, boolean] {
117
- const oldbie = this.objects_.get(type);
118
- if (oldbie !== undefined) return [oldbie, false];
119
-
120
- const $id: string = this.getName(checker, type);
121
- const obj: MetadataObject = MetadataObject.create({
122
- name: $id,
123
- properties: [],
124
- description:
125
- (type.aliasSymbol && CommentFactory.description(type.aliasSymbol)) ??
126
- (type.symbol && CommentFactory.description(type.symbol)) ??
127
- undefined,
128
- jsDocTags:
129
- type.aliasSymbol?.getJsDocTags() ?? type.symbol?.getJsDocTags() ?? [],
130
- validated: false,
131
- index: this.object_index_++,
132
- recursive: null!,
133
- nullables: [],
134
- });
135
- this.objects_.set(type, obj);
136
- return [obj, true];
137
- }
138
-
139
- public emplaceAlias(
140
- checker: ts.TypeChecker,
141
- type: ts.Type,
142
- symbol: ts.Symbol,
143
- ): [MetadataAlias, boolean, (meta: Metadata) => void] {
144
- const oldbie = this.aliases_.get(type);
145
- if (oldbie !== undefined) return [oldbie, false, () => {}];
146
-
147
- const $id: string = this.getName(checker, type);
148
- const alias: MetadataAlias = MetadataAlias.create({
149
- name: $id,
150
- value: null!,
151
- description: CommentFactory.description(symbol) ?? null,
152
- recursive: null!,
153
- nullables: [],
154
- jsDocTags: symbol.getJsDocTags() ?? [],
155
- });
156
- this.aliases_.set(type, alias);
157
- return [alias, true, (meta) => (Writable(alias).value = meta)];
158
- }
159
-
160
- public emplaceArray(
161
- checker: ts.TypeChecker,
162
- type: ts.Type,
163
- ): [MetadataArrayType, boolean, (meta: Metadata) => void] {
164
- const oldbie = this.arrays_.get(type);
165
- if (oldbie !== undefined) return [oldbie, false, () => {}];
166
-
167
- const $id = this.getName(checker, type);
168
- const array: MetadataArrayType = MetadataArrayType.create({
169
- name: $id,
170
- value: null!,
171
- index: null,
172
- recursive: null!,
173
- nullables: [],
174
- });
175
- this.arrays_.set(type, array);
176
- return [array, true, (meta) => (Writable(array).value = meta)];
177
- }
178
-
179
- public emplaceTuple(
180
- checker: ts.TypeChecker,
181
- type: ts.TupleType,
182
- ): [MetadataTupleType, boolean, (elements: Metadata[]) => void] {
183
- const oldbie = this.tuples_.get(type);
184
- if (oldbie !== undefined) return [oldbie, false, () => {}];
185
-
186
- const $id = this.getName(checker, type);
187
- const tuple: MetadataTupleType = MetadataTupleType.create({
188
- name: $id,
189
- elements: null!,
190
- index: null,
191
- recursive: null!,
192
- nullables: [],
193
- });
194
- this.tuples_.set(type, tuple);
195
- return [tuple, true, (elements) => (Writable(tuple).elements = elements)];
196
- }
197
-
198
- /**
199
- * @internal
200
- */
201
- public setObjectRecursive(obj: MetadataObject, recursive: boolean): void {
202
- Writable(obj).recursive = recursive;
203
- }
204
-
205
- /**
206
- * @internal
207
- */
208
- public setAliasRecursive(alias: MetadataAlias, recursive: boolean): void {
209
- Writable(alias).recursive = recursive;
210
- }
211
-
212
- /**
213
- * @internal
214
- */
215
- public setArrayRecursive(array: MetadataArrayType, recursive: boolean): void {
216
- Writable(array).recursive = recursive;
217
- if (recursive) Writable(array).index = this.recursive_array_index_++;
218
- }
219
-
220
- public setTupleRecursive(tuple: MetadataTupleType, recursive: boolean): void {
221
- Writable(tuple).recursive = recursive;
222
- if (recursive) Writable(tuple).index = this.recursive_tuple_index_++;
223
- }
224
-
225
- public toJSON(): IMetadataComponents {
226
- return {
227
- objects: this.objects().map((o) => o.toJSON()),
228
- aliases: this.aliases().map((d) => d.toJSON()),
229
- arrays: [...this.arrays_.values()].map((a) => a.toJSON()),
230
- tuples: [...this.tuples_.values()].map((t) => t.toJSON()),
231
- };
232
- }
233
- }
234
- export namespace MetadataCollection {
235
- export interface IOptions {
236
- replace?(str: string): string;
237
- }
238
-
239
- export const replace = (str: string): string => {
240
- let replaced: string = str;
241
- for (const [before] of REPLACERS)
242
- replaced = replaced.split(before).join("");
243
- if (replaced.length !== 0) return replaced;
244
-
245
- for (const [before, after] of REPLACERS)
246
- str = str.split(before).join(after);
247
- return str;
248
- };
249
-
250
- export const escape = (str: string): string => {
251
- for (const [before, after] of REPLACERS)
252
- if (after !== "") str = str.split(after).join(before);
253
- return str;
254
- };
255
- }
256
- const REPLACERS: [string, string][] = [
257
- ["$", "_dollar_"],
258
- ["&", "_and_"],
259
- ["|", "_or_"],
260
- ["{", "_blt_"],
261
- ["}", "_bgt_"],
262
- ["<", "_lt_"],
263
- [">", "_gt_"],
264
- ["[", "_alt_"],
265
- ["]", "_agt_"],
266
- [",", "_comma_"],
267
- ["`", "_backquote_"],
268
- ["'", "_singlequote_"],
269
- ['"', "_doublequote_"],
270
- [" ", "_space_"],
271
- ["?", "_question_"],
272
- [":", "_colon_"],
273
- [";", "_semicolon_"],
274
- ];
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataComponents } from "../schemas/metadata/IMetadataComponents";
4
+ import { Metadata } from "../schemas/metadata/Metadata";
5
+ import { MetadataAlias } from "../schemas/metadata/MetadataAlias";
6
+ import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
7
+ import { MetadataObject } from "../schemas/metadata/MetadataObject";
8
+ import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
9
+
10
+ import { Writable } from "../typings/Writable";
11
+
12
+ import { MapUtil } from "../utils/MapUtil";
13
+
14
+ import { CommentFactory } from "./CommentFactory";
15
+ import { TypeFactory } from "./TypeFactory";
16
+
17
+ export class MetadataCollection {
18
+ private objects_: Map<ts.Type, MetadataObject>;
19
+ private object_unions_: Map<string, MetadataObject[]>;
20
+ private aliases_: Map<ts.Type, MetadataAlias>;
21
+ private arrays_: Map<ts.Type, MetadataArrayType>;
22
+ private tuples_: Map<ts.Type, MetadataTupleType>;
23
+
24
+ private names_: Map<string, Map<ts.Type, string>>;
25
+ private object_index_: number;
26
+ private recursive_array_index_: number;
27
+ private recursive_tuple_index_: number;
28
+
29
+ public constructor(
30
+ private readonly options?: Partial<MetadataCollection.IOptions>,
31
+ ) {
32
+ this.objects_ = new Map();
33
+ this.object_unions_ = new Map();
34
+ this.aliases_ = new Map();
35
+ this.arrays_ = new Map();
36
+ this.tuples_ = new Map();
37
+
38
+ this.names_ = new Map();
39
+ this.object_index_ = 0;
40
+ this.recursive_array_index_ = 0;
41
+ this.recursive_tuple_index_ = 0;
42
+ }
43
+
44
+ public clone(): MetadataCollection {
45
+ const output: MetadataCollection = new MetadataCollection();
46
+ output.objects_ = new Map(this.objects_);
47
+ output.object_unions_ = new Map(this.object_unions_);
48
+ output.aliases_ = new Map(this.aliases_);
49
+ output.arrays_ = new Map(this.arrays_);
50
+ output.tuples_ = new Map(this.tuples_);
51
+ output.names_ = new Map(this.names_);
52
+ output.object_index_ = this.object_index_;
53
+ output.recursive_array_index_ = this.recursive_array_index_;
54
+ output.recursive_tuple_index_ = this.recursive_tuple_index_;
55
+ return output;
56
+ }
57
+
58
+ /* -----------------------------------------------------------
59
+ ACCESSORS
60
+ ----------------------------------------------------------- */
61
+ public aliases(): MetadataAlias[] {
62
+ return [...this.aliases_.values()];
63
+ }
64
+
65
+ public objects(): MetadataObject[] {
66
+ return [...this.objects_.values()];
67
+ }
68
+
69
+ public unions(): MetadataObject[][] {
70
+ return [...this.object_unions_.values()];
71
+ }
72
+
73
+ public arrays(): MetadataArrayType[] {
74
+ return [...this.arrays_.values()];
75
+ }
76
+
77
+ public tuples(): MetadataTupleType[] {
78
+ return [...this.tuples_.values()];
79
+ }
80
+
81
+ private getName(checker: ts.TypeChecker, type: ts.Type): string {
82
+ const name: string = (() => {
83
+ const str: string = TypeFactory.getFullName(checker)(type);
84
+ return this.options?.replace ? this.options.replace(str) : str;
85
+ })();
86
+
87
+ const duplicates: Map<ts.Type, string> = MapUtil.take(this.names_)(
88
+ name,
89
+ () => new Map(),
90
+ );
91
+ const oldbie: string | undefined = duplicates.get(type);
92
+ if (oldbie !== undefined) return oldbie;
93
+
94
+ const addicted: string = duplicates.size
95
+ ? `${name}.o${duplicates.size}`
96
+ : name;
97
+ duplicates.set(type, addicted);
98
+ return addicted;
99
+ }
100
+
101
+ /**
102
+ * @internal
103
+ */
104
+ public getUnionIndex(meta: Metadata): number {
105
+ const key: string = meta.objects.map((obj) => obj.name).join(" | ");
106
+ MapUtil.take(this.object_unions_)(key, () => meta.objects);
107
+ return [...this.object_unions_.keys()].indexOf(key);
108
+ }
109
+
110
+ /* -----------------------------------------------------------
111
+ INSTANCES
112
+ ----------------------------------------------------------- */
113
+ public emplace(
114
+ checker: ts.TypeChecker,
115
+ type: ts.Type,
116
+ ): [MetadataObject, boolean] {
117
+ const oldbie = this.objects_.get(type);
118
+ if (oldbie !== undefined) return [oldbie, false];
119
+
120
+ const $id: string = this.getName(checker, type);
121
+ const obj: MetadataObject = MetadataObject.create({
122
+ name: $id,
123
+ properties: [],
124
+ description:
125
+ (type.aliasSymbol && CommentFactory.description(type.aliasSymbol)) ??
126
+ (type.symbol && CommentFactory.description(type.symbol)) ??
127
+ undefined,
128
+ jsDocTags:
129
+ type.aliasSymbol?.getJsDocTags() ?? type.symbol?.getJsDocTags() ?? [],
130
+ validated: false,
131
+ index: this.object_index_++,
132
+ recursive: null!,
133
+ nullables: [],
134
+ });
135
+ this.objects_.set(type, obj);
136
+ return [obj, true];
137
+ }
138
+
139
+ public emplaceAlias(
140
+ checker: ts.TypeChecker,
141
+ type: ts.Type,
142
+ symbol: ts.Symbol,
143
+ ): [MetadataAlias, boolean, (meta: Metadata) => void] {
144
+ const oldbie = this.aliases_.get(type);
145
+ if (oldbie !== undefined) return [oldbie, false, () => {}];
146
+
147
+ const $id: string = this.getName(checker, type);
148
+ const alias: MetadataAlias = MetadataAlias.create({
149
+ name: $id,
150
+ value: null!,
151
+ description: CommentFactory.description(symbol) ?? null,
152
+ recursive: null!,
153
+ nullables: [],
154
+ jsDocTags: symbol.getJsDocTags() ?? [],
155
+ });
156
+ this.aliases_.set(type, alias);
157
+ return [alias, true, (meta) => (Writable(alias).value = meta)];
158
+ }
159
+
160
+ public emplaceArray(
161
+ checker: ts.TypeChecker,
162
+ type: ts.Type,
163
+ ): [MetadataArrayType, boolean, (meta: Metadata) => void] {
164
+ const oldbie = this.arrays_.get(type);
165
+ if (oldbie !== undefined) return [oldbie, false, () => {}];
166
+
167
+ const $id = this.getName(checker, type);
168
+ const array: MetadataArrayType = MetadataArrayType.create({
169
+ name: $id,
170
+ value: null!,
171
+ index: null,
172
+ recursive: null!,
173
+ nullables: [],
174
+ });
175
+ this.arrays_.set(type, array);
176
+ return [array, true, (meta) => (Writable(array).value = meta)];
177
+ }
178
+
179
+ public emplaceTuple(
180
+ checker: ts.TypeChecker,
181
+ type: ts.TupleType,
182
+ ): [MetadataTupleType, boolean, (elements: Metadata[]) => void] {
183
+ const oldbie = this.tuples_.get(type);
184
+ if (oldbie !== undefined) return [oldbie, false, () => {}];
185
+
186
+ const $id = this.getName(checker, type);
187
+ const tuple: MetadataTupleType = MetadataTupleType.create({
188
+ name: $id,
189
+ elements: null!,
190
+ index: null,
191
+ recursive: null!,
192
+ nullables: [],
193
+ });
194
+ this.tuples_.set(type, tuple);
195
+ return [tuple, true, (elements) => (Writable(tuple).elements = elements)];
196
+ }
197
+
198
+ /**
199
+ * @internal
200
+ */
201
+ public setObjectRecursive(obj: MetadataObject, recursive: boolean): void {
202
+ Writable(obj).recursive = recursive;
203
+ }
204
+
205
+ /**
206
+ * @internal
207
+ */
208
+ public setAliasRecursive(alias: MetadataAlias, recursive: boolean): void {
209
+ Writable(alias).recursive = recursive;
210
+ }
211
+
212
+ /**
213
+ * @internal
214
+ */
215
+ public setArrayRecursive(array: MetadataArrayType, recursive: boolean): void {
216
+ Writable(array).recursive = recursive;
217
+ if (recursive) Writable(array).index = this.recursive_array_index_++;
218
+ }
219
+
220
+ public setTupleRecursive(tuple: MetadataTupleType, recursive: boolean): void {
221
+ Writable(tuple).recursive = recursive;
222
+ if (recursive) Writable(tuple).index = this.recursive_tuple_index_++;
223
+ }
224
+
225
+ public toJSON(): IMetadataComponents {
226
+ return {
227
+ objects: this.objects().map((o) => o.toJSON()),
228
+ aliases: this.aliases().map((d) => d.toJSON()),
229
+ arrays: [...this.arrays_.values()].map((a) => a.toJSON()),
230
+ tuples: [...this.tuples_.values()].map((t) => t.toJSON()),
231
+ };
232
+ }
233
+ }
234
+ export namespace MetadataCollection {
235
+ export interface IOptions {
236
+ replace?(str: string): string;
237
+ }
238
+
239
+ export const replace = (str: string): string => {
240
+ let replaced: string = str;
241
+ for (const [before] of REPLACERS)
242
+ replaced = replaced.split(before).join("");
243
+ if (replaced.length !== 0) return replaced;
244
+
245
+ for (const [before, after] of REPLACERS)
246
+ str = str.split(before).join(after);
247
+ return str;
248
+ };
249
+
250
+ export const escape = (str: string): string => {
251
+ for (const [before, after] of REPLACERS)
252
+ if (after !== "") str = str.split(after).join(before);
253
+ return str;
254
+ };
255
+ }
256
+ const REPLACERS: [string, string][] = [
257
+ ["$", "_dollar_"],
258
+ ["&", "_and_"],
259
+ ["|", "_or_"],
260
+ ["{", "_blt_"],
261
+ ["}", "_bgt_"],
262
+ ["<", "_lt_"],
263
+ [">", "_gt_"],
264
+ ["[", "_alt_"],
265
+ ["]", "_agt_"],
266
+ [",", "_comma_"],
267
+ ["`", "_backquote_"],
268
+ ["'", "_singlequote_"],
269
+ ['"', "_doublequote_"],
270
+ [" ", "_space_"],
271
+ ["?", "_question_"],
272
+ [":", "_colon_"],
273
+ [";", "_semicolon_"],
274
+ ];