baja-lite 1.0.32 → 1.0.34

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 (103) hide show
  1. package/{cjs/boot-remote.d.ts → boot-remote.d.ts} +1 -1
  2. package/{es/boot-remote.js → boot-remote.js} +2 -2
  3. package/{es/boot.d.ts → boot.d.ts} +1 -1
  4. package/{es/boot.js → boot.js} +2 -2
  5. package/{es/enum.js → enum.js} +1 -1
  6. package/{es/fn.js → fn.js} +2 -2
  7. package/index.d.ts +12 -0
  8. package/index.js +12 -0
  9. package/package.json +20 -21
  10. package/{cjs/sql.d.ts → sql.d.ts} +3 -3
  11. package/{es/sql.js → sql.js} +7 -7
  12. package/{es/sqlite.d.ts → sqlite.d.ts} +1 -1
  13. package/{es/sqlite.js → sqlite.js} +1 -1
  14. package/{es/test-mysql.js → test-mysql.js} +2 -2
  15. package/{es/test-postgresql.js → test-postgresql.js} +2 -2
  16. package/cjs/boot-remote.js +0 -49
  17. package/cjs/boot.d.ts +0 -2
  18. package/cjs/boot.js +0 -183
  19. package/cjs/code.js +0 -379
  20. package/cjs/convert-xml.js +0 -417
  21. package/cjs/enum.js +0 -64
  22. package/cjs/error.js +0 -16
  23. package/cjs/fn.js +0 -179
  24. package/cjs/index.d.ts +0 -10
  25. package/cjs/index.js +0 -26
  26. package/cjs/list.js +0 -60
  27. package/cjs/math.js +0 -474
  28. package/cjs/object.js +0 -242
  29. package/cjs/set-ex.js +0 -345
  30. package/cjs/sql.js +0 -5083
  31. package/cjs/sqlite.d.ts +0 -32
  32. package/cjs/sqlite.js +0 -169
  33. package/cjs/string.js +0 -119
  34. package/cjs/test-mysql.js +0 -138
  35. package/cjs/test-postgresql.js +0 -93
  36. package/cjs/test-sqlite.js +0 -91
  37. package/cjs/test-xml.js +0 -75
  38. package/cjs/test.js +0 -4
  39. package/es/boot-remote.d.ts +0 -2
  40. package/es/code.d.ts +0 -2
  41. package/es/convert-xml.d.ts +0 -10
  42. package/es/enum.d.ts +0 -18
  43. package/es/error.d.ts +0 -5
  44. package/es/fn.d.ts +0 -128
  45. package/es/index.d.ts +0 -10
  46. package/es/index.js +0 -10
  47. package/es/list.d.ts +0 -10
  48. package/es/math.d.ts +0 -83
  49. package/es/object.d.ts +0 -83
  50. package/es/set-ex.d.ts +0 -198
  51. package/es/sql.d.ts +0 -1858
  52. package/es/string.d.ts +0 -17
  53. package/es/test-mysql.d.ts +0 -2
  54. package/es/test-postgresql.d.ts +0 -2
  55. package/es/test-sqlite.d.ts +0 -1
  56. package/es/test-xml.d.ts +0 -1
  57. package/es/test.d.ts +0 -1
  58. package/src/boot-remote.ts +0 -46
  59. package/src/boot.ts +0 -153
  60. package/src/code.ts +0 -377
  61. package/src/convert-xml.ts +0 -460
  62. package/src/enum.ts +0 -71
  63. package/src/error.ts +0 -11
  64. package/src/fn.ts +0 -295
  65. package/src/index.ts +0 -10
  66. package/src/list.ts +0 -57
  67. package/src/math.ts +0 -405
  68. package/src/object.ts +0 -247
  69. package/src/set-ex.ts +0 -374
  70. package/src/sql.ts +0 -5281
  71. package/src/sqlite.ts +0 -161
  72. package/src/string.ts +0 -111
  73. package/src/test-mysql.ts +0 -126
  74. package/src/test-postgresql.ts +0 -79
  75. package/src/test-sqlite.ts +0 -80
  76. package/src/test-xml.ts +0 -70
  77. package/src/test.ts +0 -2
  78. /package/{cjs/code.d.ts → code.d.ts} +0 -0
  79. /package/{es/code.js → code.js} +0 -0
  80. /package/{cjs/convert-xml.d.ts → convert-xml.d.ts} +0 -0
  81. /package/{es/convert-xml.js → convert-xml.js} +0 -0
  82. /package/{cjs/enum.d.ts → enum.d.ts} +0 -0
  83. /package/{cjs/error.d.ts → error.d.ts} +0 -0
  84. /package/{es/error.js → error.js} +0 -0
  85. /package/{cjs/fn.d.ts → fn.d.ts} +0 -0
  86. /package/{cjs/list.d.ts → list.d.ts} +0 -0
  87. /package/{es/list.js → list.js} +0 -0
  88. /package/{cjs/math.d.ts → math.d.ts} +0 -0
  89. /package/{es/math.js → math.js} +0 -0
  90. /package/{cjs/object.d.ts → object.d.ts} +0 -0
  91. /package/{es/object.js → object.js} +0 -0
  92. /package/{cjs/set-ex.d.ts → set-ex.d.ts} +0 -0
  93. /package/{es/set-ex.js → set-ex.js} +0 -0
  94. /package/{cjs/string.d.ts → string.d.ts} +0 -0
  95. /package/{es/string.js → string.js} +0 -0
  96. /package/{cjs/test-mysql.d.ts → test-mysql.d.ts} +0 -0
  97. /package/{cjs/test-postgresql.d.ts → test-postgresql.d.ts} +0 -0
  98. /package/{cjs/test-sqlite.d.ts → test-sqlite.d.ts} +0 -0
  99. /package/{es/test-sqlite.js → test-sqlite.js} +0 -0
  100. /package/{cjs/test-xml.d.ts → test-xml.d.ts} +0 -0
  101. /package/{es/test-xml.js → test-xml.js} +0 -0
  102. /package/{cjs/test.d.ts → test.d.ts} +0 -0
  103. /package/{es/test.js → test.js} +0 -0
@@ -1,460 +0,0 @@
1
- import LGet from 'lodash.get';
2
- export interface XML {
3
- type: 'tag' | 'text';
4
- name: string;
5
- id?: string;
6
- voidElement: boolean;
7
- attrs: Record<string, string>;
8
- children: XML[];
9
- content: string;
10
- }
11
- export const convert = function (childrens: XML[], param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
12
- let statement = '';
13
- for (let i = 0, children: XML; children = childrens[i]!; i++) {
14
- // Convert SQL statement recursively
15
- statement += convertChildren(children, param, parentIds, myBatisMapper);
16
- }
17
- // Check not converted Parameters
18
- const regexList = ['\\#{\\S*}', '\\${\\S*}'];
19
- for (let i = 0, regexString: string; regexString = regexList[i]!; i++) {
20
- var checkParam = statement.match(regexString);
21
- if (checkParam != null && checkParam.length > 0) {
22
- throw new Error("Parameter " + checkParam.join(",") + " is not converted.");
23
- }
24
- }
25
- return statement;
26
- }
27
- const convertChildren = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
28
- param ??= {};
29
- if (!isDict(param)) {
30
- throw new Error('Parameter argument should be Key-Value type or Null.');
31
- }
32
- if (children.type == 'text') {
33
- // Convert Parameters
34
- return convertParameters(children, param);
35
-
36
- } else if (children.type == 'tag') {
37
- switch (children.name.toLowerCase()) {
38
- case 'if':
39
- return convertIf(children, param, parentIds, myBatisMapper);
40
- case 'choose':
41
- return convertChoose(children, param, parentIds, myBatisMapper);
42
- case 'trim':
43
- case 'where':
44
- return convertTrimWhere(children, param, parentIds, myBatisMapper);
45
- case 'set':
46
- return convertSet(children, param, parentIds, myBatisMapper);
47
- case 'foreach':
48
- return convertForeach(children, param, parentIds, myBatisMapper);
49
- case 'bind':
50
- param = convertBind(children, param);
51
- return '';
52
- case 'include':
53
- return convertInclude(children, param, parentIds, myBatisMapper);
54
- default:
55
- throw new Error('XML is not well-formed character or markup. Consider using CDATA section.');
56
- }
57
- } else {
58
- return '';
59
- }
60
- }
61
-
62
- const convertParameters = function (children: XML, param: Record<string, any>) {
63
- let convertString = children.content;
64
-
65
- try {
66
- convertString = convertParametersInner('#', convertString, param);
67
- convertString = convertParametersInner('$', convertString, param);
68
- } catch (err) {
69
- throw new Error('Error occurred during convert parameters.');
70
- }
71
-
72
- try {
73
- // convert CDATA string
74
- convertString = convertString.replace(/(\&amp\;)/g, '&');
75
- convertString = convertString.replace(/(\&lt\;)/g, '<');
76
- convertString = convertString.replace(/(\&gt\;)/g, '>');
77
- convertString = convertString.replace(/(\&quot\;)/g, '"');
78
- } catch (err) {
79
- throw new Error('Error occurred during convert CDATA section.');
80
- }
81
-
82
- return convertString;
83
- }
84
-
85
- const isObject = function (variable: any) {
86
- return typeof variable === 'object' && variable !== null;
87
- }
88
-
89
- const isArray = function (variable: any) {
90
- return isObject(variable) && variable.hasOwnProperty('length');
91
- }
92
-
93
- const convertParametersInner = function (change: string, convertString: string, param: Record<string, any>) {
94
- const stringReg = new RegExp('(\\' + change + '\\{[a-zA-Z0-9._\\$]+\\})', 'g');
95
- let stringTarget = convertString.match(stringReg);
96
-
97
- if (stringTarget != null && stringTarget.length > 0) {
98
- const _stringTarget = uniqueArray(stringTarget);
99
-
100
- let target: string | undefined;
101
- for (let i = 0; i < _stringTarget.length; i++) {
102
- target = _stringTarget[i];
103
- const t = target!.replace(change + '{', '').replace('}', '');
104
- let tempParamKey = LGet(param, t);
105
- if (tempParamKey !== undefined) {
106
- const reg = new RegExp('\\' + change + '{' + t + '}', 'g');
107
-
108
- if (tempParamKey === null) {
109
- tempParamKey = 'NULL';
110
- convertString = convertString.replace(reg, tempParamKey);
111
- } else {
112
- if (change == '#') {
113
- // processing JSON fields structures
114
- if (isObject(tempParamKey) || isArray(tempParamKey)) {
115
- tempParamKey = JSON.stringify(tempParamKey);
116
- } else {
117
- tempParamKey = tempParamKey.toString().replace(/"/g, '\\\"');
118
- tempParamKey = mysqlRealEscapeParam(tempParamKey);
119
- }
120
-
121
- tempParamKey = tempParamKey.replace(/'/g, "''");
122
- const replaceWith = "'" + tempParamKey + "'"
123
- convertString = convertString.replace(reg, () => replaceWith);
124
- } else if (change == '$') {
125
- convertString = convertString.replace(reg, tempParamKey);
126
- }
127
- }
128
- }
129
- }
130
- }
131
- return convertString;
132
- }
133
-
134
- const convertIf = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
135
- let evalString = children.attrs['test']!;
136
- try {
137
- // Create Evaluate string
138
- evalString = replaceEvalString(evalString, param);
139
-
140
- evalString = evalString.replace(/ and /gi, ' && ');
141
- evalString = evalString.replace(/ or /gi, ' || ');
142
-
143
- // replace == to === for strict evaluate
144
- // TODO: fix != null & != ''
145
- // evalString = evalString.replace(/==/g, '===');
146
- // evalString = evalString.replace(/!=/g, '!==');
147
-
148
- evalString = evalString.replace(/^'(.*?)'\.equalsIgnoreCase\( ([a-zA-Z]+\.[a-zA-Z]+) \)/i, `($2 && $2.toUpperCase() === '$1'.toUpperCase())`);
149
- evalString = evalString.replace(/\('(.*?)'\.equalsIgnoreCase\( ([a-zA-Z]+\.[a-zA-Z]+) \)/i, `(($2 && $2.toUpperCase() === '$1'.toUpperCase())`);
150
-
151
- } catch (err) {
152
- throw new Error('Error occurred during convert <if> element.');
153
- }
154
-
155
- // Execute Evaluate string
156
- try {
157
- if (eval(evalString)) {
158
- let convertString = '';
159
- for (let i = 0, nextChildren: XML; nextChildren = children['children'][i]!; i++) {
160
- convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
161
- }
162
- return convertString;
163
-
164
- } else {
165
- return '';
166
- }
167
- } catch (e) {
168
- return '';
169
- }
170
- }
171
-
172
- const convertForeach = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
173
- try {
174
- const collection = eval('param.' + children.attrs['collection']);
175
- const item = children.attrs['item']!;
176
- const open = (children.attrs['open'] == null) ? '' : children.attrs['open'];
177
- const close = (children.attrs['close'] == null) ? '' : children.attrs['close'];
178
- const separator = (children.attrs['separator'] == null) ? '' : children.attrs['separator'];
179
-
180
- const foreachTexts: string[] = [];
181
- let coll = null;
182
- for (let j = 0; j < collection.length; j++) {
183
- coll = collection[j];
184
- const foreachParam = param;
185
- foreachParam[item] = coll;
186
-
187
- let foreachText = '';
188
- for (let k = 0, nextChildren: XML; nextChildren = children.children[k]!; k++) {
189
- let fText = convertChildren(nextChildren, foreachParam, parentIds, myBatisMapper);
190
- fText = fText.replace(/^\s*$/g, '');
191
- if (fText != null && fText.length > 0) {
192
- foreachText += fText;
193
- }
194
- }
195
-
196
- if (foreachText != null && foreachText.length > 0) {
197
- foreachTexts.push(foreachText);
198
- }
199
- }
200
-
201
- return (open + foreachTexts.join(separator) + close);
202
- } catch (err) {
203
- throw new Error('Error occurred during convert <foreach> element.');
204
- }
205
- }
206
-
207
- const convertChoose = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
208
- try {
209
- for (let i = 0, whenChildren; whenChildren = children.children[i]; i++) {
210
- if (whenChildren.type == 'tag' && whenChildren.name.toLowerCase() == 'when') {
211
- let evalString = whenChildren.attrs.test;
212
-
213
- // Create Evaluate string
214
- evalString = replaceEvalString(evalString, param);
215
-
216
- evalString = evalString.replace(/ and /gi, ' && ');
217
- evalString = evalString.replace(/ or /gi, ' || ');
218
-
219
- // Execute Evaluate string
220
- try {
221
- if (eval(evalString)) {
222
- // If <when> condition is true, do it.
223
- let convertString = '';
224
- for (let k = 0, nextChildren: XML; nextChildren = whenChildren.children[k]; k++) {
225
- convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
226
- }
227
- return convertString;
228
- } else {
229
- continue;
230
- }
231
- } catch (e) {
232
- continue;
233
- }
234
- } else if (whenChildren.type == 'tag' && whenChildren.name.toLowerCase() == 'otherwise') {
235
- // If reached <otherwise> tag, do it.
236
- let convertString = '';
237
- for (let k = 0, nextChildren: XML; nextChildren = whenChildren.children[k]; k++) {
238
- convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
239
- }
240
- return convertString;
241
- }
242
- }
243
-
244
- // If there is no suitable when and otherwise, just return null.
245
- return '';
246
-
247
- } catch (err) {
248
- throw new Error('Error occurred during convert <choose> element.');
249
- }
250
- }
251
-
252
- const convertTrimWhere = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
253
- let convertString = '';
254
- let prefix: string | undefined;
255
- let prefixOverrides: string | undefined;
256
- let suffix: string | undefined;
257
- let suffixOverrides: string | undefined;
258
- let globalSet: string | undefined;
259
-
260
- try {
261
- switch (children.name.toLowerCase()) {
262
- case 'trim':
263
- prefix = children.attrs["prefix"];
264
- prefixOverrides = children.attrs["prefixOverrides"];
265
- suffix = children.attrs["suffix"];
266
- suffixOverrides = children.attrs["suffixOverrides"];
267
- globalSet = 'g';
268
- break;
269
- case 'where':
270
- prefix = 'WHERE';
271
- prefixOverrides = 'and|or';
272
- globalSet = 'gi';
273
- break;
274
- default:
275
- throw new Error('Error occurred during convert <trim/where> element.');
276
- }
277
-
278
- // Convert children first.
279
- for (let j = 0, nextChildren: XML; nextChildren = children.children[j]!; j++) {
280
- convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
281
- }
282
-
283
- // Remove prefixOverrides
284
- let trimRegex = new RegExp('(^)([\\s]*?)(' + prefixOverrides + ')', globalSet);
285
- convertString = convertString.replace(trimRegex, '');
286
- // Remove suffixOverrides
287
- trimRegex = new RegExp('(' + suffixOverrides + ')([\\s]*?)($)', globalSet);
288
- convertString = convertString.replace(trimRegex, '');
289
-
290
- if (children.name.toLowerCase() != 'trim') {
291
- trimRegex = new RegExp('(' + prefixOverrides + ')([\\s]*?)($)', globalSet);
292
- convertString = convertString.replace(trimRegex, '');
293
- }
294
-
295
- // Add Prefix if String is not empty.
296
- trimRegex = new RegExp('([a-zA-Z])', 'g');
297
- const w = convertString.match(trimRegex);
298
-
299
- if (w != null && w.length > 0) {
300
- convertString = prefix + ' ' + convertString;
301
- if (suffix) {
302
- convertString = convertString + ' ' + suffix
303
- }
304
- }
305
-
306
- // Remove comma(,) before WHERE
307
- if (children.name.toLowerCase() != 'where') {
308
- const regex = new RegExp('(,)([\\s]*?)(where)', 'gi');
309
- convertString = convertString.replace(regex, ' WHERE ');
310
- }
311
-
312
- return convertString;
313
- } catch (err) {
314
- throw new Error('Error occurred during convert <' + children.name.toLowerCase() + '> element.');
315
- }
316
- }
317
-
318
- const convertSet = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
319
- let convertString = '';
320
-
321
- try {
322
- // Convert children first.
323
- for (let j = 0, nextChildren: XML; nextChildren = children.children[j]!; j++) {
324
- convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
325
- }
326
-
327
- // Remove comma repeated more than 2.
328
- let regex = new RegExp('(,)(,|\\s){2,}', 'g');
329
- convertString = convertString.replace(regex, ',\n');
330
-
331
- // Remove first comma if exists.
332
- regex = new RegExp('(^)([\\s]*?)(,)', 'g');
333
- convertString = convertString.replace(regex, '');
334
-
335
- // Remove last comma if exists.
336
- regex = new RegExp('(,)([\\s]*?)($)', 'g');
337
- convertString = convertString.replace(regex, '');
338
-
339
- convertString = ' SET ' + convertString;
340
- return convertString;
341
- } catch (err) {
342
- throw new Error('Error occurred during convert <set> element.');
343
- }
344
- }
345
-
346
- const convertBind = function (children: XML, param: Record<string, any>) {
347
- let evalString = children.attrs["value"]!;
348
-
349
- // Create Evaluate string
350
- evalString = replaceEvalString(evalString, param);
351
-
352
- param[children.attrs["name"]!] = eval(evalString);
353
-
354
- return param;
355
- }
356
-
357
- const convertInclude = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
358
- try {
359
- // Add Properties to param
360
- for (let j = 0, nextChildren: XML; nextChildren = children.children[j]!; j++) {
361
- if (nextChildren.type == 'tag' && nextChildren.name == 'property') {
362
- param[nextChildren.attrs['name']!] = nextChildren.attrs['value'];
363
- }
364
- }
365
- } catch (err) {
366
- throw new Error('Error occurred during read <property> element in <include> element.');
367
- }
368
-
369
- try {
370
- let refid = convertParametersInner('#', children.attrs['refid']!, param);
371
- refid = convertParametersInner('$', refid, param);
372
- let mapper: XML[] | undefined;
373
- for (const psqlid of parentIds) {
374
- mapper = myBatisMapper[`${psqlid}.${refid}`];
375
- if (mapper) {
376
- break;
377
- }
378
- }
379
- let statement = '';
380
- for (let i = 0, children: XML; children = mapper![i]!; i++) {
381
- statement += convertChildren(children, param, parentIds, myBatisMapper);
382
- }
383
- return statement;
384
- } catch (err) {
385
- throw new Error('Error occurred during convert refid attribute in <include> element.');
386
- }
387
-
388
- }
389
-
390
- const isDict = function (v: any) {
391
- return typeof v === 'object' && v !== null && !(v instanceof Array) && !(v instanceof Date);
392
- }
393
-
394
- const replaceEvalString = function (evalString: string, param: Record<string, any>) {
395
- const keys = Object.keys(param);
396
-
397
- for (let i = 0; i < keys.length; i++) {
398
- let replacePrefix = '';
399
- let replacePostfix = '';
400
- let paramRegex: RegExp | undefined;
401
-
402
- if (isDict(param[keys[i]!])) {
403
- replacePrefix = ' param.';
404
- replacePostfix = '';
405
-
406
- paramRegex = new RegExp('(^|[^a-zA-Z0-9_])(' + keys[i] + '\\.)([a-zA-Z0-9_]+)', 'g');
407
- } else {
408
- replacePrefix = ' param.';
409
- replacePostfix = ' ';
410
- paramRegex = new RegExp('(^|[^a-zA-Z0-9_])(' + keys[i] + ')($|[^a-zA-Z0-9_])', 'g');
411
- }
412
- evalString = evalString.replace(paramRegex, ('$1' + replacePrefix + '$2' + replacePostfix + '$3'));
413
- }
414
- return evalString;
415
- }
416
-
417
- const uniqueArray = function (a: RegExpMatchArray) {
418
- const seen = {};
419
- const out: string[] = [];
420
- const len = a.length;
421
- let j = 0;
422
- for (let i = 0; i < len; i++) {
423
- const item = a[i]!;
424
- if (seen[item] !== 1) {
425
- seen[item] = 1;
426
- out[j++] = item;
427
- }
428
- }
429
- return out;
430
- }
431
-
432
- const mysqlRealEscapeParam = function (param) {
433
- if (typeof param != 'string')
434
- return param;
435
-
436
- return param.replace(/[\0\x08\x09\x1a\n\r''\\\%]/g, function (char) {
437
- switch (char) {
438
- case '\0':
439
- return '\\0';
440
- case '\x08':
441
- return '\\b';
442
- case '\x09':
443
- return '\\t';
444
- case '\x1a':
445
- return '\\z';
446
- case '\n':
447
- return '\\n';
448
- case '\r':
449
- return '\\r';
450
- case '\'':
451
- case `'`:
452
- case '\\':
453
- case '%':
454
- return '\\' + char;
455
- default:
456
- return char;
457
- }
458
- });
459
- }
460
-
package/src/enum.ts DELETED
@@ -1,71 +0,0 @@
1
- import { _enums } from "./sql";
2
-
3
- export class Enum {
4
- private _value: string;
5
- private _desc: string;
6
- private _config: string[];
7
- constructor(value: string, desc: string, ...config: string[]) {
8
- this._value = value;
9
- this._desc = desc;
10
- this._config = config;
11
- }
12
- eq(value: string | number | undefined | null): boolean {
13
- if (value === undefined) {
14
- return false;
15
- }
16
- if (value === null) {
17
- return false;
18
- }
19
- if (typeof value === 'number') {
20
- return this._value === `${value}`;
21
- }
22
- return this._value === `${value}`;
23
- }
24
- value(): string {
25
- return this._value;
26
- }
27
- desc(): string {
28
- return this._desc;
29
- }
30
- config(): string[] {
31
- return this._config;
32
- }
33
- }
34
- export type EnumMap = Record<string, Enum>;
35
- export type GlobalArray = Record<string, Array<[string, string]>>;
36
- export type GlobalMap = Record<string, Record<string, string>>;
37
- export interface EnmuJson {
38
- GlobalArray: GlobalArray;
39
- GlobalMap: GlobalMap;
40
- }
41
- let configData: EnmuJson | null = null;
42
- export const getEnums = (GlobalValues?: EnumMap): EnmuJson => {
43
- if (!GlobalValues) {
44
- return globalThis[_enums];
45
- }
46
- if (configData) {
47
- return configData;
48
- }
49
- const result: EnmuJson = {
50
- GlobalArray: {},
51
- GlobalMap: {}
52
- };
53
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
54
- Object.keys(GlobalValues).forEach((item) => {
55
- // const guess = /([\w\W]+)_([^_]+)$/.exec(item);
56
- const guess = item.replace(new RegExp(`_${GlobalValues[item]!.value()}`, 'i'), '');
57
- if (guess) {
58
- if (!result.GlobalArray[guess]) {
59
- result.GlobalArray[guess] = [];
60
- }
61
- result.GlobalArray[guess]!.push([GlobalValues[item]!.value(), GlobalValues[item]!.desc()]);
62
-
63
- if (!result.GlobalMap[guess]) {
64
- result.GlobalMap[guess] = {};
65
- }
66
- result.GlobalMap[guess]![GlobalValues[item]!.value()] = GlobalValues[item]!.desc();
67
- }
68
- });
69
- configData = result;
70
- return result;
71
- };
package/src/error.ts DELETED
@@ -1,11 +0,0 @@
1
- export const Throw = {
2
- if(test: boolean, message: string | Error | any) {
3
- if (test === true) this.now(message);
4
- },
5
- ifNot(test: boolean, message: string | Error | any) {
6
- if (test !== true) this.now(message);
7
- },
8
- now(message: string | Error | any) {
9
- throw typeof message === 'string' ? new Error(message) : message;
10
- }
11
- };