@yh-kit/utils 1.2.1 → 1.2.2

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/utils.js CHANGED
@@ -1,13 +1,13 @@
1
- const n = (e) => {
1
+ const o = (e) => {
2
2
  if (!e || !e.length) return {};
3
- const r = {};
4
- return e.forEach((t) => {
5
- const o = Object.assign({ label: t.label, text: t.label }, t);
6
- r[t == null ? void 0 : t.value] = o;
7
- }), r;
3
+ const t = {};
4
+ return e.forEach((r) => {
5
+ const n = Object.assign({ label: r.label, text: r.label }, r);
6
+ t[r == null ? void 0 : r.value] = n;
7
+ }), t;
8
8
  }, s = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
9
9
  __proto__: null,
10
- toEnumObj: n
10
+ toEnumObj: o
11
11
  }, Symbol.toStringTag, { value: "Module" })), d = {
12
12
  ...s,
13
13
  /**
@@ -22,8 +22,8 @@ const n = (e) => {
22
22
  * @param element 查询元素
23
23
  * @returns 是否存在。true 存在;false 不存在
24
24
  */
25
- isExist(e, r) {
26
- return !e || !r ? !1 : e.indexOf(r) !== -1;
25
+ isExist(e, t) {
26
+ return !e || !t ? !1 : e.indexOf(t) !== -1;
27
27
  },
28
28
  /**
29
29
  * 统计数组中某元素出现的次数:对于大型数组,手动循环的性能略优于 filter 和 reduce。
@@ -31,11 +31,11 @@ const n = (e) => {
31
31
  * @param target 目标元素
32
32
  * @returns 出现次数
33
33
  */
34
- countOfAppear(e, r) {
35
- let t = 0;
36
- for (const o of e)
37
- o === r && t++;
38
- return t;
34
+ countOfAppear(e, t) {
35
+ let r = 0;
36
+ for (const n of e)
37
+ n === t && r++;
38
+ return r;
39
39
  },
40
40
  /**
41
41
  * 数组排序-默认升序
@@ -43,17 +43,17 @@ const n = (e) => {
43
43
  * @param order 排序方式:asc 升序;desc 降序
44
44
  * @returns 排序后的数组
45
45
  */
46
- sort(e, r = "asc") {
47
- return e ? e.sort((t, o) => r === "asc" ? t > o ? 1 : -1 : t < o ? 1 : -1) : [];
46
+ sort(e, t = "asc") {
47
+ return e ? e.sort((r, n) => t === "asc" ? r > n ? 1 : -1 : r < n ? 1 : -1) : [];
48
48
  }
49
- }, l = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], c = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
49
+ }, l = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], u = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
50
50
  __proto__: null,
51
51
  toLetter: l
52
- }, Symbol.toStringTag, { value: "Module" })), u = (e) => e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), i = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
52
+ }, Symbol.toStringTag, { value: "Module" })), c = (e) => e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), i = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
53
53
  __proto__: null,
54
- toMoney: u
54
+ toMoney: c
55
55
  }, Symbol.toStringTag, { value: "Module" })), g = {
56
- ...c,
56
+ ...u,
57
57
  ...i
58
58
  }, b = {
59
59
  /**
@@ -64,26 +64,35 @@ const n = (e) => {
64
64
  desensitize: (e) => e ? e.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2") || e.slice(0, 3) + "****" + e.slice(7) : ""
65
65
  }, y = {
66
66
  /**
67
- * 判断某元素是否在字符串中
67
+ * 判断某元素是否在字符串中-比includes()方法更兼容,includes为ES6新增方法,IE不支持。小程序也不支持
68
68
  * @param str 字符串
69
69
  * @param element 查询元素
70
70
  * @returns 是否存在。true 存在;false 不存在
71
71
  */
72
- isExist(e, r) {
73
- if (!e || !r)
72
+ isExist(e, t) {
73
+ if (!e || !t)
74
74
  return !1;
75
- const t = e.split(",");
76
- return console.log("判断某元素是否在字符串中", t.indexOf(r) === -1), t.indexOf(r) !== -1;
75
+ const r = e.split(",");
76
+ return console.log("判断某元素是否在字符串中", r.indexOf(t) === -1), r.indexOf(t) !== -1;
77
+ },
78
+ /**
79
+ * 判断某元素是否在字符串中-比isExist()方法更高效。
80
+ * @param str 字符串
81
+ * @param element 查询元素
82
+ * @returns 是否存在。true 存在;false 不存在
83
+ */
84
+ includes(e, t) {
85
+ return !e || !t ? !1 : e.includes(t);
77
86
  }
78
87
  }, f = (e) => {
79
- const t = new RegExp("[?&]" + e + "=([^&#]*)", "i").exec(window.location.href);
80
- return t ? decodeURIComponent(t[1]) : null;
88
+ const r = new RegExp("[?&]" + e + "=([^&#]*)", "i").exec(window.location.href);
89
+ return r ? decodeURIComponent(r[1]) : null;
81
90
  }, a = {
82
91
  getQueryInfoByName: f
83
92
  }, p = {
84
93
  ...a
85
- }, O = (e, r = 2) => {
86
- console.log(e, r);
94
+ }, O = (e, t = 2) => {
95
+ console.log(e, t);
87
96
  };
88
97
  export {
89
98
  d as arrayUtils,
@@ -1 +1 @@
1
- (function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.yhkitUtils={}))})(this,function(o){"use strict";const l={...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:e=>{if(!e||!e.length)return{};const n={};return e.forEach(t=>{const r=Object.assign({label:t.label,text:t.label},t);n[t==null?void 0:t.value]=r}),n}},Symbol.toStringTag,{value:"Module"})),unique:e=>e?Array.from(new Set(e)):[],isExist(e,n){return!e||!n?!1:e.indexOf(n)!==-1},countOfAppear(e,n){let t=0;for(const r of e)r===n&&t++;return t},sort(e,n="asc"){return e?e.sort((t,r)=>n==="asc"?t>r?1:-1:t<r?1:-1):[]}},i={...Object.freeze(Object.defineProperty({__proto__:null,toLetter:e=>e>25||e<0?"":"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e]},Symbol.toStringTag,{value:"Module"})),...Object.freeze(Object.defineProperty({__proto__:null,toMoney:e=>e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},Symbol.toStringTag,{value:"Module"}))},u={desensitize:e=>e?e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||e.slice(0,3)+"****"+e.slice(7):""},c={isExist(e,n){if(!e||!n)return!1;const t=e.split(",");return console.log("判断某元素是否在字符串中",t.indexOf(n)===-1),t.indexOf(n)!==-1}},f={...{getQueryInfoByName:e=>{const t=new RegExp("[?&]"+e+"=([^&#]*)","i").exec(window.location.href);return t?decodeURIComponent(t[1]):null}}},d=(e,n=2)=>{console.log(e,n)};o.arrayUtils=l,o.numberUtils=i,o.phoneUtils=u,o.stringUtils=c,o.toList=d,o.urlUtils=f,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(r,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(r=typeof globalThis<"u"?globalThis:r||self,s(r.yhkitUtils={}))})(this,function(r){"use strict";const i={...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:e=>{if(!e||!e.length)return{};const t={};return e.forEach(n=>{const o=Object.assign({label:n.label,text:n.label},n);t[n==null?void 0:n.value]=o}),t}},Symbol.toStringTag,{value:"Module"})),unique:e=>e?Array.from(new Set(e)):[],isExist(e,t){return!e||!t?!1:e.indexOf(t)!==-1},countOfAppear(e,t){let n=0;for(const o of e)o===t&&n++;return n},sort(e,t="asc"){return e?e.sort((n,o)=>t==="asc"?n>o?1:-1:n<o?1:-1):[]}},l={...Object.freeze(Object.defineProperty({__proto__:null,toLetter:e=>e>25||e<0?"":"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e]},Symbol.toStringTag,{value:"Module"})),...Object.freeze(Object.defineProperty({__proto__:null,toMoney:e=>e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},Symbol.toStringTag,{value:"Module"}))},u={desensitize:e=>e?e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||e.slice(0,3)+"****"+e.slice(7):""},c={isExist(e,t){if(!e||!t)return!1;const n=e.split(",");return console.log("判断某元素是否在字符串中",n.indexOf(t)===-1),n.indexOf(t)!==-1},includes(e,t){return!e||!t?!1:e.includes(t)}},f={...{getQueryInfoByName:e=>{const n=new RegExp("[?&]"+e+"=([^&#]*)","i").exec(window.location.href);return n?decodeURIComponent(n[1]):null}}},d=(e,t=2)=>{console.log(e,t)};r.arrayUtils=i,r.numberUtils=l,r.phoneUtils=u,r.stringUtils=c,r.toList=d,r.urlUtils=f,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yh-kit/utils",
3
3
  "private": false,
4
- "version": "1.2.1",
4
+ "version": "1.2.2",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -3,10 +3,17 @@
3
3
  */
4
4
  export declare const stringUtils: {
5
5
  /**
6
- * 判断某元素是否在字符串中
6
+ * 判断某元素是否在字符串中-比includes()方法更兼容,includes为ES6新增方法,IE不支持。小程序也不支持
7
7
  * @param str 字符串
8
8
  * @param element 查询元素
9
9
  * @returns 是否存在。true 存在;false 不存在
10
10
  */
11
11
  isExist(str: string, element: string): boolean;
12
+ /**
13
+ * 判断某元素是否在字符串中-比isExist()方法更高效。
14
+ * @param str 字符串
15
+ * @param element 查询元素
16
+ * @returns 是否存在。true 存在;false 不存在
17
+ */
18
+ includes(str: string, element: string): boolean;
12
19
  };