@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 +38 -29
- package/dist/utils.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/utils/lib/string/index.d.ts +8 -1
package/dist/utils.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
const o = (e) => {
|
|
2
2
|
if (!e || !e.length) return {};
|
|
3
|
-
const
|
|
4
|
-
return e.forEach((
|
|
5
|
-
const
|
|
6
|
-
r
|
|
7
|
-
}),
|
|
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:
|
|
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,
|
|
26
|
-
return !e || !
|
|
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,
|
|
35
|
-
let
|
|
36
|
-
for (const
|
|
37
|
-
|
|
38
|
-
return
|
|
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,
|
|
47
|
-
return e ? e.sort((
|
|
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],
|
|
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" })),
|
|
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:
|
|
54
|
+
toMoney: c
|
|
55
55
|
}, Symbol.toStringTag, { value: "Module" })), g = {
|
|
56
|
-
...
|
|
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,
|
|
73
|
-
if (!e || !
|
|
72
|
+
isExist(e, t) {
|
|
73
|
+
if (!e || !t)
|
|
74
74
|
return !1;
|
|
75
|
-
const
|
|
76
|
-
return console.log("判断某元素是否在字符串中",
|
|
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
|
|
80
|
-
return
|
|
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,
|
|
86
|
-
console.log(e,
|
|
94
|
+
}, O = (e, t = 2) => {
|
|
95
|
+
console.log(e, t);
|
|
87
96
|
};
|
|
88
97
|
export {
|
|
89
98
|
d as arrayUtils,
|
package/dist/utils.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
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
|
@@ -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
|
};
|