baja-lite 1.0.4 → 1.0.6

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 (85) hide show
  1. package/cjs/boot-remote.d.ts +2 -0
  2. package/cjs/boot-remote.js +35 -0
  3. package/cjs/boot.d.ts +2 -0
  4. package/cjs/boot.js +152 -0
  5. package/cjs/code.d.ts +1 -0
  6. package/cjs/code.js +359 -1
  7. package/cjs/convert-xml.d.ts +10 -0
  8. package/cjs/convert-xml.js +414 -0
  9. package/cjs/enum.d.ts +10 -0
  10. package/cjs/enum.js +32 -0
  11. package/cjs/error.js +1 -1
  12. package/cjs/fn.js +3 -3
  13. package/cjs/index.d.ts +3 -0
  14. package/cjs/index.js +3 -0
  15. package/cjs/list.d.ts +10 -0
  16. package/cjs/list.js +36 -0
  17. package/cjs/object.d.ts +7 -1
  18. package/cjs/object.js +36 -2
  19. package/cjs/set-ex.d.ts +41 -15
  20. package/cjs/set-ex.js +68 -52
  21. package/cjs/sql.d.ts +760 -305
  22. package/cjs/sql.js +1702 -1041
  23. package/cjs/sqlite.d.ts +38 -0
  24. package/cjs/sqlite.js +194 -0
  25. package/cjs/test-mysql.d.ts +2 -1
  26. package/cjs/test-mysql.js +85 -63
  27. package/cjs/test-sqlite.d.ts +1 -1
  28. package/cjs/test-sqlite.js +3 -1
  29. package/cjs/test-xml.d.ts +1 -0
  30. package/cjs/test-xml.js +75 -0
  31. package/es/boot-remote.d.ts +2 -0
  32. package/es/boot-remote.js +31 -0
  33. package/es/boot.d.ts +2 -0
  34. package/es/boot.js +125 -0
  35. package/es/code.d.ts +1 -0
  36. package/es/code.js +355 -2
  37. package/es/convert-xml.d.ts +10 -0
  38. package/es/convert-xml.js +410 -0
  39. package/es/enum.d.ts +10 -0
  40. package/es/enum.js +28 -0
  41. package/es/error.js +1 -1
  42. package/es/index.d.ts +3 -0
  43. package/es/index.js +3 -0
  44. package/es/list.d.ts +10 -0
  45. package/es/list.js +32 -0
  46. package/es/object.d.ts +7 -1
  47. package/es/object.js +28 -1
  48. package/es/set-ex.d.ts +41 -15
  49. package/es/set-ex.js +68 -52
  50. package/es/sql.d.ts +760 -305
  51. package/es/sql.js +1573 -917
  52. package/es/sqlite.d.ts +38 -0
  53. package/es/sqlite.js +164 -0
  54. package/es/test-mysql.d.ts +2 -1
  55. package/es/test-mysql.js +85 -64
  56. package/es/test-sqlite.d.ts +1 -1
  57. package/es/test-sqlite.js +3 -1
  58. package/es/test-xml.d.ts +1 -0
  59. package/es/test-xml.js +70 -0
  60. package/package.json +15 -10
  61. package/src/boot-remote.ts +31 -0
  62. package/src/boot.ts +129 -0
  63. package/src/code.ts +342 -1
  64. package/src/convert-xml.ts +462 -0
  65. package/src/enum.ts +31 -0
  66. package/src/error.ts +1 -1
  67. package/src/index.ts +4 -1
  68. package/src/list.ts +31 -0
  69. package/src/object.ts +48 -14
  70. package/src/set-ex.ts +91 -70
  71. package/src/sql.ts +1652 -965
  72. package/src/sqlite.ts +161 -0
  73. package/src/test-mysql.ts +93 -65
  74. package/src/test-sqlite.ts +3 -1
  75. package/src/test-xml.ts +70 -0
  76. package/cjs/constant.d.ts +0 -13
  77. package/cjs/constant.js +0 -19
  78. package/cjs/redis.d.ts +0 -0
  79. package/cjs/redis.js +0 -1
  80. package/es/constant.d.ts +0 -13
  81. package/es/constant.js +0 -16
  82. package/es/redis.d.ts +0 -0
  83. package/es/redis.js +0 -1
  84. package/src/constant.ts +0 -14
  85. package/src/redis.ts +0 -0
@@ -0,0 +1,414 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convert = void 0;
4
+ const convert = function (childrens, param, parentIds, myBatisMapper) {
5
+ let statement = '';
6
+ for (let i = 0, children; children = childrens[i]; i++) {
7
+ // Convert SQL statement recursively
8
+ statement += convertChildren(children, param, parentIds, myBatisMapper);
9
+ }
10
+ // Check not converted Parameters
11
+ var regexList = ['\\#{\\S*}', '\\${\\S*}'];
12
+ for (var i = 0, regexString; regexString = regexList[i]; i++) {
13
+ var regex = new RegExp(regex, 'g');
14
+ var checkParam = statement.match(regexString);
15
+ if (checkParam != null && checkParam.length > 0) {
16
+ throw new Error("Parameter " + checkParam.join(",") + " is not converted.");
17
+ }
18
+ }
19
+ return statement;
20
+ };
21
+ exports.convert = convert;
22
+ const convertChildren = function (children, param, parentIds, myBatisMapper) {
23
+ param ?? (param = {});
24
+ if (!isDict(param)) {
25
+ throw new Error('Parameter argument should be Key-Value type or Null.');
26
+ }
27
+ if (children.type == 'text') {
28
+ // Convert Parameters
29
+ return convertParameters(children, param);
30
+ }
31
+ else if (children.type == 'tag') {
32
+ switch (children.name.toLowerCase()) {
33
+ case 'if':
34
+ return convertIf(children, param, parentIds, myBatisMapper);
35
+ case 'choose':
36
+ return convertChoose(children, param, parentIds, myBatisMapper);
37
+ case 'trim':
38
+ case 'where':
39
+ return convertTrimWhere(children, param, parentIds, myBatisMapper);
40
+ case 'set':
41
+ return convertSet(children, param, parentIds, myBatisMapper);
42
+ case 'foreach':
43
+ return convertForeach(children, param, parentIds, myBatisMapper);
44
+ case 'bind':
45
+ param = convertBind(children, param);
46
+ return '';
47
+ case 'include':
48
+ return convertInclude(children, param, parentIds, myBatisMapper);
49
+ default:
50
+ throw new Error('XML is not well-formed character or markup. Consider using CDATA section.');
51
+ }
52
+ }
53
+ else {
54
+ return '';
55
+ }
56
+ };
57
+ const convertParameters = function (children, param) {
58
+ let convertString = children.content;
59
+ try {
60
+ convertString = convertParametersInner('#', convertString, param);
61
+ convertString = convertParametersInner('$', convertString, param);
62
+ }
63
+ catch (err) {
64
+ throw new Error('Error occurred during convert parameters.');
65
+ }
66
+ try {
67
+ // convert CDATA string
68
+ convertString = convertString.replace(/(\&amp\;)/g, '&');
69
+ convertString = convertString.replace(/(\&lt\;)/g, '<');
70
+ convertString = convertString.replace(/(\&gt\;)/g, '>');
71
+ convertString = convertString.replace(/(\&quot\;)/g, '"');
72
+ }
73
+ catch (err) {
74
+ throw new Error('Error occurred during convert CDATA section.');
75
+ }
76
+ return convertString;
77
+ };
78
+ const isObject = function (variable) {
79
+ return typeof variable === 'object' && variable !== null;
80
+ };
81
+ const isArray = function (variable) {
82
+ return isObject(variable) && variable.hasOwnProperty('length');
83
+ };
84
+ const convertParametersInner = function (change, convertString, param) {
85
+ const stringReg = new RegExp('(\\' + change + '\\{[a-zA-Z0-9._\\$]+\\})', 'g');
86
+ let stringTarget = convertString.match(stringReg);
87
+ if (stringTarget != null && stringTarget.length > 0) {
88
+ const _stringTarget = uniqueArray(stringTarget);
89
+ let target;
90
+ for (let i = 0; i < _stringTarget.length; i++) {
91
+ target = _stringTarget[i];
92
+ const t = target.replace(change + '{', '').replace('}', '');
93
+ let tempParamKey = eval('param.' + t);
94
+ if (tempParamKey !== undefined) {
95
+ const reg = new RegExp('\\' + change + '{' + t + '}', 'g');
96
+ if (tempParamKey === null) {
97
+ tempParamKey = 'NULL';
98
+ convertString = convertString.replace(reg, tempParamKey);
99
+ }
100
+ else {
101
+ if (change == '#') {
102
+ // processing JSON fields structures
103
+ if (isObject(tempParamKey) || isArray(tempParamKey)) {
104
+ tempParamKey = JSON.stringify(tempParamKey);
105
+ }
106
+ else {
107
+ tempParamKey = tempParamKey.toString().replace(/"/g, '\\\"');
108
+ tempParamKey = mysqlRealEscapeParam(tempParamKey);
109
+ }
110
+ tempParamKey = tempParamKey.replace(/'/g, "''");
111
+ const replaceWith = "'" + tempParamKey + "'";
112
+ convertString = convertString.replace(reg, () => replaceWith);
113
+ }
114
+ else if (change == '$') {
115
+ convertString = convertString.replace(reg, tempParamKey);
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ return convertString;
122
+ };
123
+ const convertIf = function (children, param, parentIds, myBatisMapper) {
124
+ let evalString = children.attrs['test'];
125
+ try {
126
+ // Create Evaluate string
127
+ evalString = replaceEvalString(evalString, param);
128
+ evalString = evalString.replace(/ and /gi, ' && ');
129
+ evalString = evalString.replace(/ or /gi, ' || ');
130
+ // replace == to === for strict evaluate
131
+ // TODO: fix != null & != ''
132
+ // evalString = evalString.replace(/==/g, '===');
133
+ // evalString = evalString.replace(/!=/g, '!==');
134
+ evalString = evalString.replace(/^'(.*?)'\.equalsIgnoreCase\( ([a-zA-Z]+\.[a-zA-Z]+) \)/i, `($2 && $2.toUpperCase() === '$1'.toUpperCase())`);
135
+ evalString = evalString.replace(/\('(.*?)'\.equalsIgnoreCase\( ([a-zA-Z]+\.[a-zA-Z]+) \)/i, `(($2 && $2.toUpperCase() === '$1'.toUpperCase())`);
136
+ }
137
+ catch (err) {
138
+ throw new Error('Error occurred during convert <if> element.');
139
+ }
140
+ // Execute Evaluate string
141
+ try {
142
+ if (eval(evalString)) {
143
+ let convertString = '';
144
+ for (let i = 0, nextChildren; nextChildren = children['children'][i]; i++) {
145
+ convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
146
+ }
147
+ return convertString;
148
+ }
149
+ else {
150
+ return '';
151
+ }
152
+ }
153
+ catch (e) {
154
+ return '';
155
+ }
156
+ };
157
+ const convertForeach = function (children, param, parentIds, myBatisMapper) {
158
+ try {
159
+ const collection = eval('param.' + children.attrs['collection']);
160
+ const item = children.attrs['item'];
161
+ const open = (children.attrs['open'] == null) ? '' : children.attrs['open'];
162
+ const close = (children.attrs['close'] == null) ? '' : children.attrs['close'];
163
+ const separator = (children.attrs['separator'] == null) ? '' : children.attrs['separator'];
164
+ const foreachTexts = [];
165
+ let coll = null;
166
+ for (let j = 0; j < collection.length; j++) {
167
+ coll = collection[j];
168
+ const foreachParam = param;
169
+ foreachParam[item] = coll;
170
+ let foreachText = '';
171
+ for (let k = 0, nextChildren; nextChildren = children.children[k]; k++) {
172
+ let fText = convertChildren(nextChildren, foreachParam, parentIds, myBatisMapper);
173
+ fText = fText.replace(/^\s*$/g, '');
174
+ if (fText != null && fText.length > 0) {
175
+ foreachText += fText;
176
+ }
177
+ }
178
+ if (foreachText != null && foreachText.length > 0) {
179
+ foreachTexts.push(foreachText);
180
+ }
181
+ }
182
+ return (open + foreachTexts.join(separator) + close);
183
+ }
184
+ catch (err) {
185
+ throw new Error('Error occurred during convert <foreach> element.');
186
+ }
187
+ };
188
+ const convertChoose = function (children, param, parentIds, myBatisMapper) {
189
+ try {
190
+ for (let i = 0, whenChildren; whenChildren = children.children[i]; i++) {
191
+ if (whenChildren.type == 'tag' && whenChildren.name.toLowerCase() == 'when') {
192
+ let evalString = whenChildren.attrs.test;
193
+ // Create Evaluate string
194
+ evalString = replaceEvalString(evalString, param);
195
+ evalString = evalString.replace(/ and /gi, ' && ');
196
+ evalString = evalString.replace(/ or /gi, ' || ');
197
+ // Execute Evaluate string
198
+ try {
199
+ if (eval(evalString)) {
200
+ // If <when> condition is true, do it.
201
+ let convertString = '';
202
+ for (let k = 0, nextChildren; nextChildren = whenChildren.children[k]; k++) {
203
+ convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
204
+ }
205
+ return convertString;
206
+ }
207
+ else {
208
+ continue;
209
+ }
210
+ }
211
+ catch (e) {
212
+ continue;
213
+ }
214
+ }
215
+ else if (whenChildren.type == 'tag' && whenChildren.name.toLowerCase() == 'otherwise') {
216
+ // If reached <otherwise> tag, do it.
217
+ let convertString = '';
218
+ for (let k = 0, nextChildren; nextChildren = whenChildren.children[k]; k++) {
219
+ convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
220
+ }
221
+ return convertString;
222
+ }
223
+ }
224
+ // If there is no suitable when and otherwise, just return null.
225
+ return '';
226
+ }
227
+ catch (err) {
228
+ throw new Error('Error occurred during convert <choose> element.');
229
+ }
230
+ };
231
+ const convertTrimWhere = function (children, param, parentIds, myBatisMapper) {
232
+ let convertString = '';
233
+ let prefix;
234
+ let prefixOverrides;
235
+ let suffix;
236
+ let suffixOverrides;
237
+ let globalSet;
238
+ try {
239
+ switch (children.name.toLowerCase()) {
240
+ case 'trim':
241
+ prefix = children.attrs["prefix"];
242
+ prefixOverrides = children.attrs["prefixOverrides"];
243
+ suffix = children.attrs["suffix"];
244
+ suffixOverrides = children.attrs["suffixOverrides"];
245
+ globalSet = 'g';
246
+ break;
247
+ case 'where':
248
+ prefix = 'WHERE';
249
+ prefixOverrides = 'and|or';
250
+ globalSet = 'gi';
251
+ break;
252
+ default:
253
+ throw new Error('Error occurred during convert <trim/where> element.');
254
+ }
255
+ // Convert children first.
256
+ for (let j = 0, nextChildren; nextChildren = children.children[j]; j++) {
257
+ convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
258
+ }
259
+ // Remove prefixOverrides
260
+ let trimRegex = new RegExp('(^)([\\s]*?)(' + prefixOverrides + ')', globalSet);
261
+ convertString = convertString.replace(trimRegex, '');
262
+ // Remove suffixOverrides
263
+ trimRegex = new RegExp('(' + suffixOverrides + ')([\\s]*?)($)', globalSet);
264
+ convertString = convertString.replace(trimRegex, '');
265
+ if (children.name.toLowerCase() != 'trim') {
266
+ trimRegex = new RegExp('(' + prefixOverrides + ')([\\s]*?)($)', globalSet);
267
+ convertString = convertString.replace(trimRegex, '');
268
+ }
269
+ // Add Prefix if String is not empty.
270
+ trimRegex = new RegExp('([a-zA-Z])', 'g');
271
+ const w = convertString.match(trimRegex);
272
+ if (w != null && w.length > 0) {
273
+ convertString = prefix + ' ' + convertString;
274
+ if (suffix) {
275
+ convertString = convertString + ' ' + suffix;
276
+ }
277
+ }
278
+ // Remove comma(,) before WHERE
279
+ if (children.name.toLowerCase() != 'where') {
280
+ const regex = new RegExp('(,)([\\s]*?)(where)', 'gi');
281
+ convertString = convertString.replace(regex, ' WHERE ');
282
+ }
283
+ return convertString;
284
+ }
285
+ catch (err) {
286
+ throw new Error('Error occurred during convert <' + children.name.toLowerCase() + '> element.');
287
+ }
288
+ };
289
+ const convertSet = function (children, param, parentIds, myBatisMapper) {
290
+ let convertString = '';
291
+ try {
292
+ // Convert children first.
293
+ for (let j = 0, nextChildren; nextChildren = children.children[j]; j++) {
294
+ convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
295
+ }
296
+ // Remove comma repeated more than 2.
297
+ let regex = new RegExp('(,)(,|\\s){2,}', 'g');
298
+ convertString = convertString.replace(regex, ',\n');
299
+ // Remove first comma if exists.
300
+ regex = new RegExp('(^)([\\s]*?)(,)', 'g');
301
+ convertString = convertString.replace(regex, '');
302
+ // Remove last comma if exists.
303
+ regex = new RegExp('(,)([\\s]*?)($)', 'g');
304
+ convertString = convertString.replace(regex, '');
305
+ convertString = ' SET ' + convertString;
306
+ return convertString;
307
+ }
308
+ catch (err) {
309
+ throw new Error('Error occurred during convert <set> element.');
310
+ }
311
+ };
312
+ const convertBind = function (children, param) {
313
+ let evalString = children.attrs["value"];
314
+ // Create Evaluate string
315
+ evalString = replaceEvalString(evalString, param);
316
+ param[children.attrs["name"]] = eval(evalString);
317
+ return param;
318
+ };
319
+ const convertInclude = function (children, param, parentIds, myBatisMapper) {
320
+ try {
321
+ // Add Properties to param
322
+ for (let j = 0, nextChildren; nextChildren = children.children[j]; j++) {
323
+ if (nextChildren.type == 'tag' && nextChildren.name == 'property') {
324
+ param[nextChildren.attrs['name']] = nextChildren.attrs['value'];
325
+ }
326
+ }
327
+ }
328
+ catch (err) {
329
+ throw new Error('Error occurred during read <property> element in <include> element.');
330
+ }
331
+ try {
332
+ let refid = convertParametersInner('#', children.attrs['refid'], param);
333
+ refid = convertParametersInner('$', refid, param);
334
+ let mapper;
335
+ for (const psqlid of parentIds) {
336
+ mapper = myBatisMapper[`${psqlid}.${refid}`];
337
+ if (mapper) {
338
+ break;
339
+ }
340
+ }
341
+ let statement = '';
342
+ for (let i = 0, children; children = mapper[i]; i++) {
343
+ statement += convertChildren(children, param, parentIds, myBatisMapper);
344
+ }
345
+ return statement;
346
+ }
347
+ catch (err) {
348
+ throw new Error('Error occurred during convert refid attribute in <include> element.');
349
+ }
350
+ };
351
+ const isDict = function (v) {
352
+ return typeof v === 'object' && v !== null && !(v instanceof Array) && !(v instanceof Date);
353
+ };
354
+ const replaceEvalString = function (evalString, param) {
355
+ const keys = Object.keys(param);
356
+ for (let i = 0; i < keys.length; i++) {
357
+ let replacePrefix = '';
358
+ let replacePostfix = '';
359
+ let paramRegex;
360
+ if (isDict(param[keys[i]])) {
361
+ replacePrefix = ' param.';
362
+ replacePostfix = '';
363
+ paramRegex = new RegExp('(^|[^a-zA-Z0-9_])(' + keys[i] + '\\.)([a-zA-Z0-9_]+)', 'g');
364
+ }
365
+ else {
366
+ replacePrefix = ' param.';
367
+ replacePostfix = ' ';
368
+ paramRegex = new RegExp('(^|[^a-zA-Z0-9_])(' + keys[i] + ')($|[^a-zA-Z0-9_])', 'g');
369
+ }
370
+ evalString = evalString.replace(paramRegex, ('$1' + replacePrefix + '$2' + replacePostfix + '$3'));
371
+ }
372
+ return evalString;
373
+ };
374
+ const uniqueArray = function (a) {
375
+ const seen = {};
376
+ const out = [];
377
+ const len = a.length;
378
+ let j = 0;
379
+ for (let i = 0; i < len; i++) {
380
+ const item = a[i];
381
+ if (seen[item] !== 1) {
382
+ seen[item] = 1;
383
+ out[j++] = item;
384
+ }
385
+ }
386
+ return out;
387
+ };
388
+ const mysqlRealEscapeParam = function (param) {
389
+ if (typeof param != 'string')
390
+ return param;
391
+ return param.replace(/[\0\x08\x09\x1a\n\r''\\\%]/g, function (char) {
392
+ switch (char) {
393
+ case '\0':
394
+ return '\\0';
395
+ case '\x08':
396
+ return '\\b';
397
+ case '\x09':
398
+ return '\\t';
399
+ case '\x1a':
400
+ return '\\z';
401
+ case '\n':
402
+ return '\\n';
403
+ case '\r':
404
+ return '\\r';
405
+ case '\'':
406
+ case `'`:
407
+ case '\\':
408
+ case '%':
409
+ return '\\' + char;
410
+ default:
411
+ return char;
412
+ }
413
+ });
414
+ };
package/cjs/enum.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare class Enum {
2
+ private _value;
3
+ private _desc;
4
+ private _config;
5
+ constructor(value: string, desc: string, ...config: string[]);
6
+ eq(value: string | number | undefined | null): boolean;
7
+ value(): string;
8
+ desc(): string;
9
+ config(): string[];
10
+ }
package/cjs/enum.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Enum = void 0;
4
+ class Enum {
5
+ constructor(value, desc, ...config) {
6
+ this._value = value;
7
+ this._desc = desc;
8
+ this._config = config;
9
+ }
10
+ eq(value) {
11
+ if (value === undefined) {
12
+ return false;
13
+ }
14
+ if (value === null) {
15
+ return false;
16
+ }
17
+ if (typeof value === 'number') {
18
+ return this._value === `${value}`;
19
+ }
20
+ return this._value === `${value}`;
21
+ }
22
+ value() {
23
+ return this._value;
24
+ }
25
+ desc() {
26
+ return this._desc;
27
+ }
28
+ config() {
29
+ return this._config;
30
+ }
31
+ }
32
+ exports.Enum = Enum;
package/cjs/error.js CHANGED
@@ -12,5 +12,5 @@ exports.Throw = {
12
12
  },
13
13
  now(message) {
14
14
  throw typeof message === 'string' ? new Error(message) : message;
15
- },
15
+ }
16
16
  };
package/cjs/fn.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.excuteSplit = exports.ExcuteSplitMode = exports.dieTrying = exports.sleep = exports.promise = void 0;
3
+ exports.ExcuteSplitMode = exports.sleep = exports.promise = void 0;
4
+ exports.dieTrying = dieTrying;
5
+ exports.excuteSplit = excuteSplit;
4
6
  const object_1 = require("./object");
5
7
  const error_1 = require("./error");
6
8
  /**
@@ -74,7 +76,6 @@ async function dieTrying(fn, { ifFinish = (result) => !!result, maxTryTimes = 20
74
76
  }
75
77
  return result;
76
78
  }
77
- exports.dieTrying = dieTrying;
78
79
  var ExcuteSplitMode;
79
80
  (function (ExcuteSplitMode) {
80
81
  ExcuteSplitMode[ExcuteSplitMode["SyncTrust"] = 0] = "SyncTrust";
@@ -166,4 +167,3 @@ function excuteSplit(sync, datas, fn, { everyLength = 0, groupCount = 0, settled
166
167
  return reasons;
167
168
  }
168
169
  }
169
- exports.excuteSplit = excuteSplit;
package/cjs/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import 'reflect-metadata';
1
2
  export * from './error';
2
3
  export * from './fn';
3
4
  export * from './math';
@@ -5,3 +6,5 @@ export * from './object';
5
6
  export * from './set-ex';
6
7
  export * from './sql';
7
8
  export * from './string';
9
+ export * from './enum';
10
+ export * from './list';
package/cjs/index.js CHANGED
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ require("reflect-metadata");
17
18
  __exportStar(require("./error"), exports);
18
19
  __exportStar(require("./fn"), exports);
19
20
  __exportStar(require("./math"), exports);
@@ -21,3 +22,5 @@ __exportStar(require("./object"), exports);
21
22
  __exportStar(require("./set-ex"), exports);
22
23
  __exportStar(require("./sql"), exports);
23
24
  __exportStar(require("./string"), exports);
25
+ __exportStar(require("./enum"), exports);
26
+ __exportStar(require("./list"), exports);
package/cjs/list.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare class ArrayList<T> extends Array<T> {
2
+ constructor(array?: Array<T> | T | undefined);
3
+ add(...items: T[]): void;
4
+ size(): number;
5
+ isEmpty(): boolean;
6
+ get(index: number): T | undefined;
7
+ clear(): void;
8
+ set(index: number, item: T): void;
9
+ remove(index: number): void;
10
+ }
package/cjs/list.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArrayList = void 0;
4
+ class ArrayList extends Array {
5
+ constructor(array) {
6
+ super();
7
+ if (array instanceof Array) {
8
+ super.push(...array);
9
+ }
10
+ else if (typeof array !== 'undefined') {
11
+ super.push(array);
12
+ }
13
+ }
14
+ add(...items) {
15
+ this.push(...items);
16
+ }
17
+ size() {
18
+ return this.length;
19
+ }
20
+ isEmpty() {
21
+ return this.length === 0;
22
+ }
23
+ get(index) {
24
+ return this[index];
25
+ }
26
+ clear() {
27
+ this.length = 0;
28
+ }
29
+ set(index, item) {
30
+ this[index] = item;
31
+ }
32
+ remove(index) {
33
+ this.splice(index, 1);
34
+ }
35
+ }
36
+ exports.ArrayList = ArrayList;
package/cjs/object.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 对象对象(等同与convertBean)
3
3
  * 仅会将classType有的属性进行转换
4
- * 相当与一次属性过滤
4
+ * * 相当与一次属性过滤
5
5
  * @param source
6
6
  * @param classType
7
7
  */
@@ -75,3 +75,9 @@ export declare const arraySplit: <T = any>(datas: T[], { everyLength, groupCount
75
75
  everyLength?: number | undefined;
76
76
  groupCount?: number | undefined;
77
77
  }) => T[][];
78
+ export declare const P2C: (pro: string, IF?: boolean) => string;
79
+ export declare const C2P: (pro: string, IF?: boolean) => string;
80
+ export declare function C2P2<T extends Object = any, L extends Object = T>(datas: L[]): T[];
81
+ export declare function C2P2<T extends Object = any, L extends Object = T>(datas: L): T;
82
+ export declare function P2C2<T extends Object = any, L extends Object = T>(datas: L[]): T[];
83
+ export declare function P2C2<T extends Object = any, L extends Object = T>(datas: L): T;
package/cjs/object.js CHANGED
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.arraySplit = exports.array2map = exports.mixList = exports.mixArray = exports.fixEmptyPrototy = exports.coverComplexBean = exports.createBeanFromArray = exports.emptyBean = exports.convertBeans = exports.convertBean = exports.copyBean = void 0;
6
+ exports.C2P = exports.P2C = exports.arraySplit = exports.array2map = exports.mixList = exports.mixArray = exports.fixEmptyPrototy = exports.coverComplexBean = exports.createBeanFromArray = exports.emptyBean = exports.convertBeans = exports.convertBean = exports.copyBean = void 0;
7
+ exports.C2P2 = C2P2;
8
+ exports.P2C2 = P2C2;
9
+ const iterare_1 = __importDefault(require("iterare"));
4
10
  /**
5
11
  * 对象对象(等同与convertBean)
6
12
  * 仅会将classType有的属性进行转换
7
- * 相当与一次属性过滤
13
+ * * 相当与一次属性过滤
8
14
  * @param source
9
15
  * @param classType
10
16
  */
@@ -206,3 +212,31 @@ const arraySplit = (datas, { everyLength = 0, groupCount = 0 } = {}) => {
206
212
  }
207
213
  };
208
214
  exports.arraySplit = arraySplit;
215
+ const P2CEX = /[A-Z]/g;
216
+ const P2C = (pro, IF = true) => IF ? pro.replace(P2CEX, (a) => `_${a.toLowerCase()}`) : pro;
217
+ exports.P2C = P2C;
218
+ const C2PEX = /_([a-z])/g;
219
+ const C2P = (pro, IF = true) => IF ? pro.replace(C2PEX, (a, b) => `${b.toUpperCase()}`) : pro;
220
+ exports.C2P = C2P;
221
+ function C2P2(datas) {
222
+ if (datas instanceof Array) {
223
+ return (0, iterare_1.default)(datas).map((data) => Object.fromEntries(Object.entries(data).map(([K, V]) => [(0, exports.C2P)(K), V]))).toArray();
224
+ }
225
+ else if (datas) {
226
+ return Object.fromEntries(Object.entries(datas).map(([K, V]) => [(0, exports.C2P)(K), V]));
227
+ }
228
+ else {
229
+ return datas;
230
+ }
231
+ }
232
+ function P2C2(datas) {
233
+ if (datas instanceof Array) {
234
+ return (0, iterare_1.default)(datas).map((data) => Object.fromEntries(Object.entries(data).map(([K, V]) => [(0, exports.P2C)(K), V]))).toArray();
235
+ }
236
+ else if (datas) {
237
+ return Object.fromEntries(Object.entries(datas).map(([K, V]) => [(0, exports.P2C)(K), V]));
238
+ }
239
+ else {
240
+ return datas;
241
+ }
242
+ }