@pawover/kit 0.0.0-alpha.17 → 0.0.0-alpha.18

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/dist/index.d.ts CHANGED
@@ -2,6 +2,12 @@ import { Class, NonEmptyObject, Replace, SetOptional, UnionToTuple, ValueOf } fr
2
2
  import { assign } from "radashi";
3
3
 
4
4
  //#region src/utils/array/arrayCast.d.ts
5
+
6
+ /**
7
+ * 构造数组
8
+ * @param candidate 待构造项
9
+ * @param checkEmpty 是否检查 `undefined` 和 `null`
10
+ */
5
11
  declare function arrayCast<T>(candidate: T | T[], checkEmpty?: boolean): T[];
6
12
  //#endregion
7
13
  //#region src/utils/array/arrayCompete.d.ts
@@ -24,8 +30,15 @@ declare function arrayCompete<T>(initialList: readonly T[], match: (a: T, b: T)
24
30
  */
25
31
  declare function arrayCounting<T, K extends PropertyKey>(initialList: readonly T[], match: (row: T) => K): Record<string, number>;
26
32
  //#endregion
27
- //#region src/utils/array/arrayDiff.d.ts
28
- declare function arrayDiff<T>(initialList: readonly T[], diffList: readonly T[], match: (row: T) => PropertyKey): T[];
33
+ //#region src/utils/array/arrayDifference.d.ts
34
+ /**
35
+ * 求数组差集
36
+ *
37
+ * @param initialList 初始数组
38
+ * @param diffList 对比数组
39
+ * @param match 匹配函数
40
+ */
41
+ declare function arrayDifference<T>(initialList: readonly T[], diffList: readonly T[], match?: (row: T) => unknown): T[];
29
42
  //#endregion
30
43
  //#region src/utils/array/arrayFirst.d.ts
31
44
  /**
@@ -46,6 +59,16 @@ declare function arrayFirst<T>(initialList: readonly T[], saveValue?: T): T | un
46
59
  */
47
60
  declare function arrayFork<T>(initialList: readonly T[], match: (item: T) => boolean): [T[], T[]];
48
61
  //#endregion
62
+ //#region src/utils/array/arrayIntersection.d.ts
63
+ /**
64
+ * 求数组交集
65
+ *
66
+ * @param initialList 初始数组
67
+ * @param diffList 对比数组
68
+ * @param match 匹配函数
69
+ */
70
+ declare function arrayIntersection<T>(initialList: readonly T[], diffList: readonly T[], match?: (row: T) => unknown): T[];
71
+ //#endregion
49
72
  //#region src/utils/array/arrayLast.d.ts
50
73
  /**
51
74
  * 获取数组最后一项
@@ -64,7 +87,7 @@ declare function arrayLast<T>(initialList: readonly T[], saveValue?: T): T | und
64
87
  * @param mergeList 待合并数组
65
88
  * @param match 匹配函数
66
89
  */
67
- declare function arrayMerge<T>(initialList: readonly T[], mergeList: readonly T[], match: (item: T) => unknown): T[];
90
+ declare function arrayMerge<T>(initialList: readonly T[], mergeList: readonly T[], match?: (item: T) => unknown): T[];
68
91
  //#endregion
69
92
  //#region src/utils/array/arrayPick.d.ts
70
93
  /**
@@ -385,4 +408,4 @@ declare const prototypeStrings: {
385
408
  };
386
409
  declare function resolvePrototypeString(value: unknown): string;
387
410
  //#endregion
388
- export { arrayCast, arrayCompete, arrayCounting, arrayDiff, arrayFirst, arrayFork, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isArray, isAsyncFunction, isBigInt, isBoolean, isClass, isDate, isEqual, isError, isFile, isFunction, isGeneratorFunction, isInteger, isIterable, isMap, isNull, isNumber, isObject, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, prototypeStrings, resolvePrototypeString, rowsToTree, stringInitialCase, stringReplace, stringToJson, stringToValues, to, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
411
+ export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isArray, isAsyncFunction, isBigInt, isBoolean, isClass, isDate, isEqual, isError, isFile, isFunction, isGeneratorFunction, isInteger, isIterable, isMap, isNull, isNumber, isObject, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, prototypeStrings, resolvePrototypeString, rowsToTree, stringInitialCase, stringReplace, stringToJson, stringToValues, to, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
package/dist/index.js CHANGED
@@ -227,6 +227,11 @@ function isWindow(value) {
227
227
 
228
228
  //#endregion
229
229
  //#region src/utils/array/arrayCast.ts
230
+ /**
231
+ * 构造数组
232
+ * @param candidate 待构造项
233
+ * @param checkEmpty 是否检查 `undefined` 和 `null`
234
+ */
230
235
  function arrayCast(candidate, checkEmpty = true) {
231
236
  if (checkEmpty && (isUndefined(candidate) || isNull(candidate))) return [];
232
237
  return isArray(candidate) ? [...candidate] : [candidate];
@@ -265,17 +270,27 @@ function arrayCounting(initialList, match) {
265
270
  }
266
271
 
267
272
  //#endregion
268
- //#region src/utils/array/arrayDiff.ts
269
- function arrayDiff(initialList, diffList, match) {
273
+ //#region src/utils/array/arrayDifference.ts
274
+ /**
275
+ * 求数组差集
276
+ *
277
+ * @param initialList 初始数组
278
+ * @param diffList 对比数组
279
+ * @param match 匹配函数
280
+ */
281
+ function arrayDifference(initialList, diffList, match) {
270
282
  if (!isArray(initialList) && !isArray(diffList)) return [];
271
283
  if (!isArray(initialList) || !initialList.length) return [...diffList];
272
284
  if (!isArray(diffList) || !diffList.length) return [...initialList];
273
- if (!isFunction(match)) return [];
274
- const keys = diffList.reduce((prev, curr) => {
275
- prev[match(curr)] = true;
276
- return prev;
277
- }, {});
278
- return initialList.filter((a) => !keys[match(a)]);
285
+ if (!isFunction(match)) {
286
+ const arraySet = new Set(diffList);
287
+ return Array.from(new Set(initialList.filter((item) => !arraySet.has(item))));
288
+ }
289
+ const map = /* @__PURE__ */ new Map();
290
+ diffList.forEach((item) => {
291
+ map.set(match(item), true);
292
+ });
293
+ return initialList.filter((a) => !map.get(match(a)));
279
294
  }
280
295
 
281
296
  //#endregion
@@ -306,6 +321,30 @@ function arrayFork(initialList, match) {
306
321
  return forked;
307
322
  }
308
323
 
324
+ //#endregion
325
+ //#region src/utils/array/arrayIntersection.ts
326
+ /**
327
+ * 求数组交集
328
+ *
329
+ * @param initialList 初始数组
330
+ * @param diffList 对比数组
331
+ * @param match 匹配函数
332
+ */
333
+ function arrayIntersection(initialList, diffList, match) {
334
+ if (!isArray(initialList) && !isArray(diffList)) return [];
335
+ if (!isArray(initialList) || !initialList.length) return [...diffList];
336
+ if (!isArray(diffList) || !diffList.length) return [...initialList];
337
+ if (!isFunction(match)) {
338
+ const arraySet = new Set(diffList);
339
+ return Array.from(new Set(initialList.filter((item) => arraySet.has(item))));
340
+ }
341
+ const map = /* @__PURE__ */ new Map();
342
+ diffList.forEach((item) => {
343
+ map.set(match(item), true);
344
+ });
345
+ return initialList.filter((a) => map.get(match(a)));
346
+ }
347
+
309
348
  //#endregion
310
349
  //#region src/utils/array/arrayLast.ts
311
350
  /**
@@ -332,7 +371,7 @@ function arrayLast(initialList, saveValue) {
332
371
  function arrayMerge(initialList, mergeList, match) {
333
372
  if (!isArray(initialList)) return [];
334
373
  if (!isArray(mergeList)) return [...initialList];
335
- if (!isFunction(match)) return [...initialList];
374
+ if (!isFunction(match)) return Array.from(new Set([...initialList, ...mergeList]));
336
375
  const keys = /* @__PURE__ */ new Map();
337
376
  for (const item of mergeList) keys.set(match(item), item);
338
377
  return initialList.map((prevItem) => {
@@ -1133,4 +1172,4 @@ function treeToRows(tree, options = {}) {
1133
1172
  }
1134
1173
 
1135
1174
  //#endregion
1136
- export { arrayCast, arrayCompete, arrayCounting, arrayDiff, arrayFirst, arrayFork, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isArray, isAsyncFunction, isBigInt, isBoolean, isClass, isDate, isEqual, isError, isFile, isFunction, isGeneratorFunction, isInteger, isIterable, isMap, isNull, isNumber, isObject, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, prototypeStrings, resolvePrototypeString, rowsToTree, stringInitialCase, stringReplace, stringToJson, stringToValues, to, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
1175
+ export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isArray, isAsyncFunction, isBigInt, isBoolean, isClass, isDate, isEqual, isError, isFile, isFunction, isGeneratorFunction, isInteger, isIterable, isMap, isNull, isNumber, isObject, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, prototypeStrings, resolvePrototypeString, rowsToTree, stringInitialCase, stringReplace, stringToJson, stringToValues, to, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
package/metadata.json CHANGED
@@ -3,9 +3,10 @@
3
3
  "arrayCast",
4
4
  "arrayCompete",
5
5
  "arrayCounting",
6
- "arrayDiff",
6
+ "arrayDifference",
7
7
  "arrayFirst",
8
8
  "arrayFork",
9
+ "arrayIntersection",
9
10
  "arrayLast",
10
11
  "arrayMerge",
11
12
  "arrayPick",
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "description": "pawover's kit",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "version": "0.0.0-alpha.17",
7
+ "version": "0.0.0-alpha.18",
8
8
  "packageManager": "pnpm@10.20.0",
9
9
  "engines": {
10
10
  "node": ">=22.20.0"