baja-lite 1.0.4 → 1.0.5

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 (74) 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 +345 -1
  7. package/cjs/convert-xml.d.ts +10 -0
  8. package/cjs/convert-xml.js +413 -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/index.d.ts +2 -0
  13. package/cjs/index.js +2 -0
  14. package/cjs/object.d.ts +7 -1
  15. package/cjs/object.js +36 -2
  16. package/cjs/sql.d.ts +405 -148
  17. package/cjs/sql.js +1229 -861
  18. package/cjs/sqlite.d.ts +38 -0
  19. package/cjs/sqlite.js +194 -0
  20. package/cjs/test-mysql.d.ts +1 -1
  21. package/cjs/test-mysql.js +72 -63
  22. package/cjs/test-sqlite.d.ts +1 -1
  23. package/cjs/test-sqlite.js +3 -1
  24. package/cjs/test-xml.d.ts +1 -0
  25. package/cjs/test-xml.js +75 -0
  26. package/es/boot-remote.d.ts +2 -0
  27. package/es/boot-remote.js +31 -0
  28. package/es/boot.d.ts +2 -0
  29. package/es/boot.js +125 -0
  30. package/es/code.d.ts +1 -0
  31. package/es/code.js +341 -2
  32. package/es/convert-xml.d.ts +10 -0
  33. package/es/convert-xml.js +409 -0
  34. package/es/enum.d.ts +10 -0
  35. package/es/enum.js +28 -0
  36. package/es/error.js +1 -1
  37. package/es/index.d.ts +2 -0
  38. package/es/index.js +2 -0
  39. package/es/object.d.ts +7 -1
  40. package/es/object.js +28 -1
  41. package/es/sql.d.ts +405 -148
  42. package/es/sql.js +1099 -735
  43. package/es/sqlite.d.ts +38 -0
  44. package/es/sqlite.js +164 -0
  45. package/es/test-mysql.d.ts +1 -1
  46. package/es/test-mysql.js +72 -63
  47. package/es/test-sqlite.d.ts +1 -1
  48. package/es/test-sqlite.js +3 -1
  49. package/es/test-xml.d.ts +1 -0
  50. package/es/test-xml.js +70 -0
  51. package/package.json +10 -7
  52. package/src/boot-remote.ts +31 -0
  53. package/src/boot.ts +129 -0
  54. package/src/code.ts +326 -1
  55. package/src/convert-xml.ts +461 -0
  56. package/src/enum.ts +31 -0
  57. package/src/error.ts +1 -1
  58. package/src/index.ts +3 -1
  59. package/src/object.ts +47 -14
  60. package/src/sql.ts +1145 -787
  61. package/src/sqlite.ts +161 -0
  62. package/src/test-mysql.ts +72 -63
  63. package/src/test-sqlite.ts +3 -1
  64. package/src/test-xml.ts +70 -0
  65. package/cjs/constant.d.ts +0 -13
  66. package/cjs/constant.js +0 -19
  67. package/cjs/redis.d.ts +0 -0
  68. package/cjs/redis.js +0 -1
  69. package/es/constant.d.ts +0 -13
  70. package/es/constant.js +0 -16
  71. package/es/redis.d.ts +0 -0
  72. package/es/redis.js +0 -1
  73. package/src/constant.ts +0 -14
  74. package/src/redis.ts +0 -0
@@ -0,0 +1,413 @@
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
+ evalString = evalString.replace(/==/g, '===');
132
+ evalString = evalString.replace(/!=/g, '!==');
133
+ evalString = evalString.replace(/^'(.*?)'\.equalsIgnoreCase\( ([a-zA-Z]+\.[a-zA-Z]+) \)/i, `($2 && $2.toUpperCase() === '$1'.toUpperCase())`);
134
+ evalString = evalString.replace(/\('(.*?)'\.equalsIgnoreCase\( ([a-zA-Z]+\.[a-zA-Z]+) \)/i, `(($2 && $2.toUpperCase() === '$1'.toUpperCase())`);
135
+ }
136
+ catch (err) {
137
+ throw new Error('Error occurred during convert <if> element.');
138
+ }
139
+ // Execute Evaluate string
140
+ try {
141
+ if (eval(evalString)) {
142
+ let convertString = '';
143
+ for (let i = 0, nextChildren; nextChildren = children['children'][i]; i++) {
144
+ convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
145
+ }
146
+ return convertString;
147
+ }
148
+ else {
149
+ return '';
150
+ }
151
+ }
152
+ catch (e) {
153
+ return '';
154
+ }
155
+ };
156
+ const convertForeach = function (children, param, parentIds, myBatisMapper) {
157
+ try {
158
+ const collection = eval('param.' + children.attrs['collection']);
159
+ const item = children.attrs['item'];
160
+ const open = (children.attrs['open'] == null) ? '' : children.attrs['open'];
161
+ const close = (children.attrs['close'] == null) ? '' : children.attrs['close'];
162
+ const separator = (children.attrs['separator'] == null) ? '' : children.attrs['separator'];
163
+ const foreachTexts = [];
164
+ let coll = null;
165
+ for (let j = 0; j < collection.length; j++) {
166
+ coll = collection[j];
167
+ const foreachParam = param;
168
+ foreachParam[item] = coll;
169
+ let foreachText = '';
170
+ for (let k = 0, nextChildren; nextChildren = children.children[k]; k++) {
171
+ let fText = convertChildren(nextChildren, foreachParam, parentIds, myBatisMapper);
172
+ fText = fText.replace(/^\s*$/g, '');
173
+ if (fText != null && fText.length > 0) {
174
+ foreachText += fText;
175
+ }
176
+ }
177
+ if (foreachText != null && foreachText.length > 0) {
178
+ foreachTexts.push(foreachText);
179
+ }
180
+ }
181
+ return (open + foreachTexts.join(separator) + close);
182
+ }
183
+ catch (err) {
184
+ throw new Error('Error occurred during convert <foreach> element.');
185
+ }
186
+ };
187
+ const convertChoose = function (children, param, parentIds, myBatisMapper) {
188
+ try {
189
+ for (let i = 0, whenChildren; whenChildren = children.children[i]; i++) {
190
+ if (whenChildren.type == 'tag' && whenChildren.name.toLowerCase() == 'when') {
191
+ let evalString = whenChildren.attrs.test;
192
+ // Create Evaluate string
193
+ evalString = replaceEvalString(evalString, param);
194
+ evalString = evalString.replace(/ and /gi, ' && ');
195
+ evalString = evalString.replace(/ or /gi, ' || ');
196
+ // Execute Evaluate string
197
+ try {
198
+ if (eval(evalString)) {
199
+ // If <when> condition is true, do it.
200
+ let convertString = '';
201
+ for (let k = 0, nextChildren; nextChildren = whenChildren.children[k]; k++) {
202
+ convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
203
+ }
204
+ return convertString;
205
+ }
206
+ else {
207
+ continue;
208
+ }
209
+ }
210
+ catch (e) {
211
+ continue;
212
+ }
213
+ }
214
+ else if (whenChildren.type == 'tag' && whenChildren.name.toLowerCase() == 'otherwise') {
215
+ // If reached <otherwise> tag, do it.
216
+ let convertString = '';
217
+ for (let k = 0, nextChildren; nextChildren = whenChildren.children[k]; k++) {
218
+ convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
219
+ }
220
+ return convertString;
221
+ }
222
+ }
223
+ // If there is no suitable when and otherwise, just return null.
224
+ return '';
225
+ }
226
+ catch (err) {
227
+ throw new Error('Error occurred during convert <choose> element.');
228
+ }
229
+ };
230
+ const convertTrimWhere = function (children, param, parentIds, myBatisMapper) {
231
+ let convertString = '';
232
+ let prefix;
233
+ let prefixOverrides;
234
+ let suffix;
235
+ let suffixOverrides;
236
+ let globalSet;
237
+ try {
238
+ switch (children.name.toLowerCase()) {
239
+ case 'trim':
240
+ prefix = children.attrs["prefix"];
241
+ prefixOverrides = children.attrs["prefixOverrides"];
242
+ suffix = children.attrs["suffix"];
243
+ suffixOverrides = children.attrs["suffixOverrides"];
244
+ globalSet = 'g';
245
+ break;
246
+ case 'where':
247
+ prefix = 'WHERE';
248
+ prefixOverrides = 'and|or';
249
+ globalSet = 'gi';
250
+ break;
251
+ default:
252
+ throw new Error('Error occurred during convert <trim/where> element.');
253
+ }
254
+ // Convert children first.
255
+ for (let j = 0, nextChildren; nextChildren = children.children[j]; j++) {
256
+ convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
257
+ }
258
+ // Remove prefixOverrides
259
+ let trimRegex = new RegExp('(^)([\\s]*?)(' + prefixOverrides + ')', globalSet);
260
+ convertString = convertString.replace(trimRegex, '');
261
+ // Remove suffixOverrides
262
+ trimRegex = new RegExp('(' + suffixOverrides + ')([\\s]*?)($)', globalSet);
263
+ convertString = convertString.replace(trimRegex, '');
264
+ if (children.name.toLowerCase() != 'trim') {
265
+ trimRegex = new RegExp('(' + prefixOverrides + ')([\\s]*?)($)', globalSet);
266
+ convertString = convertString.replace(trimRegex, '');
267
+ }
268
+ // Add Prefix if String is not empty.
269
+ trimRegex = new RegExp('([a-zA-Z])', 'g');
270
+ const w = convertString.match(trimRegex);
271
+ if (w != null && w.length > 0) {
272
+ convertString = prefix + ' ' + convertString;
273
+ if (suffix) {
274
+ convertString = convertString + ' ' + suffix;
275
+ }
276
+ }
277
+ // Remove comma(,) before WHERE
278
+ if (children.name.toLowerCase() != 'where') {
279
+ const regex = new RegExp('(,)([\\s]*?)(where)', 'gi');
280
+ convertString = convertString.replace(regex, ' WHERE ');
281
+ }
282
+ return convertString;
283
+ }
284
+ catch (err) {
285
+ throw new Error('Error occurred during convert <' + children.name.toLowerCase() + '> element.');
286
+ }
287
+ };
288
+ const convertSet = function (children, param, parentIds, myBatisMapper) {
289
+ let convertString = '';
290
+ try {
291
+ // Convert children first.
292
+ for (let j = 0, nextChildren; nextChildren = children.children[j]; j++) {
293
+ convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
294
+ }
295
+ // Remove comma repeated more than 2.
296
+ let regex = new RegExp('(,)(,|\\s){2,}', 'g');
297
+ convertString = convertString.replace(regex, ',\n');
298
+ // Remove first comma if exists.
299
+ regex = new RegExp('(^)([\\s]*?)(,)', 'g');
300
+ convertString = convertString.replace(regex, '');
301
+ // Remove last comma if exists.
302
+ regex = new RegExp('(,)([\\s]*?)($)', 'g');
303
+ convertString = convertString.replace(regex, '');
304
+ convertString = ' SET ' + convertString;
305
+ return convertString;
306
+ }
307
+ catch (err) {
308
+ throw new Error('Error occurred during convert <set> element.');
309
+ }
310
+ };
311
+ const convertBind = function (children, param) {
312
+ let evalString = children.attrs["value"];
313
+ // Create Evaluate string
314
+ evalString = replaceEvalString(evalString, param);
315
+ param[children.attrs["name"]] = eval(evalString);
316
+ return param;
317
+ };
318
+ const convertInclude = function (children, param, parentIds, myBatisMapper) {
319
+ try {
320
+ // Add Properties to param
321
+ for (let j = 0, nextChildren; nextChildren = children.children[j]; j++) {
322
+ if (nextChildren.type == 'tag' && nextChildren.name == 'property') {
323
+ param[nextChildren.attrs['name']] = nextChildren.attrs['value'];
324
+ }
325
+ }
326
+ }
327
+ catch (err) {
328
+ throw new Error('Error occurred during read <property> element in <include> element.');
329
+ }
330
+ try {
331
+ let refid = convertParametersInner('#', children.attrs['refid'], param);
332
+ refid = convertParametersInner('$', refid, param);
333
+ let mapper;
334
+ for (const psqlid of parentIds) {
335
+ mapper = myBatisMapper[`${psqlid}.${refid}`];
336
+ if (mapper) {
337
+ break;
338
+ }
339
+ }
340
+ let statement = '';
341
+ for (let i = 0, children; children = mapper[i]; i++) {
342
+ statement += convertChildren(children, param, parentIds, myBatisMapper);
343
+ }
344
+ return statement;
345
+ }
346
+ catch (err) {
347
+ throw new Error('Error occurred during convert refid attribute in <include> element.');
348
+ }
349
+ };
350
+ const isDict = function (v) {
351
+ return typeof v === 'object' && v !== null && !(v instanceof Array) && !(v instanceof Date);
352
+ };
353
+ const replaceEvalString = function (evalString, param) {
354
+ const keys = Object.keys(param);
355
+ for (let i = 0; i < keys.length; i++) {
356
+ let replacePrefix = '';
357
+ let replacePostfix = '';
358
+ let paramRegex;
359
+ if (isDict(param[keys[i]])) {
360
+ replacePrefix = ' param.';
361
+ replacePostfix = '';
362
+ paramRegex = new RegExp('(^|[^a-zA-Z0-9_])(' + keys[i] + '\\.)([a-zA-Z0-9_]+)', 'g');
363
+ }
364
+ else {
365
+ replacePrefix = ' param.';
366
+ replacePostfix = ' ';
367
+ paramRegex = new RegExp('(^|[^a-zA-Z0-9_])(' + keys[i] + ')($|[^a-zA-Z0-9_])', 'g');
368
+ }
369
+ evalString = evalString.replace(paramRegex, ('$1' + replacePrefix + '$2' + replacePostfix + '$3'));
370
+ }
371
+ return evalString;
372
+ };
373
+ const uniqueArray = function (a) {
374
+ const seen = {};
375
+ const out = [];
376
+ const len = a.length;
377
+ let j = 0;
378
+ for (let i = 0; i < len; i++) {
379
+ const item = a[i];
380
+ if (seen[item] !== 1) {
381
+ seen[item] = 1;
382
+ out[j++] = item;
383
+ }
384
+ }
385
+ return out;
386
+ };
387
+ const mysqlRealEscapeParam = function (param) {
388
+ if (typeof param != 'string')
389
+ return param;
390
+ return param.replace(/[\0\x08\x09\x1a\n\r''\\\%]/g, function (char) {
391
+ switch (char) {
392
+ case '\0':
393
+ return '\\0';
394
+ case '\x08':
395
+ return '\\b';
396
+ case '\x09':
397
+ return '\\t';
398
+ case '\x1a':
399
+ return '\\z';
400
+ case '\n':
401
+ return '\\n';
402
+ case '\r':
403
+ return '\\r';
404
+ case '\'':
405
+ case `'`:
406
+ case '\\':
407
+ case '%':
408
+ return '\\' + char;
409
+ default:
410
+ return char;
411
+ }
412
+ });
413
+ };
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/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,4 @@ export * from './object';
5
6
  export * from './set-ex';
6
7
  export * from './sql';
7
8
  export * from './string';
9
+ export * from './enum';
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,4 @@ __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);
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,14 @@
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.P2C2 = exports.C2P2 = 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
+ const iterare_1 = __importDefault(require("iterare"));
4
8
  /**
5
9
  * 对象对象(等同与convertBean)
6
10
  * 仅会将classType有的属性进行转换
7
- * 相当与一次属性过滤
11
+ * * 相当与一次属性过滤
8
12
  * @param source
9
13
  * @param classType
10
14
  */
@@ -206,3 +210,33 @@ const arraySplit = (datas, { everyLength = 0, groupCount = 0 } = {}) => {
206
210
  }
207
211
  };
208
212
  exports.arraySplit = arraySplit;
213
+ const P2CEX = /[A-Z]/g;
214
+ const P2C = (pro, IF = true) => IF ? pro.replace(P2CEX, (a) => `_${a.toLowerCase()}`) : pro;
215
+ exports.P2C = P2C;
216
+ const C2PEX = /_([a-z])/g;
217
+ const C2P = (pro, IF = true) => IF ? pro.replace(C2PEX, (a, b) => `_${b.toUpperCase()}`) : pro;
218
+ exports.C2P = C2P;
219
+ function C2P2(datas) {
220
+ if (datas instanceof Array) {
221
+ return (0, iterare_1.default)(datas).map((data) => Object.fromEntries(Object.entries(data).map(([K, V]) => [(0, exports.C2P)(K), V]))).toArray();
222
+ }
223
+ else if (datas) {
224
+ return Object.fromEntries(Object.entries(datas).map(([K, V]) => [(0, exports.C2P)(K), V]));
225
+ }
226
+ else {
227
+ return datas;
228
+ }
229
+ }
230
+ exports.C2P2 = C2P2;
231
+ function P2C2(datas) {
232
+ if (datas instanceof Array) {
233
+ return (0, iterare_1.default)(datas).map((data) => Object.fromEntries(Object.entries(data).map(([K, V]) => [(0, exports.P2C)(K), V]))).toArray();
234
+ }
235
+ else if (datas) {
236
+ return Object.fromEntries(Object.entries(datas).map(([K, V]) => [(0, exports.P2C)(K), V]));
237
+ }
238
+ else {
239
+ return datas;
240
+ }
241
+ }
242
+ exports.P2C2 = P2C2;