baja-lite 1.5.22 → 1.5.24
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/README.md +1 -1
- package/event.d.ts +10 -0
- package/event.js +38 -0
- package/object.d.ts +6 -0
- package/object.js +18 -0
- package/package.json +1 -1
- package/sql.js +18 -8
package/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
|
|
2
|
-
[
|
|
2
|
+
[](https://deepwiki.com/void-soul/baja-lite)
|
package/event.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type EventParams = readonly unknown[];
|
|
2
|
+
type EventHandler<T extends EventParams> = (...args: T) => void;
|
|
3
|
+
export declare class EventBus<T extends Record<string, EventParams>> {
|
|
4
|
+
private readonly all;
|
|
5
|
+
on<K extends keyof T>(type: K, handler: EventHandler<T[K]>): this;
|
|
6
|
+
once<K extends keyof T>(type: K, handler: EventHandler<T[K]>): this;
|
|
7
|
+
off<K extends keyof T>(type: K, handler?: EventHandler<T[K]>): this;
|
|
8
|
+
emit<K extends keyof T>(type: K, ...args: T[K]): this;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
package/event.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class EventBus {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.all = new Map();
|
|
4
|
+
}
|
|
5
|
+
on(type, handler) {
|
|
6
|
+
let list = this.all.get(type);
|
|
7
|
+
if (!list)
|
|
8
|
+
this.all.set(type, (list = []));
|
|
9
|
+
list.push(handler);
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
once(type, handler) {
|
|
13
|
+
const wrapper = (...args) => {
|
|
14
|
+
handler(...args);
|
|
15
|
+
this.off(type, wrapper);
|
|
16
|
+
};
|
|
17
|
+
return this.on(type, wrapper);
|
|
18
|
+
}
|
|
19
|
+
off(type, handler) {
|
|
20
|
+
const list = this.all.get(type);
|
|
21
|
+
if (!list)
|
|
22
|
+
return this;
|
|
23
|
+
if (handler) {
|
|
24
|
+
const idx = list.indexOf(handler);
|
|
25
|
+
if (idx !== -1)
|
|
26
|
+
list.splice(idx, 1);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.all.delete(type);
|
|
30
|
+
}
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
emit(type, ...args) {
|
|
34
|
+
const list = this.all.get(type);
|
|
35
|
+
list?.slice().forEach(fn => fn(...args));
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/object.d.ts
CHANGED
|
@@ -111,6 +111,12 @@ export declare const arraySplit: <T = any>(datas: T[], { everyLength, groupCount
|
|
|
111
111
|
* @returns
|
|
112
112
|
*/
|
|
113
113
|
export declare const assginObject: <T extends Object>(source: T, ...os: T[]) => void;
|
|
114
|
+
/**
|
|
115
|
+
* 去除数组中重复数据,同时可以通过each函数为每个数据执行某项操作
|
|
116
|
+
* @param source
|
|
117
|
+
* @param each
|
|
118
|
+
*/
|
|
119
|
+
export declare const distinctArray: <T extends Object>(source: T[], keys: (keyof T)[], each?: (data: T) => void) => T[];
|
|
114
120
|
export declare const P2C: (pro: string, IF?: boolean) => string;
|
|
115
121
|
export declare const C2P: (pro: string, IF?: boolean) => string;
|
|
116
122
|
export declare function C2P2<T extends Object = any, L extends Object = T>(datas: L[], hump?: boolean, convert?: Record<string, (data: any) => any>): T[];
|
package/object.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SetEx } from 'baja-lite-field';
|
|
1
2
|
import * as ite from 'iterare';
|
|
2
3
|
const iterate = ite.iterate;
|
|
3
4
|
/**
|
|
@@ -246,6 +247,23 @@ export const arraySplit = (datas, { everyLength = 0, groupCount = 0 } = {}) => {
|
|
|
246
247
|
export const assginObject = (source, ...os) => {
|
|
247
248
|
os.forEach(o => Object.entries(o).forEach(([key, value]) => value !== null && value !== undefined && `${value}`.trim() !== '' && (source[key] = value)));
|
|
248
249
|
};
|
|
250
|
+
/**
|
|
251
|
+
* 去除数组中重复数据,同时可以通过each函数为每个数据执行某项操作
|
|
252
|
+
* @param source
|
|
253
|
+
* @param each
|
|
254
|
+
*/
|
|
255
|
+
export const distinctArray = (source, keys, each) => {
|
|
256
|
+
const set = new SetEx({ key: '___id' });
|
|
257
|
+
for (const item of source) {
|
|
258
|
+
const _item = item;
|
|
259
|
+
_item.___id = keys.map(key => item[key]).join('_');
|
|
260
|
+
if (each) {
|
|
261
|
+
each(item);
|
|
262
|
+
}
|
|
263
|
+
set.add(_item);
|
|
264
|
+
}
|
|
265
|
+
return set.toArray();
|
|
266
|
+
};
|
|
249
267
|
const P2CEX = /[A-Z]/g;
|
|
250
268
|
export const P2C = (pro, IF = true) => (IF ? pro.replace(P2CEX, (a) => `_${a.toLowerCase()}`) : pro);
|
|
251
269
|
const C2PEX = /_([a-z])/g;
|
package/package.json
CHANGED
package/sql.js
CHANGED
|
@@ -1386,12 +1386,17 @@ class Build {
|
|
|
1386
1386
|
}
|
|
1387
1387
|
/**
|
|
1388
1388
|
*
|
|
1389
|
-
* beetween and
|
|
1390
|
-
* etc.
|
|
1391
|
-
*
|
|
1392
|
-
* createtime
|
|
1393
|
-
*
|
|
1394
|
-
*
|
|
1389
|
+
* # beetween and
|
|
1390
|
+
* ## etc.
|
|
1391
|
+
* ```
|
|
1392
|
+
* {{#between}} AND t.createtime ({{createtime}}) {{/between}}
|
|
1393
|
+
* // 其中:
|
|
1394
|
+
* createtime = '1,2'
|
|
1395
|
+
* // 或者
|
|
1396
|
+
* createtime = ['1', '2']
|
|
1397
|
+
* // 将生成:
|
|
1398
|
+
* AND t.createtime BETWEEN '1' AND '2'
|
|
1399
|
+
* ```
|
|
1395
1400
|
* @returns
|
|
1396
1401
|
* @memberof Build
|
|
1397
1402
|
*/
|
|
@@ -1401,8 +1406,13 @@ class Build {
|
|
|
1401
1406
|
if (/\(([\w\W]+)\)/.exec(result)) {
|
|
1402
1407
|
return render(text).replace(/\(([\w\W]+)\)/, (a, b) => {
|
|
1403
1408
|
if (a && b) {
|
|
1404
|
-
|
|
1405
|
-
|
|
1409
|
+
if (typeof b === 'string') {
|
|
1410
|
+
const xx = b.split(',');
|
|
1411
|
+
return ` BETWEEN '${xx[0]}' AND '${xx[1]}'`;
|
|
1412
|
+
}
|
|
1413
|
+
else {
|
|
1414
|
+
return ` BETWEEN '${b[0]}' AND '${b[1]}'`;
|
|
1415
|
+
}
|
|
1406
1416
|
}
|
|
1407
1417
|
else {
|
|
1408
1418
|
return '';
|