baja-lite 1.5.22 → 1.5.23

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 CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- [文档](https://deepwiki.com/void-soul/baja-lite)
2
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/void-soul/baja-lite)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.5.22",
3
+ "version": "1.5.23",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/baja-lite",
6
6
  "repository": {
package/sql.js CHANGED
@@ -1386,12 +1386,17 @@ class Build {
1386
1386
  }
1387
1387
  /**
1388
1388
  *
1389
- * beetween and
1390
- * etc.
1391
- * {{#between}} AND t.createtime | ({{createtime}}) {{/between}}
1392
- * createtime: 1,2
1393
- * ===
1394
- * AND t.createtime BETWEEN 1 AND 2
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
- const xx = b.split(',');
1405
- return `'${xx[0]}' AND '${xx[1]}'`;
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 '';