baja-lite 1.1.3 → 1.1.4

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 (76) hide show
  1. package/.eslintignore +7 -0
  2. package/.eslintrc.cjs +89 -0
  3. package/.prettierrc +4 -0
  4. package/ci.js +29 -0
  5. package/package-cjs.json +17 -0
  6. package/package.json +6 -6
  7. package/{boot-remote.js → src/boot-remote.ts} +7 -6
  8. package/{boot.js → src/boot.ts} +39 -32
  9. package/{code.js → src/code.ts} +67 -64
  10. package/{convert-xml.js → src/convert-xml.ts} +155 -105
  11. package/src/enum.ts +71 -0
  12. package/src/error.ts +11 -0
  13. package/src/fn.ts +295 -0
  14. package/{index.d.ts → src/index.ts} +11 -11
  15. package/{list.js → src/list.ts} +9 -8
  16. package/src/math.ts +405 -0
  17. package/src/object.ts +247 -0
  18. package/src/set-ex.ts +374 -0
  19. package/src/sql.ts +5281 -0
  20. package/{sqlite.js → src/sqlite.ts} +52 -53
  21. package/src/string.ts +111 -0
  22. package/{test-mysql.js → src/test-mysql.ts} +126 -135
  23. package/src/test-postgresql.ts +79 -0
  24. package/{test-sqlite.js → src/test-sqlite.ts} +80 -89
  25. package/{test-xml.js → src/test-xml.ts} +1 -1
  26. package/src/test.ts +2 -0
  27. package/src/wx/base.ts +76 -0
  28. package/src/wx/mini.ts +133 -0
  29. package/src/wx/organ.ts +290 -0
  30. package/{wx/types.d.ts → src/wx/types.ts} +10 -21
  31. package/test.json +0 -0
  32. package/tsconfig.base.json +80 -0
  33. package/tsconfig.cjs.json +42 -0
  34. package/tsconfig.json +44 -0
  35. package/xml/event-report.xml +13 -0
  36. package/yarn.lock +1493 -0
  37. package/boot-remote.d.ts +0 -2
  38. package/boot.d.ts +0 -2
  39. package/code.d.ts +0 -2
  40. package/convert-xml.d.ts +0 -10
  41. package/enum.d.ts +0 -18
  42. package/enum.js +0 -59
  43. package/error.d.ts +0 -5
  44. package/error.js +0 -13
  45. package/fn.d.ts +0 -128
  46. package/fn.js +0 -172
  47. package/index.js +0 -11
  48. package/list.d.ts +0 -10
  49. package/math.d.ts +0 -83
  50. package/math.js +0 -451
  51. package/object.d.ts +0 -83
  52. package/object.js +0 -222
  53. package/set-ex.d.ts +0 -198
  54. package/set-ex.js +0 -338
  55. package/sql.d.ts +0 -1858
  56. package/sql.js +0 -5025
  57. package/sqlite.d.ts +0 -32
  58. package/string.d.ts +0 -17
  59. package/string.js +0 -105
  60. package/test-mysql.d.ts +0 -2
  61. package/test-postgresql.d.ts +0 -2
  62. package/test-postgresql.js +0 -90
  63. package/test-sqlite.d.ts +0 -1
  64. package/test-xml.d.ts +0 -1
  65. package/test.d.ts +0 -1
  66. package/test.js +0 -2
  67. package/wx/base.d.ts +0 -11
  68. package/wx/base.js +0 -78
  69. package/wx/mini.d.ts +0 -45
  70. package/wx/mini.js +0 -102
  71. package/wx/organ.d.ts +0 -65
  72. package/wx/organ.js +0 -171
  73. package/wx/types.js +0 -1
  74. package/wx.js +0 -3
  75. /package/{README.md → Readme.md} +0 -0
  76. /package/{wx.d.ts → src/wx.ts} +0 -0
package/object.js DELETED
@@ -1,222 +0,0 @@
1
- import iterate from "iterare";
2
- /**
3
- * 对象对象(等同与convertBean)
4
- * 仅会将classType有的属性进行转换
5
- * * 相当与一次属性过滤
6
- * @param source
7
- * @param classType
8
- */
9
- export const copyBean = (source, classType) => {
10
- const result = {};
11
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
12
- Object.keys(classType).forEach((key) => {
13
- result[key] =
14
- source[key] !== undefined ? source[key] : (result[key] = null);
15
- });
16
- return result;
17
- };
18
- /**
19
- * 对象转换(等同与copyBean)
20
- * 仅会将classType有的属性进行转换
21
- * 相当与一次属性过滤
22
- * @param source
23
- * @param classType
24
- */
25
- export const convertBean = copyBean;
26
- /**
27
- * 批量对象转换(等同与copyBean)
28
- * 仅会将classType有的属性进行转换
29
- * 相当与一次属性过滤
30
- * @param source
31
- * @param classType
32
- */
33
- export const convertBeans = (source, classType, cb) => {
34
- const result = new Array();
35
- for (const bean of source) {
36
- const data = convertBean(bean, classType);
37
- if (cb) {
38
- cb(data, bean);
39
- }
40
- result.push(data);
41
- }
42
- return result;
43
- };
44
- /**
45
- * 创建一个空对象
46
- * 其内各属性都是null
47
- * @param classType
48
- */
49
- export const emptyBean = (classType) => {
50
- const target = {};
51
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
52
- Object.keys(classType).forEach((key) => {
53
- target[key] = null;
54
- });
55
- return target;
56
- };
57
- /**
58
- * 将一个json数组提取为一个json对象
59
- * @param source 源数组
60
- * @param key 作为新对象的key的字段
61
- * @param value 作为新对象value的字段,不传则将自身为value
62
- */
63
- export const createBeanFromArray = (source, key, value) => {
64
- const result = {};
65
- if (value) {
66
- source.forEach((item) => {
67
- if (item[key]) {
68
- result[`${item[key]}`] = item[value];
69
- }
70
- });
71
- }
72
- else {
73
- source.forEach((item) => {
74
- if (item[key]) {
75
- result[`${item[key]}`] = item;
76
- }
77
- });
78
- }
79
- return result;
80
- };
81
- /**
82
- * 转换复合对象为指定bean
83
- * @param source
84
- * @param classType
85
- */
86
- export const coverComplexBean = (source, classType) => {
87
- const result = {};
88
- const arrayData = {};
89
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
90
- for (const [key, value] of Object.entries(source)) {
91
- if (value instanceof Array) {
92
- arrayData[key] = value;
93
- }
94
- else if (typeof value === 'object') {
95
- Object.assign(result, value);
96
- }
97
- else {
98
- result[key] = value;
99
- }
100
- }
101
- return {
102
- data: convertBean(result, classType),
103
- array: arrayData
104
- };
105
- };
106
- /**
107
- * 将目标对象中为空的字段替换为source中对应key的值或者函数返回值
108
- * @param target
109
- * @param source
110
- */
111
- export const fixEmptyPrototy = async (target, source) => {
112
- for (const [key, fn] of Object.entries(source)) {
113
- if (!target[key]) {
114
- if (typeof fn === 'function') {
115
- target[key] = await fn();
116
- }
117
- else {
118
- target[key] = fn;
119
- }
120
- }
121
- }
122
- };
123
- export const mixArray = (array, key, defKey) => {
124
- const obj = array.map(item => item[key]);
125
- const result = {};
126
- for (const i of obj) {
127
- let ki = '';
128
- if (i !== undefined && i !== null) {
129
- ki = `${i}`;
130
- }
131
- else if (defKey) {
132
- ki = defKey;
133
- }
134
- if (!result[ki]) {
135
- result[ki] = 0;
136
- }
137
- result[ki]++;
138
- }
139
- return result;
140
- };
141
- export const mixList = (array, key, value, defKey) => {
142
- const result = {};
143
- for (const i of array) {
144
- let ki = '';
145
- if (i[key] !== undefined && i[key] !== null) {
146
- ki = `${i[key]}`;
147
- }
148
- else if (defKey) {
149
- ki = defKey;
150
- }
151
- if (!result[ki]) {
152
- result[ki] = [];
153
- }
154
- if (value) {
155
- result[ki].push(i[value]);
156
- }
157
- else {
158
- result[ki].push(i);
159
- }
160
- }
161
- return result;
162
- };
163
- export const array2map = (array, v) => {
164
- const ot = {};
165
- for (const item of array) {
166
- ot[item] = v;
167
- }
168
- return ot;
169
- };
170
- /**
171
- * 数组分割
172
- * @param datas
173
- * @param config(二选一) everyLength=每组个数(最后一组可能不足次数), groupCount=拆分几组
174
- * @returns T[][]
175
- */
176
- export const arraySplit = (datas, { everyLength = 0, groupCount = 0 } = {}) => {
177
- if (groupCount > 0) {
178
- everyLength = Math.floor(datas.length / groupCount + 0.9);
179
- const result = [];
180
- for (let i = 0; i < groupCount; i++) {
181
- result.push(datas.slice(i * everyLength, (i + 1) * everyLength));
182
- }
183
- return result;
184
- }
185
- else if (everyLength > 0) {
186
- groupCount = Math.ceil(datas.length / everyLength);
187
- const result = [];
188
- for (let i = 0; i < groupCount; i++) {
189
- result.push(datas.slice(i * everyLength, (i + 1) * everyLength));
190
- }
191
- return result;
192
- }
193
- else {
194
- throw new Error('参数错误!');
195
- }
196
- };
197
- const P2CEX = /[A-Z]/g;
198
- export const P2C = (pro, IF = true) => IF ? pro.replace(P2CEX, (a) => `_${a.toLowerCase()}`) : pro;
199
- const C2PEX = /_([a-z])/g;
200
- export const C2P = (pro, IF = true) => IF ? pro.replace(C2PEX, (a, b) => `${b.toUpperCase()}`) : pro;
201
- export function C2P2(datas) {
202
- if (datas instanceof Array) {
203
- return iterate(datas).map((data) => Object.fromEntries(Object.entries(data).map(([K, V]) => [C2P(K), V]))).toArray();
204
- }
205
- else if (datas) {
206
- return Object.fromEntries(Object.entries(datas).map(([K, V]) => [C2P(K), V]));
207
- }
208
- else {
209
- return datas;
210
- }
211
- }
212
- export function P2C2(datas) {
213
- if (datas instanceof Array) {
214
- return iterate(datas).map((data) => Object.fromEntries(Object.entries(data).map(([K, V]) => [P2C(K), V]))).toArray();
215
- }
216
- else if (datas) {
217
- return Object.fromEntries(Object.entries(datas).map(([K, V]) => [P2C(K), V]));
218
- }
219
- else {
220
- return datas;
221
- }
222
- }
package/set-ex.d.ts DELETED
@@ -1,198 +0,0 @@
1
- export declare class SetEx<T> extends Set {
2
- private _key;
3
- private _onExist1?;
4
- private _onNotExist1?;
5
- private _replaceIfExits1;
6
- private _onExist2?;
7
- private _onNotExist2?;
8
- private _replaceIfExits2;
9
- private _map;
10
- /**
11
- * @param key 识别是否存在的对象的属性名
12
- * @param onExist 当存在时作何操作? oldData/newData 哪个将添加到set,由replaceItemWhenExits决定,默认是oldData生效
13
- * @param onNotExist 当不存在时作何操作?
14
- * @param replaceWhenExits 当存在时是否覆盖?
15
- * @param values 初始数组
16
- */
17
- constructor(option: {
18
- key: keyof T;
19
- /** add&addAll触发 */
20
- onExist1?: (oldData: T, newData: T) => void;
21
- /** add&addAll触发 */
22
- onNotExist1?: (newData: T) => void;
23
- /** add&addAll触发 */
24
- replaceIfExits1?: boolean;
25
- /** add2&addAll2触发 */
26
- onExist2?: (oldData: T, newData: T) => void;
27
- /** add2&addAll2触发 */
28
- onNotExist2?: (newData: T) => void;
29
- /** add2&addAll2触发 */
30
- replaceIfExits2?: boolean;
31
- values?: ReadonlyArray<T> | null;
32
- });
33
- /**
34
- *
35
- * 添加返回
36
- * @param {T} value
37
- * @returns {this} 当前对象
38
- */
39
- add(value: T): this;
40
- /**
41
- * 批量添加
42
- * @param values
43
- * @returns 当前对象
44
- */
45
- addAll(...values: T[]): this;
46
- /**
47
- *
48
- * 添加
49
- * @param {T} value
50
- * @returns {T} 添加成功的对象:可能是新加入集合的,也可能是原本存在的
51
- */
52
- add2(value: T): T;
53
- /**
54
- *
55
- * 添加并返回添加成功的对象:可能是新加入集合的,也可能是原本存在的
56
- * @param {T} values
57
- * @returns {T}
58
- */
59
- addAll2(values: T[]): T[];
60
- /**
61
- * 用key找到匹配的第一个对象
62
- * @param {*} key 这是对象的关键属性,而非对象
63
- * @returns {(T | null)}
64
- */
65
- find(key: T[keyof T]): T | null;
66
- /**
67
- * 用key找到匹配的所有对象
68
- * @param {*} key 这是对象的关键属性,而非对象
69
- * @returns {T[]}
70
- */
71
- findAll(key: T[keyof T]): T[];
72
- /**
73
- *
74
- * 用函数回调找到匹配的第一个对象
75
- * @param {(item: T) => boolean} fn
76
- * @returns {T[]}
77
- */
78
- filter(fn: (item: T) => boolean): T | null;
79
- /**
80
- *
81
- * 用函数回调找到匹配的所有对象
82
- * @param {(item: T) => boolean} fn
83
- * @returns {T[]}
84
- */
85
- filterAll(fn: (item: T) => boolean): T[];
86
- /**
87
- *
88
- * 是否存在key对应的对象
89
- * @param {*} value 这是对象的关键属性,而非对象
90
- * @returns {boolean}
91
- */
92
- has(key: T[keyof T]): boolean;
93
- /**
94
- * 转为数组
95
- * @param param0
96
- * @returns
97
- */
98
- toArray({ sort, each, filter, map }?: {
99
- sort?: (a: T, b: T) => number;
100
- each?: (a: T) => void;
101
- filter?: (a: T) => boolean;
102
- map?: (a: T) => T;
103
- }): T[];
104
- /**
105
- * 转为JSON对象
106
- * @param key
107
- * @param value
108
- * @param param2
109
- * @returns
110
- */
111
- toJSON<L = T>(key: keyof T, value?: keyof T, { sort, each, filter, map }?: {
112
- sort?: (a: T, b: T) => number;
113
- each?: (a: T) => void;
114
- filter?: (a: T) => boolean;
115
- map?: (a: T) => T;
116
- }): {
117
- [k: string]: L;
118
- };
119
- /**
120
- *
121
- * 删除key对应的对象
122
- * @param {*} _key 这是对象的关键属性,而非对象
123
- * @returns {boolean}
124
- */
125
- delete(_key: T[keyof T]): boolean;
126
- /**
127
- *
128
- * 重置
129
- * @param {keyof T} key
130
- * @param {(oldData: T, newData: T) => void} [onExist]
131
- * @param {boolean} [replaceWhenExits=false]
132
- */
133
- reset(option: {
134
- key?: keyof T;
135
- /** add&addAll触发 */
136
- onExist1?: (oldData: T, newData: T) => void;
137
- /** add&addAll触发 */
138
- onNotExist1?: (newData: T) => void;
139
- /** add&addAll触发 */
140
- replaceIfExits1?: boolean;
141
- /** add2&addAll2触发 */
142
- onExist2?: (oldData: T, newData: T) => void;
143
- /** add2&addAll2触发 */
144
- onNotExist2?: (newData: T) => void;
145
- /** add2&addAll2触发 */
146
- replaceIfExits2?: boolean;
147
- values?: ReadonlyArray<T> | null;
148
- }): this;
149
- /**
150
- *
151
- * @param param0 转为JSON对象,value可能是数组
152
- * @returns
153
- */
154
- toJSONArray({ sort, each, filter, map }?: {
155
- sort?: (a: T, b: T) => number;
156
- each?: (a: T) => void;
157
- filter?: (a: T) => boolean;
158
- map?: (a: T) => T;
159
- }): {
160
- [k: string]: T[keyof T][];
161
- };
162
- /**
163
- * 转为hot-table支持的数组
164
- * @param param0
165
- * @param keys
166
- * @returns
167
- */
168
- toDataGrid({ sort, each, filter, map }?: {
169
- sort?: (a: T, b: T) => number;
170
- each?: (a: T) => void;
171
- filter?: (a: T) => boolean;
172
- map?: (a: T) => T;
173
- }, ...keys: (keyof T)[]): (keyof T | T[keyof T])[][];
174
- /**
175
- * 转为饼图支持的数组
176
- * @param param0
177
- * @param keys
178
- * @returns
179
- */
180
- toPieGrid({ sort, each, filter, map }?: {
181
- sort?: (a: T, b: T) => number;
182
- each?: (a: T) => void;
183
- filter?: (a: T) => boolean;
184
- map?: (a: T) => T;
185
- }, ...keys: (keyof T)[]): {
186
- [k: string]: {
187
- value: T[keyof T];
188
- name: T[keyof T];
189
- }[];
190
- };
191
- set onExist1(onExist1: ((oldData: T, newData: T) => void) | undefined);
192
- set onExist2(onExist2: ((oldData: T, newData: T) => void) | undefined);
193
- set onNotExist1(onNotExist1: ((newData: T) => void) | undefined);
194
- set onNotExist2(onNotExist2: ((newData: T) => void) | undefined);
195
- set replaceIfExits1(replaceIfExits1: boolean);
196
- set replaceIfExits2(replaceIfExits2: boolean);
197
- set key(key: keyof T);
198
- }