baja-lite 1.3.27 → 1.3.28
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.
- package/boot-remote.d.ts +2 -0
- package/{src/boot-remote.ts → boot-remote.js} +6 -7
- package/boot.d.ts +2 -0
- package/{src/boot.ts → boot.js} +31 -38
- package/code.d.ts +2 -0
- package/{src/code.ts → code.js} +71 -66
- package/convert-xml.d.ts +10 -0
- package/{src/convert-xml.ts → convert-xml.js} +105 -155
- package/enum.d.ts +18 -0
- package/enum.js +59 -0
- package/error.d.ts +5 -0
- package/error.js +13 -0
- package/fn.d.ts +128 -0
- package/fn.js +172 -0
- package/{src/index.ts → index.d.ts} +11 -12
- package/index.js +11 -0
- package/list.d.ts +10 -0
- package/{src/list.ts → list.js} +8 -9
- package/math.d.ts +83 -0
- package/math.js +451 -0
- package/object.d.ts +83 -0
- package/object.js +221 -0
- package/package.json +1 -1
- package/snowflake.d.ts +12 -0
- package/{src/snowflake.ts → snowflake.js} +33 -52
- package/sql.d.ts +1798 -0
- package/sql.js +4802 -0
- package/sqlite.d.ts +32 -0
- package/{src/sqlite.ts → sqlite.js} +53 -52
- package/string.d.ts +17 -0
- package/string.js +105 -0
- package/test-mysql.d.ts +2 -0
- package/test-mysql.js +109 -0
- package/test-postgresql.d.ts +2 -0
- package/{src/test-postgresql.ts → test-postgresql.js} +91 -80
- package/test-sqlite.d.ts +1 -0
- package/{src/test-sqlite.ts → test-sqlite.js} +90 -80
- package/test-xml.d.ts +1 -0
- package/{src/test-xml.ts → test-xml.js} +1 -1
- package/test.d.ts +1 -0
- package/{src/test.ts → test.js} +2 -3
- package/wx/base.d.ts +11 -0
- package/wx/base.js +78 -0
- package/wx/mini.d.ts +52 -0
- package/wx/mini.js +112 -0
- package/wx/organ.d.ts +65 -0
- package/wx/organ.js +171 -0
- package/{src/wx/types.ts → wx/types.d.ts} +21 -10
- package/wx/types.js +1 -0
- package/wx.js +3 -0
- package/.eslintignore +0 -7
- package/.eslintrc.cjs +0 -89
- package/.prettierrc +0 -4
- package/.vscode/settings.json +0 -8
- package/ci.js +0 -29
- package/package-cjs.json +0 -17
- package/src/enum.ts +0 -71
- package/src/error.ts +0 -11
- package/src/fn.ts +0 -295
- package/src/math.ts +0 -405
- package/src/object.ts +0 -247
- package/src/sql.ts +0 -5023
- package/src/string.ts +0 -111
- package/src/test-mysql.ts +0 -144
- package/src/wx/base.ts +0 -76
- package/src/wx/mini.ts +0 -147
- package/src/wx/organ.ts +0 -290
- package/tsconfig.cjs.json +0 -42
- package/tsconfig.json +0 -44
- package/tsconfig.tsbuildinfo +0 -1
- package/xml/event-report.xml +0 -13
- package/yarn.lock +0 -1757
- /package/{Readme.md → README.md} +0 -0
- /package/{src/wx.ts → wx.d.ts} +0 -0
package/src/object.ts
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import iterate from "iterare";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 对象对象(等同与convertBean)
|
|
5
|
-
* 仅会将classType有的属性进行转换
|
|
6
|
-
* * 相当与一次属性过滤
|
|
7
|
-
* @param source
|
|
8
|
-
* @param classType
|
|
9
|
-
*/
|
|
10
|
-
export const copyBean = <T>(source: any, classType: any): T => {
|
|
11
|
-
const result = {};
|
|
12
|
-
Object.keys(classType).forEach((key) => {
|
|
13
|
-
result[key] =
|
|
14
|
-
source[key] !== undefined ? source[key] : (result[key] = null);
|
|
15
|
-
});
|
|
16
|
-
return result as T;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 对象转换(等同与copyBean)
|
|
21
|
-
* 仅会将classType有的属性进行转换
|
|
22
|
-
* 相当与一次属性过滤
|
|
23
|
-
* @param source
|
|
24
|
-
* @param classType
|
|
25
|
-
*/
|
|
26
|
-
export const convertBean = copyBean;
|
|
27
|
-
/**
|
|
28
|
-
* 批量对象转换(等同与copyBean)
|
|
29
|
-
* 仅会将classType有的属性进行转换
|
|
30
|
-
* 相当与一次属性过滤
|
|
31
|
-
* @param source
|
|
32
|
-
* @param classType
|
|
33
|
-
*/
|
|
34
|
-
export const convertBeans = <T>(
|
|
35
|
-
source: any[],
|
|
36
|
-
classType: any,
|
|
37
|
-
cb?: (target: T, source: any) => void
|
|
38
|
-
): T[] => {
|
|
39
|
-
const result = new Array<T>();
|
|
40
|
-
for (const bean of source) {
|
|
41
|
-
const data = convertBean<T>(bean, classType);
|
|
42
|
-
if (cb) {
|
|
43
|
-
cb(data, bean);
|
|
44
|
-
}
|
|
45
|
-
result.push(data);
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* 创建一个空对象
|
|
51
|
-
* 其内各属性都是null
|
|
52
|
-
* @param classType
|
|
53
|
-
*/
|
|
54
|
-
export const emptyBean = <T>(classType: any): T => {
|
|
55
|
-
const target = {} as T;
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
57
|
-
Object.keys(classType).forEach((key) => {
|
|
58
|
-
target[key] = null;
|
|
59
|
-
});
|
|
60
|
-
return target;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 将一个json数组提取为一个json对象
|
|
65
|
-
* @param source 源数组
|
|
66
|
-
* @param key 作为新对象的key的字段
|
|
67
|
-
* @param value 作为新对象value的字段,不传则将自身为value
|
|
68
|
-
*/
|
|
69
|
-
export const createBeanFromArray = <F, T = F>(
|
|
70
|
-
source: F[],
|
|
71
|
-
key: keyof F,
|
|
72
|
-
value?: keyof F
|
|
73
|
-
): {
|
|
74
|
-
[name: string]: T;
|
|
75
|
-
} => {
|
|
76
|
-
const result: {
|
|
77
|
-
[name: string]: T;
|
|
78
|
-
} = {};
|
|
79
|
-
if (value) {
|
|
80
|
-
source.forEach((item) => {
|
|
81
|
-
if (item[key]) {
|
|
82
|
-
result[`${item[key]}`] = item[value] as unknown as T;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
} else {
|
|
86
|
-
source.forEach((item) => {
|
|
87
|
-
if (item[key]) {
|
|
88
|
-
result[`${item[key]}`] = item as unknown as T;
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
return result;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* 转换复合对象为指定bean
|
|
97
|
-
* @param source
|
|
98
|
-
* @param classType
|
|
99
|
-
*/
|
|
100
|
-
export const coverComplexBean = <T>(
|
|
101
|
-
source: any,
|
|
102
|
-
classType: any
|
|
103
|
-
): { data: T; array: { [key: string]: any[] } } => {
|
|
104
|
-
const result = {};
|
|
105
|
-
const arrayData = {};
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
107
|
-
for (const [key, value] of Object.entries(source)) {
|
|
108
|
-
if (value instanceof Array) {
|
|
109
|
-
arrayData[key] = value;
|
|
110
|
-
} else if (typeof value === 'object') {
|
|
111
|
-
Object.assign(result, value);
|
|
112
|
-
} else {
|
|
113
|
-
result[key] = value;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
data: convertBean<T>(result, classType),
|
|
118
|
-
array: arrayData
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* 将目标对象中为空的字段替换为source中对应key的值或者函数返回值
|
|
124
|
-
* @param target
|
|
125
|
-
* @param source
|
|
126
|
-
*/
|
|
127
|
-
export const fixEmptyPrototy = async (
|
|
128
|
-
target: any,
|
|
129
|
-
source: {
|
|
130
|
-
[key: string]: any;
|
|
131
|
-
}
|
|
132
|
-
) => {
|
|
133
|
-
for (const [key, fn] of Object.entries(source)) {
|
|
134
|
-
if (!target[key]) {
|
|
135
|
-
if (typeof fn === 'function') {
|
|
136
|
-
target[key] = await fn();
|
|
137
|
-
} else {
|
|
138
|
-
target[key] = fn;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
export const mixArray = <T>(array: T[], key: keyof T, defKey?: string): { [key: string]: number } => {
|
|
146
|
-
const obj = array.map(item => item[key]);
|
|
147
|
-
const result: { [k: string]: number } = {};
|
|
148
|
-
for (const i of obj) {
|
|
149
|
-
let ki = '';
|
|
150
|
-
if (i !== undefined && i !== null) {
|
|
151
|
-
ki = `${i}`;
|
|
152
|
-
} else if (defKey) {
|
|
153
|
-
ki = defKey;
|
|
154
|
-
}
|
|
155
|
-
if (!result[ki]) {
|
|
156
|
-
result[ki] = 0;
|
|
157
|
-
}
|
|
158
|
-
result[ki]!++;
|
|
159
|
-
}
|
|
160
|
-
return result;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
export const mixList = <T, V = T>(array: T[], key: keyof T, value?: keyof T, defKey?: string): { [key: string]: V[] } => {
|
|
164
|
-
const result: { [k: string]: V[] } = {};
|
|
165
|
-
for (const i of array) {
|
|
166
|
-
let ki = '';
|
|
167
|
-
if (i[key] !== undefined && i[key] !== null) {
|
|
168
|
-
ki = `${i[key]}`;
|
|
169
|
-
} else if (defKey) {
|
|
170
|
-
ki = defKey;
|
|
171
|
-
}
|
|
172
|
-
if (!result[ki]) {
|
|
173
|
-
result[ki] = [];
|
|
174
|
-
}
|
|
175
|
-
if (value) {
|
|
176
|
-
result[ki]!.push(i[value] as any);
|
|
177
|
-
} else {
|
|
178
|
-
result[ki]!.push(i as any);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return result;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export const array2map = <T = string | number>(array: string[], v: T): { [key: string]: T } => {
|
|
185
|
-
const ot: { [key: string]: T } = {};
|
|
186
|
-
for (const item of array) {
|
|
187
|
-
ot[item] = v;
|
|
188
|
-
}
|
|
189
|
-
return ot;
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* 数组分割
|
|
193
|
-
* @param datas
|
|
194
|
-
* @param config(二选一) everyLength=每组个数(最后一组可能不足次数), groupCount=拆分几组
|
|
195
|
-
* @returns T[][]
|
|
196
|
-
*/
|
|
197
|
-
export const arraySplit = <T = any>(datas: T[], { everyLength = 0, groupCount = 0 } = {}) => {
|
|
198
|
-
if (groupCount > 0) {
|
|
199
|
-
everyLength = Math.floor(datas.length / groupCount + 0.9);
|
|
200
|
-
const result: T[][] = [];
|
|
201
|
-
for (let i = 0; i < groupCount; i++) {
|
|
202
|
-
result.push(datas.slice(i * everyLength, (i + 1) * everyLength));
|
|
203
|
-
}
|
|
204
|
-
return result;
|
|
205
|
-
} else if (everyLength > 0) {
|
|
206
|
-
groupCount = Math.ceil(datas.length / everyLength);
|
|
207
|
-
const result: T[][] = [];
|
|
208
|
-
for (let i = 0; i < groupCount; i++) {
|
|
209
|
-
result.push(datas.slice(i * everyLength, (i + 1) * everyLength));
|
|
210
|
-
}
|
|
211
|
-
return result;
|
|
212
|
-
} else {
|
|
213
|
-
throw new Error('参数错误!');
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const P2CEX = /[A-Z]/g;
|
|
219
|
-
export const P2C = (pro: string, IF = true) => IF ? pro.replace(P2CEX, (a: string) => `_${a.toLowerCase()}`) : pro;
|
|
220
|
-
const C2PEX = /_([a-z])/g;
|
|
221
|
-
export const C2P = (pro: string, IF = true) => IF ? pro.replace(C2PEX, (a: string, b: string) => `${b.toUpperCase()}`) : pro;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
export function C2P2<T extends Object = any, L extends Object = T>(datas: L[]): T[];
|
|
225
|
-
export function C2P2<T extends Object = any, L extends Object = T>(datas: L): T;
|
|
226
|
-
export function C2P2<T extends Object = any, L extends Object = T>(datas: L | L[]): T | T[] {
|
|
227
|
-
if (datas instanceof Array) {
|
|
228
|
-
return iterate(datas).map((data: L) => Object.fromEntries<T>(Object.entries(data).map(([K, V]) => [C2P(K), V]))).toArray() as unknown as T[];
|
|
229
|
-
} else if (datas) {
|
|
230
|
-
return Object.fromEntries<T>(Object.entries(datas).map(([K, V]) => [C2P(K), V])) as unknown as T;
|
|
231
|
-
} else {
|
|
232
|
-
return datas;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export function P2C2<T extends Object = any, L extends Object = T>(datas: L[]): T[];
|
|
237
|
-
export function P2C2<T extends Object = any, L extends Object = T>(datas: L): T;
|
|
238
|
-
export function P2C2<T extends Object = any, L extends Object = T>(datas: L | L[]): T | T[] {
|
|
239
|
-
if (datas instanceof Array) {
|
|
240
|
-
return iterate(datas).map((data: L) => Object.fromEntries<T>(Object.entries(data).map(([K, V]) => [P2C(K), V]))).toArray() as unknown as T[];
|
|
241
|
-
} else if (datas) {
|
|
242
|
-
return Object.fromEntries<T>(Object.entries(datas).map(([K, V]) => [P2C(K), V])) as unknown as T;
|
|
243
|
-
} else {
|
|
244
|
-
return datas;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|