@fast-china/utils 1.0.17 → 1.0.19

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.
@@ -8,9 +8,23 @@ var FastUtils = function(exports, vue) {
8
8
  * @returns
9
9
  */
10
10
  hasDuplicateProperty(arr, prop) {
11
- const values2 = arr.map((obj) => obj[prop]);
12
- const uniqueValues = new Set(values2);
13
- return values2.length !== uniqueValues.size;
11
+ if (Array.isArray(prop)) {
12
+ const seen = /* @__PURE__ */ new Set();
13
+ for (const obj of arr) {
14
+ const key = JSON.stringify(prop.map((p) => obj[p]));
15
+ if (seen.has(key)) return true;
16
+ seen.add(key);
17
+ }
18
+ return false;
19
+ } else {
20
+ const seen = /* @__PURE__ */ new Set();
21
+ for (const obj of arr) {
22
+ const value = obj[prop];
23
+ if (seen.has(value)) return true;
24
+ seen.add(value);
25
+ }
26
+ return false;
27
+ }
14
28
  },
15
29
  /**
16
30
  * 是否存在非重复值
@@ -19,11 +33,17 @@ var FastUtils = function(exports, vue) {
19
33
  * @returns
20
34
  */
21
35
  hasDifferentProperty(arr, prop) {
22
- const valueSet = /* @__PURE__ */ new Set();
23
- for (const obj of arr) {
24
- valueSet.add(obj[prop]);
25
- if (valueSet.size > 1) {
26
- return true;
36
+ if (arr.length <= 1) return false;
37
+ if (Array.isArray(prop)) {
38
+ const firstKey = JSON.stringify(prop.map((p) => arr[0][p]));
39
+ for (let i = 1; i < arr.length; i++) {
40
+ const currentKey = JSON.stringify(prop.map((p) => arr[i][p]));
41
+ if (currentKey !== firstKey) return true;
42
+ }
43
+ } else {
44
+ const firstValue = arr[0][prop];
45
+ for (let i = 1; i < arr.length; i++) {
46
+ if (arr[i][prop] !== firstValue) return true;
27
47
  }
28
48
  }
29
49
  return false;