@fast-china/utils 1.0.17 → 1.0.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.
@@ -8,12 +8,12 @@ export declare const arrayUtil: {
8
8
  * @param prop 属性
9
9
  * @returns
10
10
  */
11
- hasDuplicateProperty<T>(arr: T[], prop: keyof T): boolean;
11
+ hasDuplicateProperty<T>(arr: T[], prop: keyof T | (keyof T)[]): boolean;
12
12
  /**
13
13
  * 是否存在非重复值
14
14
  * @param arr 数组
15
15
  * @param prop 属性
16
16
  * @returns
17
17
  */
18
- hasDifferentProperty<T>(arr: T[], prop: keyof T): boolean;
18
+ hasDifferentProperty<T>(arr: T[], prop: keyof T | (keyof T)[]): boolean;
19
19
  };
@@ -6,9 +6,23 @@ const arrayUtil = {
6
6
  * @returns
7
7
  */
8
8
  hasDuplicateProperty(arr, prop) {
9
- const values = arr.map((obj) => obj[prop]);
10
- const uniqueValues = new Set(values);
11
- return values.length !== uniqueValues.size;
9
+ if (Array.isArray(prop)) {
10
+ const seen = /* @__PURE__ */ new Set();
11
+ for (const obj of arr) {
12
+ const key = JSON.stringify(prop.map((p) => obj[p]));
13
+ if (seen.has(key)) return true;
14
+ seen.add(key);
15
+ }
16
+ return false;
17
+ } else {
18
+ const seen = /* @__PURE__ */ new Set();
19
+ for (const obj of arr) {
20
+ const value = obj[prop];
21
+ if (seen.has(value)) return true;
22
+ seen.add(value);
23
+ }
24
+ return false;
25
+ }
12
26
  },
13
27
  /**
14
28
  * 是否存在非重复值
@@ -17,11 +31,17 @@ const arrayUtil = {
17
31
  * @returns
18
32
  */
19
33
  hasDifferentProperty(arr, prop) {
20
- const valueSet = /* @__PURE__ */ new Set();
21
- for (const obj of arr) {
22
- valueSet.add(obj[prop]);
23
- if (valueSet.size > 1) {
24
- return true;
34
+ if (arr.length <= 1) return false;
35
+ if (Array.isArray(prop)) {
36
+ const firstKey = JSON.stringify(prop.map((p) => arr[0][p]));
37
+ for (let i = 1; i < arr.length; i++) {
38
+ const currentKey = JSON.stringify(prop.map((p) => arr[i][p]));
39
+ if (currentKey !== firstKey) return true;
40
+ }
41
+ } else {
42
+ const firstValue = arr[0][prop];
43
+ for (let i = 1; i < arr.length; i++) {
44
+ if (arr[i][prop] !== firstValue) return true;
25
45
  }
26
46
  }
27
47
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/array/index.ts"],"sourcesContent":["/**\n * 数据工具类\n */\nexport const arrayUtil = {\n\t/**\n\t * 是否存在重复值\n\t * @param arr 数组\n\t * @param prop 属性\n\t * @returns\n\t */\n\thasDuplicateProperty<T>(arr: T[], prop: keyof T): boolean {\n\t\tconst values = arr.map((obj) => obj[prop]);\n\t\tconst uniqueValues = new Set(values);\n\t\treturn values.length !== uniqueValues.size;\n\t},\n\t/**\n\t * 是否存在非重复值\n\t * @param arr 数组\n\t * @param prop 属性\n\t * @returns\n\t */\n\thasDifferentProperty<T>(arr: T[], prop: keyof T): boolean {\n\t\tconst valueSet = new Set<any>();\n\t\tfor (const obj of arr) {\n\t\t\tvalueSet.add(obj[prop]);\n\t\t\tif (valueSet.size > 1) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t},\n};\n"],"names":[],"mappings":"AAGO,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOxB,qBAAwB,KAAU,MAAwB;AACzD,UAAM,SAAS,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC;AACnC,UAAA,eAAe,IAAI,IAAI,MAAM;AAC5B,WAAA,OAAO,WAAW,aAAa;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAAwB,KAAU,MAAwB;AACnD,UAAA,+BAAe,IAAS;AAC9B,eAAW,OAAO,KAAK;AACb,eAAA,IAAI,IAAI,IAAI,CAAC;AAClB,UAAA,SAAS,OAAO,GAAG;AACf,eAAA;AAAA,MAAA;AAAA,IACR;AAEM,WAAA;AAAA,EAAA;AAET;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/array/index.ts"],"sourcesContent":["/**\n * 数据工具类\n */\nexport const arrayUtil = {\n\t/**\n\t * 是否存在重复值\n\t * @param arr 数组\n\t * @param prop 属性\n\t * @returns\n\t */\n\thasDuplicateProperty<T>(arr: T[], prop: keyof T | (keyof T)[]): boolean {\n\t\tif (Array.isArray(prop)) {\n\t\t\tconst seen = new Set<string>();\n\t\t\tfor (const obj of arr) {\n\t\t\t\tconst key = JSON.stringify(prop.map((p) => obj[p]));\n\t\t\t\tif (seen.has(key)) return true;\n\t\t\t\tseen.add(key);\n\t\t\t}\n\t\t\treturn false;\n\t\t} else {\n\t\t\tconst seen = new Set<any>();\n\t\t\tfor (const obj of arr) {\n\t\t\t\tconst value = obj[prop];\n\t\t\t\tif (seen.has(value)) return true;\n\t\t\t\tseen.add(value);\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t},\n\t/**\n\t * 是否存在非重复值\n\t * @param arr 数组\n\t * @param prop 属性\n\t * @returns\n\t */\n\thasDifferentProperty<T>(arr: T[], prop: keyof T | (keyof T)[]): boolean {\n\t\tif (arr.length <= 1) return false;\n\n\t\tif (Array.isArray(prop)) {\n\t\t\tconst firstKey = JSON.stringify(prop.map((p) => arr[0][p]));\n\t\t\tfor (let i = 1; i < arr.length; i++) {\n\t\t\t\tconst currentKey = JSON.stringify(prop.map((p) => arr[i][p]));\n\t\t\t\tif (currentKey !== firstKey) return true;\n\t\t\t}\n\t\t} else {\n\t\t\tconst firstValue = arr[0][prop];\n\t\t\tfor (let i = 1; i < arr.length; i++) {\n\t\t\t\tif (arr[i][prop] !== firstValue) return true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t},\n};\n"],"names":[],"mappings":"AAGO,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOxB,qBAAwB,KAAU,MAAsC;AACnE,QAAA,MAAM,QAAQ,IAAI,GAAG;AAClB,YAAA,2BAAW,IAAY;AAC7B,iBAAW,OAAO,KAAK;AAChB,cAAA,MAAM,KAAK,UAAU,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;AAClD,YAAI,KAAK,IAAI,GAAG,EAAU,QAAA;AAC1B,aAAK,IAAI,GAAG;AAAA,MAAA;AAEN,aAAA;AAAA,IAAA,OACD;AACA,YAAA,2BAAW,IAAS;AAC1B,iBAAW,OAAO,KAAK;AAChB,cAAA,QAAQ,IAAI,IAAI;AACtB,YAAI,KAAK,IAAI,KAAK,EAAU,QAAA;AAC5B,aAAK,IAAI,KAAK;AAAA,MAAA;AAER,aAAA;AAAA,IAAA;AAAA,EAET;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAAwB,KAAU,MAAsC;AACnE,QAAA,IAAI,UAAU,EAAU,QAAA;AAExB,QAAA,MAAM,QAAQ,IAAI,GAAG;AACxB,YAAM,WAAW,KAAK,UAAU,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1D,eAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACpC,cAAM,aAAa,KAAK,UAAU,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AACxD,YAAA,eAAe,SAAiB,QAAA;AAAA,MAAA;AAAA,IACrC,OACM;AACN,YAAM,aAAa,IAAI,CAAC,EAAE,IAAI;AAC9B,eAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACpC,YAAI,IAAI,CAAC,EAAE,IAAI,MAAM,WAAmB,QAAA;AAAA,MAAA;AAAA,IACzC;AAEM,WAAA;AAAA,EAAA;AAET;"}
@@ -8,12 +8,12 @@ export declare const arrayUtil: {
8
8
  * @param prop 属性
9
9
  * @returns
10
10
  */
11
- hasDuplicateProperty<T>(arr: T[], prop: keyof T): boolean;
11
+ hasDuplicateProperty<T>(arr: T[], prop: keyof T | (keyof T)[]): boolean;
12
12
  /**
13
13
  * 是否存在非重复值
14
14
  * @param arr 数组
15
15
  * @param prop 属性
16
16
  * @returns
17
17
  */
18
- hasDifferentProperty<T>(arr: T[], prop: keyof T): boolean;
18
+ hasDifferentProperty<T>(arr: T[], prop: keyof T | (keyof T)[]): boolean;
19
19
  };
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={hasDuplicateProperty(e,t){const r=e.map((e=>e[t])),o=new Set(r);return r.length!==o.size},hasDifferentProperty(e,t){const r=new Set;for(const o of e)if(r.add(o[t]),r.size>1)return!0;return!1}};exports.arrayUtil=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r={hasDuplicateProperty(r,t){if(Array.isArray(t)){const e=new Set;for(const n of r){const r=JSON.stringify(t.map((r=>n[r])));if(e.has(r))return!0;e.add(r)}return!1}{const e=new Set;for(const n of r){const r=n[t];if(e.has(r))return!0;e.add(r)}return!1}},hasDifferentProperty(r,t){if(r.length<=1)return!1;if(Array.isArray(t)){const e=JSON.stringify(t.map((t=>r[0][t])));for(let n=1;n<r.length;n++){if(JSON.stringify(t.map((t=>r[n][t])))!==e)return!0}}else{const e=r[0][t];for(let n=1;n<r.length;n++)if(r[n][t]!==e)return!0}return!1}};exports.arrayUtil=r;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/array/index.ts"],"sourcesContent":["/**\n * 数据工具类\n */\nexport const arrayUtil = {\n\t/**\n\t * 是否存在重复值\n\t * @param arr 数组\n\t * @param prop 属性\n\t * @returns\n\t */\n\thasDuplicateProperty<T>(arr: T[], prop: keyof T): boolean {\n\t\tconst values = arr.map((obj) => obj[prop]);\n\t\tconst uniqueValues = new Set(values);\n\t\treturn values.length !== uniqueValues.size;\n\t},\n\t/**\n\t * 是否存在非重复值\n\t * @param arr 数组\n\t * @param prop 属性\n\t * @returns\n\t */\n\thasDifferentProperty<T>(arr: T[], prop: keyof T): boolean {\n\t\tconst valueSet = new Set<any>();\n\t\tfor (const obj of arr) {\n\t\t\tvalueSet.add(obj[prop]);\n\t\t\tif (valueSet.size > 1) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t},\n};\n"],"names":["arrayUtil","hasDuplicateProperty","arr","prop","values","map","obj","uniqueValues","Set","length","size","hasDifferentProperty","valueSet","add"],"mappings":"gFAGO,MAAMA,EAAY,CAOxB,oBAAAC,CAAwBC,EAAUC,GACjC,MAAMC,EAASF,EAAIG,KAAKC,GAAQA,EAAIH,KAC9BI,EAAe,IAAIC,IAAIJ,GACtB,OAAAA,EAAOK,SAAWF,EAAaG,IACvC,EAOA,oBAAAC,CAAwBT,EAAUC,GAC3B,MAAAS,MAAeJ,IACrB,IAAA,MAAWF,KAAOJ,EAEb,GADKU,EAAAC,IAAIP,EAAIH,IACbS,EAASF,KAAO,EACZ,OAAA,EAGF,OAAA,CAAA"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/array/index.ts"],"sourcesContent":["/**\n * 数据工具类\n */\nexport const arrayUtil = {\n\t/**\n\t * 是否存在重复值\n\t * @param arr 数组\n\t * @param prop 属性\n\t * @returns\n\t */\n\thasDuplicateProperty<T>(arr: T[], prop: keyof T | (keyof T)[]): boolean {\n\t\tif (Array.isArray(prop)) {\n\t\t\tconst seen = new Set<string>();\n\t\t\tfor (const obj of arr) {\n\t\t\t\tconst key = JSON.stringify(prop.map((p) => obj[p]));\n\t\t\t\tif (seen.has(key)) return true;\n\t\t\t\tseen.add(key);\n\t\t\t}\n\t\t\treturn false;\n\t\t} else {\n\t\t\tconst seen = new Set<any>();\n\t\t\tfor (const obj of arr) {\n\t\t\t\tconst value = obj[prop];\n\t\t\t\tif (seen.has(value)) return true;\n\t\t\t\tseen.add(value);\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t},\n\t/**\n\t * 是否存在非重复值\n\t * @param arr 数组\n\t * @param prop 属性\n\t * @returns\n\t */\n\thasDifferentProperty<T>(arr: T[], prop: keyof T | (keyof T)[]): boolean {\n\t\tif (arr.length <= 1) return false;\n\n\t\tif (Array.isArray(prop)) {\n\t\t\tconst firstKey = JSON.stringify(prop.map((p) => arr[0][p]));\n\t\t\tfor (let i = 1; i < arr.length; i++) {\n\t\t\t\tconst currentKey = JSON.stringify(prop.map((p) => arr[i][p]));\n\t\t\t\tif (currentKey !== firstKey) return true;\n\t\t\t}\n\t\t} else {\n\t\t\tconst firstValue = arr[0][prop];\n\t\t\tfor (let i = 1; i < arr.length; i++) {\n\t\t\t\tif (arr[i][prop] !== firstValue) return true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t},\n};\n"],"names":["arrayUtil","hasDuplicateProperty","arr","prop","Array","isArray","seen","Set","obj","key","JSON","stringify","map","p","has","add","value","hasDifferentProperty","length","firstKey","i","firstValue"],"mappings":"gFAGO,MAAMA,EAAY,CAOxB,oBAAAC,CAAwBC,EAAUC,GAC7B,GAAAC,MAAMC,QAAQF,GAAO,CAClB,MAAAG,MAAWC,IACjB,IAAA,MAAWC,KAAON,EAAK,CAChB,MAAAO,EAAMC,KAAKC,UAAUR,EAAKS,KAAKC,GAAML,EAAIK,MAC/C,GAAIP,EAAKQ,IAAIL,GAAa,OAAA,EAC1BH,EAAKS,IAAIN,EAAG,CAEN,OAAA,CAAA,CACD,CACA,MAAAH,MAAWC,IACjB,IAAA,MAAWC,KAAON,EAAK,CAChB,MAAAc,EAAQR,EAAIL,GAClB,GAAIG,EAAKQ,IAAIE,GAAe,OAAA,EAC5BV,EAAKS,IAAIC,EAAK,CAER,OAAA,CAAA,CAET,EAOA,oBAAAC,CAAwBf,EAAUC,GAC7B,GAAAD,EAAIgB,QAAU,EAAU,OAAA,EAExB,GAAAd,MAAMC,QAAQF,GAAO,CACxB,MAAMgB,EAAWT,KAAKC,UAAUR,EAAKS,KAAKC,GAAMX,EAAI,GAAGW,MACvD,IAAA,IAASO,EAAI,EAAGA,EAAIlB,EAAIgB,OAAQE,IAAK,CAEhC,GADeV,KAAKC,UAAUR,EAAKS,KAAKC,GAAMX,EAAIkB,GAAGP,QACtCM,EAAiB,OAAA,CAAA,CACrC,KACM,CACN,MAAME,EAAanB,EAAI,GAAGC,GAC1B,IAAA,IAASiB,EAAI,EAAGA,EAAIlB,EAAIgB,OAAQE,IAC/B,GAAIlB,EAAIkB,GAAGjB,KAAUkB,EAAmB,OAAA,CACzC,CAEM,OAAA,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fast-china/utils",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "Fast 工具库.",
5
5
  "type": "module",
6
6
  "keywords": [