@yh-kit/utils 1.5.0 → 1.6.0
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 +338 -156
- package/dist/utils.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/utils/lib/array/index.d.ts +19 -0
- package/types/utils/lib/date/index.d.ts +8 -0
- package/types/utils/lib/document/index.d.ts +40 -0
- package/types/utils/lib/index.d.ts +2 -1
- package/types/utils/lib/map/index.d.ts +23 -0
- package/types/utils/lib/object/index.d.ts +20 -0
- package/types/utils/lib/string/index.d.ts +13 -0
- package/types/utils/lib/element/index.d.ts +0 -12
package/dist/utils.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const b = (t) => {
|
|
2
2
|
if (!t || !t.length) return {};
|
|
3
|
-
const
|
|
4
|
-
return t.forEach((
|
|
5
|
-
const o = Object.assign({ label:
|
|
6
|
-
e
|
|
7
|
-
}),
|
|
3
|
+
const r = {};
|
|
4
|
+
return t.forEach((e) => {
|
|
5
|
+
const o = Object.assign({ label: e.label, text: e.label }, e);
|
|
6
|
+
r[e == null ? void 0 : e.value] = o;
|
|
7
|
+
}), r;
|
|
8
8
|
}, y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
9
9
|
__proto__: null,
|
|
10
10
|
toEnumObj: b
|
|
@@ -24,8 +24,8 @@ const b = (t) => {
|
|
|
24
24
|
* @param element 查询元素
|
|
25
25
|
* @returns 是否存在。true 存在;false 不存在
|
|
26
26
|
*/
|
|
27
|
-
isExist(t,
|
|
28
|
-
return !t || !
|
|
27
|
+
isExist(t, r) {
|
|
28
|
+
return !t || !r ? !1 : t.indexOf(r) !== -1;
|
|
29
29
|
},
|
|
30
30
|
/**
|
|
31
31
|
* 统计数组中某元素出现的次数:对于大型数组,手动循环的性能略优于 filter 和 reduce。
|
|
@@ -33,11 +33,25 @@ const b = (t) => {
|
|
|
33
33
|
* @param target 目标元素
|
|
34
34
|
* @returns 出现次数
|
|
35
35
|
*/
|
|
36
|
-
countOfAppear(t,
|
|
37
|
-
let
|
|
36
|
+
countOfAppear(t, r) {
|
|
37
|
+
let e = 0;
|
|
38
38
|
for (const o of t)
|
|
39
|
-
o ===
|
|
40
|
-
return
|
|
39
|
+
o === r && e++;
|
|
40
|
+
return e;
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* 查找某个元素在数组中重复出现的位置
|
|
44
|
+
* @param array 数组
|
|
45
|
+
* @param element 元素
|
|
46
|
+
* @returns 位置数组
|
|
47
|
+
*/
|
|
48
|
+
indexsOfAppear(t, r) {
|
|
49
|
+
let e = -1;
|
|
50
|
+
const o = [];
|
|
51
|
+
do
|
|
52
|
+
e = t.indexOf(r, e + 1), e !== -1 && o.push(e);
|
|
53
|
+
while (e !== -1);
|
|
54
|
+
return o;
|
|
41
55
|
},
|
|
42
56
|
/**
|
|
43
57
|
* 数组排序-默认升序
|
|
@@ -45,8 +59,8 @@ const b = (t) => {
|
|
|
45
59
|
* @param order 排序方式:asc 升序;desc 降序
|
|
46
60
|
* @returns 排序后的数组
|
|
47
61
|
*/
|
|
48
|
-
sort(t,
|
|
49
|
-
return t ? t.sort((
|
|
62
|
+
sort(t, r = "asc") {
|
|
63
|
+
return t ? t.sort((e, o) => r === "asc" ? e > o ? 1 : -1 : e < o ? 1 : -1) : [];
|
|
50
64
|
},
|
|
51
65
|
/**
|
|
52
66
|
* 数组乱序(洗牌算法)
|
|
@@ -62,17 +76,33 @@ const b = (t) => {
|
|
|
62
76
|
shuffle(t) {
|
|
63
77
|
if (!t)
|
|
64
78
|
return [];
|
|
65
|
-
for (let
|
|
66
|
-
const
|
|
67
|
-
[t[
|
|
79
|
+
for (let r = t.length - 1; r > 0; r--) {
|
|
80
|
+
const e = Math.floor(Math.random() * (r + 1));
|
|
81
|
+
[t[r], t[e]] = [t[e], t[r]];
|
|
68
82
|
}
|
|
69
83
|
return t;
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* 获取数组中的最大值
|
|
87
|
+
* @param arr 数组
|
|
88
|
+
* @returns 最大值
|
|
89
|
+
*/
|
|
90
|
+
getMaxValue(t) {
|
|
91
|
+
return t ? Math.max(...t) : 0;
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* 获取数组中的最小值
|
|
95
|
+
* @param arr 数组
|
|
96
|
+
* @returns 最小值
|
|
97
|
+
*/
|
|
98
|
+
getMinValue(t) {
|
|
99
|
+
return t ? Math.min(...t) : 0;
|
|
70
100
|
}
|
|
71
101
|
},
|
|
72
102
|
{
|
|
73
103
|
...y
|
|
74
104
|
}
|
|
75
|
-
),
|
|
105
|
+
), L = {
|
|
76
106
|
/**
|
|
77
107
|
* 将Base64编码的字符串转换为Blob对象。
|
|
78
108
|
* Blob对象用于表示二进制大型对象,可以在浏览器环境中处理大文件或二进制数据。
|
|
@@ -82,20 +112,20 @@ const b = (t) => {
|
|
|
82
112
|
* @param sliceSize 可选参数,表示分片大小,默认为512字节。用于控制每次处理的Base64字符串长度,以优化大文件的处理。
|
|
83
113
|
* @returns 返回转换后的Blob对象,如果转换失败,则返回null。
|
|
84
114
|
*/
|
|
85
|
-
toBlob(t,
|
|
86
|
-
const
|
|
115
|
+
toBlob(t, r = "", e = 512) {
|
|
116
|
+
const n = (t.split(",")[1] || t).replace(/-/g, "+").replace(/_/g, "/"), s = "=".repeat((4 - n.length % 4) % 4), l = n + s;
|
|
87
117
|
try {
|
|
88
|
-
const
|
|
89
|
-
for (let
|
|
90
|
-
const
|
|
91
|
-
for (let
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
118
|
+
const c = atob(l), a = [];
|
|
119
|
+
for (let d = 0; d < c.length; d += e) {
|
|
120
|
+
const i = c.slice(d, d + e), f = new Array(i.length);
|
|
121
|
+
for (let u = 0; u < i.length; u++)
|
|
122
|
+
f[u] = i.charCodeAt(u);
|
|
123
|
+
const h = new Uint8Array(f);
|
|
124
|
+
a.push(h);
|
|
95
125
|
}
|
|
96
|
-
return new Blob(
|
|
97
|
-
} catch (
|
|
98
|
-
return console.error("Failed to convert base64 to blob:",
|
|
126
|
+
return new Blob(a, { type: r });
|
|
127
|
+
} catch (c) {
|
|
128
|
+
return console.error("Failed to convert base64 to blob:", c), null;
|
|
99
129
|
}
|
|
100
130
|
},
|
|
101
131
|
/**
|
|
@@ -108,18 +138,18 @@ const b = (t) => {
|
|
|
108
138
|
* @param mimeType MIME类型,默认为"text/plain"。
|
|
109
139
|
* @returns 返回一个File对象,包含解码后的数据。
|
|
110
140
|
*/
|
|
111
|
-
toFile(t,
|
|
112
|
-
const
|
|
113
|
-
for (let
|
|
114
|
-
const
|
|
115
|
-
for (let
|
|
116
|
-
|
|
117
|
-
|
|
141
|
+
toFile(t, r = "file.txt", e = "text/plain") {
|
|
142
|
+
const n = t.replace(/^data:.+;base64,/, "").replace(/-/g, "+").replace(/_/g, "/"), s = "=".repeat((4 - n.length % 4) % 4), l = n + s, c = atob(l), a = [];
|
|
143
|
+
for (let i = 0; i < c.length; i += 512) {
|
|
144
|
+
const f = c.slice(i, i + 512), h = new Array(f.length);
|
|
145
|
+
for (let u = 0; u < f.length; u++)
|
|
146
|
+
h[u] = f.charCodeAt(u);
|
|
147
|
+
a.push(new Uint8Array(h));
|
|
118
148
|
}
|
|
119
|
-
const
|
|
120
|
-
return new File([
|
|
149
|
+
const d = new Blob(a, { type: e });
|
|
150
|
+
return new File([d], r, { type: e });
|
|
121
151
|
}
|
|
122
|
-
},
|
|
152
|
+
}, m = {
|
|
123
153
|
/**
|
|
124
154
|
* 检查是否为空字符串
|
|
125
155
|
* @param str 要检查的字符串
|
|
@@ -238,8 +268,8 @@ const b = (t) => {
|
|
|
238
268
|
* @returns true 表示元素在可视区域内,false 表示元素不在可视区域内
|
|
239
269
|
*/
|
|
240
270
|
isInViewport(t) {
|
|
241
|
-
const
|
|
242
|
-
return
|
|
271
|
+
const r = t.getBoundingClientRect();
|
|
272
|
+
return r.top >= 0 && r.left >= 0 && r.bottom <= window.innerHeight && r.right <= window.innerWidth;
|
|
243
273
|
},
|
|
244
274
|
/**
|
|
245
275
|
* 判断是否为闰年
|
|
@@ -263,7 +293,7 @@ const b = (t) => {
|
|
|
263
293
|
isMobile() {
|
|
264
294
|
return /Mobi|Android|iPhone/i.test(navigator.userAgent);
|
|
265
295
|
}
|
|
266
|
-
},
|
|
296
|
+
}, j = {
|
|
267
297
|
/**
|
|
268
298
|
* 通过传入的name获取cookie的值
|
|
269
299
|
* @param name cookie的name
|
|
@@ -271,8 +301,8 @@ const b = (t) => {
|
|
|
271
301
|
*/
|
|
272
302
|
getCookie(t) {
|
|
273
303
|
if (!t) return;
|
|
274
|
-
const
|
|
275
|
-
return
|
|
304
|
+
const r = document.cookie.match(new RegExp("(^| )" + t + "=([^;]+)"));
|
|
305
|
+
return r ? decodeURIComponent(r[2]) : null;
|
|
276
306
|
},
|
|
277
307
|
/**
|
|
278
308
|
* 设置 cookie
|
|
@@ -281,9 +311,9 @@ const b = (t) => {
|
|
|
281
311
|
* @param days cookie的过期时间,默认7天。如果为0,则表示cookie在会话结束时过期。如果为负数,则表示cookie已过期。
|
|
282
312
|
* @returns void
|
|
283
313
|
*/
|
|
284
|
-
setCookie(t,
|
|
314
|
+
setCookie(t, r, e = 7) {
|
|
285
315
|
const o = /* @__PURE__ */ new Date();
|
|
286
|
-
o.setTime(o.getTime() +
|
|
316
|
+
o.setTime(o.getTime() + e * 24 * 60 * 60 * 1e3), document.cookie = `${t}=${encodeURIComponent(r)};expires=${o.toUTCString()};path=/`;
|
|
287
317
|
},
|
|
288
318
|
/**
|
|
289
319
|
* 删除cookie
|
|
@@ -293,15 +323,15 @@ const b = (t) => {
|
|
|
293
323
|
deleteCookie(t) {
|
|
294
324
|
this.setCookie(t, "", -1);
|
|
295
325
|
}
|
|
296
|
-
},
|
|
326
|
+
}, C = {
|
|
297
327
|
/**
|
|
298
328
|
* 获取当前时间字符串
|
|
299
329
|
* @param locales 区域设置。如:'zh-CN','en-US',"chinese"。默认'zh-CN'。
|
|
300
330
|
* @param hour12 是否使用12小时制。默认false,使用24小时制。
|
|
301
331
|
* @returns 当前时间的字符串。如:'2025/5/27 16:54:45'
|
|
302
332
|
*/
|
|
303
|
-
getTimeString(t,
|
|
304
|
-
return
|
|
333
|
+
getTimeString(t, r = !1) {
|
|
334
|
+
return r ? (/* @__PURE__ */ new Date()).toLocaleString(t, { hour12: !0 }) : (/* @__PURE__ */ new Date()).toLocaleString("chinese", { hour12: !1 });
|
|
305
335
|
},
|
|
306
336
|
/**
|
|
307
337
|
* 计算两个日期相差天数
|
|
@@ -309,9 +339,9 @@ const b = (t) => {
|
|
|
309
339
|
* @param date2 日期2
|
|
310
340
|
* @returns 相差天数
|
|
311
341
|
*/
|
|
312
|
-
diffDays(t,
|
|
313
|
-
const
|
|
314
|
-
return
|
|
342
|
+
diffDays(t, r) {
|
|
343
|
+
const e = new Date(t).getTime(), o = new Date(r).getTime();
|
|
344
|
+
return e > o ? Math.abs(Math.floor((e - o) / (24 * 3600 * 1e3))) : Math.abs(Math.floor((o - e) / (24 * 3600 * 1e3)));
|
|
315
345
|
},
|
|
316
346
|
/**
|
|
317
347
|
* 生成唯一ID(时间戳+随机数)
|
|
@@ -319,18 +349,37 @@ const b = (t) => {
|
|
|
319
349
|
*/
|
|
320
350
|
uniqueId() {
|
|
321
351
|
return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
|
|
322
|
-
}
|
|
323
|
-
}, N = {
|
|
352
|
+
},
|
|
324
353
|
/**
|
|
325
|
-
*
|
|
326
|
-
* @param
|
|
327
|
-
* @param
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
354
|
+
* 获取指定日期是当年的第几天
|
|
355
|
+
* @param year 年份
|
|
356
|
+
* @param month 月份 数字:1-12;1:代表一月;12:代表十二月
|
|
357
|
+
* @param day 日期
|
|
358
|
+
* @returns 当年的第几天
|
|
359
|
+
*/
|
|
360
|
+
getWhichDays(t, r, e) {
|
|
361
|
+
let o = e;
|
|
362
|
+
for (let n = 1; n < r; n++)
|
|
363
|
+
switch (n) {
|
|
364
|
+
case 1:
|
|
365
|
+
case 3:
|
|
366
|
+
case 5:
|
|
367
|
+
case 7:
|
|
368
|
+
case 8:
|
|
369
|
+
case 10:
|
|
370
|
+
case 12:
|
|
371
|
+
o += 31;
|
|
372
|
+
break;
|
|
373
|
+
case 2:
|
|
374
|
+
m.isLeapYear(t) ? o += 29 : o += 28;
|
|
375
|
+
break;
|
|
376
|
+
default:
|
|
377
|
+
o += 30;
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
return o;
|
|
332
381
|
}
|
|
333
|
-
},
|
|
382
|
+
}, T = {
|
|
334
383
|
/**
|
|
335
384
|
* 获取元素相对于文档顶部的偏移量(距离)
|
|
336
385
|
* 处理了SVG元素的特殊情况。
|
|
@@ -341,43 +390,120 @@ const b = (t) => {
|
|
|
341
390
|
if (!t)
|
|
342
391
|
throw new Error("Element is not provided");
|
|
343
392
|
if (t instanceof SVGElement) {
|
|
344
|
-
const
|
|
345
|
-
return
|
|
393
|
+
const e = t.getBoundingClientRect(), o = window.pageYOffset || document.documentElement.scrollTop;
|
|
394
|
+
return e.top + o;
|
|
346
395
|
}
|
|
347
|
-
let
|
|
396
|
+
let r = 0;
|
|
348
397
|
for (; t; )
|
|
349
|
-
|
|
350
|
-
return
|
|
398
|
+
r += t.offsetTop, t = t.offsetParent;
|
|
399
|
+
return r;
|
|
400
|
+
},
|
|
401
|
+
/**
|
|
402
|
+
* 获取文档的滚动值
|
|
403
|
+
* @returns 包含滚动值的对象 { scrollLeft: 水平滚动值, scrollTop: 垂直滚动值 }
|
|
404
|
+
*/
|
|
405
|
+
getScrollValue() {
|
|
406
|
+
const t = {
|
|
407
|
+
scrollLeft: 0,
|
|
408
|
+
scrollTop: 0
|
|
409
|
+
};
|
|
410
|
+
return t.scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft, t.scrollTop = document.body.scrollTop || document.documentElement.scrollTop, t;
|
|
411
|
+
},
|
|
412
|
+
/**
|
|
413
|
+
* 获取鼠标事件的页面坐标
|
|
414
|
+
* 已解决pageX、pageY兼容性问题
|
|
415
|
+
* e.pageX = e.clientX + 页面滚动的横向距离 ;
|
|
416
|
+
* e.pageY = e.clientY + 页面滚动的纵向距离 ;
|
|
417
|
+
* @param e 鼠标事件
|
|
418
|
+
* @returns 包含页面坐标的对象 { pageX: 水平页面坐标, pageY: 垂直页面坐标 }
|
|
419
|
+
*/
|
|
420
|
+
getPageValue(t) {
|
|
421
|
+
t = t || window.event;
|
|
422
|
+
const r = t.pageX || t.clientX + this.getScrollValue().scrollLeft, e = t.pageY || t.clientY + this.getScrollValue().scrollTop;
|
|
423
|
+
return {
|
|
424
|
+
pageX: r,
|
|
425
|
+
pageY: e
|
|
426
|
+
};
|
|
427
|
+
},
|
|
428
|
+
/**
|
|
429
|
+
* 给元素添加事件监听器 - 判断并处理了监听事件的兼容性问题
|
|
430
|
+
* 实例应用: addEventListenerFn(btn, 'click', function(){})
|
|
431
|
+
* @param element 元素
|
|
432
|
+
* @param eventName 事件名称
|
|
433
|
+
* @param fn 事件处理函数
|
|
434
|
+
*/
|
|
435
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
436
|
+
addEventListener(t, r, e) {
|
|
437
|
+
t.addEventListener ? t.addEventListener(r, e) : t.attachEvent ? t.attachEvent("on" + r, e) : t["on" + r] = e;
|
|
438
|
+
}
|
|
439
|
+
}, k = {
|
|
440
|
+
/**
|
|
441
|
+
* 将blob对象转化成文件并导出到本地
|
|
442
|
+
* @param blob blob对象
|
|
443
|
+
* @param filename 文件名
|
|
444
|
+
*/
|
|
445
|
+
saveAsBlob(t, r) {
|
|
446
|
+
const e = document.createElement("a"), o = window.URL.createObjectURL(t);
|
|
447
|
+
e.href = o, e.download = r, document.body.appendChild(e), e.click(), URL.revokeObjectURL(o), document.body.removeChild(e);
|
|
351
448
|
}
|
|
352
|
-
},
|
|
449
|
+
}, _ = {
|
|
353
450
|
/**
|
|
354
451
|
* 将选中的字母数组从A-Z排序:用于试题选择答案的排序实例
|
|
355
452
|
* @param arr 字母数组
|
|
356
453
|
* @returns
|
|
357
454
|
*/
|
|
358
455
|
sortFromA2Z(t) {
|
|
359
|
-
return t != null && t.length ? t.sort((
|
|
360
|
-
const
|
|
361
|
-
return
|
|
456
|
+
return t != null && t.length ? t.sort((e, o) => {
|
|
457
|
+
const n = e.toUpperCase(), s = o.toUpperCase();
|
|
458
|
+
return n < s ? -1 : n > s ? 1 : 0;
|
|
362
459
|
}) : void 0;
|
|
363
460
|
}
|
|
461
|
+
}, v = {
|
|
462
|
+
/**
|
|
463
|
+
* 计算弧度
|
|
464
|
+
* 在数学和编程里,角度有两种常用单位,分别是度(°)和弧度(rad)。
|
|
465
|
+
* 1 个完整的圆周,用角度表示是 360°,用弧度表示则是 2π rad。
|
|
466
|
+
* 角度和弧度的换算关系为:弧度 = 角度 × π / 180。
|
|
467
|
+
* @param d 经度值或纬度值
|
|
468
|
+
* @returns 弧度值
|
|
469
|
+
*/
|
|
470
|
+
rad(t) {
|
|
471
|
+
return t * Math.PI / 180;
|
|
472
|
+
},
|
|
473
|
+
/**
|
|
474
|
+
* 根据经纬度计算距离
|
|
475
|
+
* @param userLat 用户纬度
|
|
476
|
+
* @param userLng 用户经度
|
|
477
|
+
* @param targetLat 目标纬度
|
|
478
|
+
* @param targetLng 目标经度
|
|
479
|
+
* @returns 距离值 单位:km
|
|
480
|
+
*/
|
|
481
|
+
getDistance(t, r, e, o) {
|
|
482
|
+
const n = this.rad(t), s = this.rad(e), l = n - s, c = this.rad(r) - this.rad(o);
|
|
483
|
+
let a = 2 * Math.asin(
|
|
484
|
+
Math.sqrt(
|
|
485
|
+
Math.pow(Math.sin(l / 2), 2) + Math.cos(n) * Math.cos(s) * Math.pow(Math.sin(c / 2), 2)
|
|
486
|
+
)
|
|
487
|
+
);
|
|
488
|
+
return a = a * 6378.137, a = Math.round(a * 1e4) / 1e4, a = +a.toFixed(2), console.log("经纬度计算的距离为:" + a), a;
|
|
489
|
+
}
|
|
364
490
|
};
|
|
365
|
-
class
|
|
491
|
+
class I {
|
|
366
492
|
/**
|
|
367
493
|
* 转换为标准金额格式(带千分位和两位小数)
|
|
368
494
|
* @param num 要转换的数字
|
|
369
495
|
* @returns 格式化后的字符串
|
|
370
496
|
*/
|
|
371
|
-
static toStandardFormat(
|
|
497
|
+
static toStandardFormat(r) {
|
|
372
498
|
try {
|
|
373
|
-
const
|
|
374
|
-
if (isNaN(
|
|
499
|
+
const e = typeof r == "string" ? parseFloat(r) : r;
|
|
500
|
+
if (isNaN(e))
|
|
375
501
|
throw new Error("输入不是有效的数字");
|
|
376
|
-
if (!isFinite(
|
|
502
|
+
if (!isFinite(e))
|
|
377
503
|
throw new Error("输入是无穷大");
|
|
378
|
-
return
|
|
379
|
-
} catch (
|
|
380
|
-
return console.error("格式化失败:",
|
|
504
|
+
return e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
505
|
+
} catch (e) {
|
|
506
|
+
return console.error("格式化失败:", e), "格式错误";
|
|
381
507
|
}
|
|
382
508
|
}
|
|
383
509
|
/**
|
|
@@ -385,46 +511,46 @@ class L {
|
|
|
385
511
|
* @param num 要转换的数字
|
|
386
512
|
* @returns 中文大写金额字符串
|
|
387
513
|
*/
|
|
388
|
-
static toChineseFormat(
|
|
514
|
+
static toChineseFormat(r) {
|
|
389
515
|
try {
|
|
390
|
-
const
|
|
391
|
-
if (isNaN(
|
|
516
|
+
const e = typeof r == "string" ? parseFloat(r) : r;
|
|
517
|
+
if (isNaN(e))
|
|
392
518
|
throw new Error("输入不是有效的数字");
|
|
393
|
-
if (
|
|
519
|
+
if (e > 9999999999999e-2 || e < -9999999999999e-2)
|
|
394
520
|
throw new Error("输入数字超出范围");
|
|
395
|
-
const o =
|
|
396
|
-
let
|
|
397
|
-
if (
|
|
398
|
-
|
|
521
|
+
const o = e < 0, n = Math.abs(e), s = Math.floor(n), l = Math.round((n - s) * 100), c = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"], a = ["", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟"], d = ["角", "分"];
|
|
522
|
+
let i = "", f = s;
|
|
523
|
+
if (f === 0)
|
|
524
|
+
i = c[0];
|
|
399
525
|
else {
|
|
400
|
-
let
|
|
401
|
-
for (;
|
|
402
|
-
const
|
|
403
|
-
|
|
526
|
+
let p = 0;
|
|
527
|
+
for (; f > 0; ) {
|
|
528
|
+
const g = f % 10;
|
|
529
|
+
g !== 0 ? i = c[g] + a[p] + i : i.charAt(0) !== c[0] && (i = c[g] + i), f = Math.floor(f / 10), p++;
|
|
404
530
|
}
|
|
405
|
-
|
|
531
|
+
i = i.replace(/零+/g, "零"), i = i.replace(/零+$/, "");
|
|
406
532
|
}
|
|
407
|
-
let
|
|
408
|
-
if (
|
|
409
|
-
const
|
|
410
|
-
|
|
533
|
+
let h = "";
|
|
534
|
+
if (l > 0) {
|
|
535
|
+
const p = Math.floor(l / 10), g = l % 10;
|
|
536
|
+
p > 0 && (h += c[p] + d[0]), g > 0 && (h += c[g] + d[1]);
|
|
411
537
|
} else
|
|
412
|
-
|
|
413
|
-
let
|
|
414
|
-
return
|
|
415
|
-
} catch (
|
|
416
|
-
return console.error("转换失败:",
|
|
538
|
+
h = "整";
|
|
539
|
+
let u = (o ? "负" : "") + i + "圆" + h;
|
|
540
|
+
return u === "零圆整" && (u = "零圆"), u;
|
|
541
|
+
} catch (e) {
|
|
542
|
+
return console.error("转换失败:", e), "格式错误";
|
|
417
543
|
}
|
|
418
544
|
}
|
|
419
545
|
}
|
|
420
|
-
const
|
|
546
|
+
const w = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], S = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
421
547
|
__proto__: null,
|
|
422
|
-
toLetter:
|
|
423
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
548
|
+
toLetter: w
|
|
549
|
+
}, Symbol.toStringTag, { value: "Module" })), M = (t) => t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
424
550
|
__proto__: null,
|
|
425
|
-
toMoney:
|
|
426
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
427
|
-
...
|
|
551
|
+
toMoney: M
|
|
552
|
+
}, Symbol.toStringTag, { value: "Module" })), B = {
|
|
553
|
+
...S,
|
|
428
554
|
...O,
|
|
429
555
|
/**
|
|
430
556
|
* 判断是否为数字
|
|
@@ -434,7 +560,7 @@ const m = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], w = /*
|
|
|
434
560
|
isNumber(t) {
|
|
435
561
|
return typeof t == "number" && !isNaN(t);
|
|
436
562
|
}
|
|
437
|
-
},
|
|
563
|
+
}, N = {
|
|
438
564
|
/**
|
|
439
565
|
* 判断对象是否为空
|
|
440
566
|
* @param obj 对象
|
|
@@ -442,8 +568,30 @@ const m = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], w = /*
|
|
|
442
568
|
*/
|
|
443
569
|
isEmptyObject(t) {
|
|
444
570
|
return t ? Object.keys(t).length === 0 && t.constructor === Object : !0;
|
|
571
|
+
},
|
|
572
|
+
/**
|
|
573
|
+
* 复制对象【对象的浅拷贝 把obj1的成员,复制给obj2】
|
|
574
|
+
* @param obj1 源对象
|
|
575
|
+
* @param obj2 目标对象
|
|
576
|
+
*/
|
|
577
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
578
|
+
copy(t, r) {
|
|
579
|
+
for (const e in t)
|
|
580
|
+
r[e] = t[e];
|
|
581
|
+
},
|
|
582
|
+
/**
|
|
583
|
+
* 对象的深拷贝 把o1 的成员,复制给o2
|
|
584
|
+
* @param o1
|
|
585
|
+
* @param o2
|
|
586
|
+
*/
|
|
587
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
588
|
+
deepCopy(t, r) {
|
|
589
|
+
for (const e in t) {
|
|
590
|
+
const o = t[e];
|
|
591
|
+
o instanceof Object ? (r[e] = {}, this.deepCopy(o, r[e])) : o instanceof Array ? (r[e] = [], this.deepCopy(o, r[e])) : r[e] = t[e];
|
|
592
|
+
}
|
|
445
593
|
}
|
|
446
|
-
},
|
|
594
|
+
}, P = {
|
|
447
595
|
/**
|
|
448
596
|
* 脱敏
|
|
449
597
|
* @param phone 电话号码/手机号码
|
|
@@ -452,7 +600,7 @@ const m = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], w = /*
|
|
|
452
600
|
desensitize(t) {
|
|
453
601
|
return t ? t.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2") || t.slice(0, 3) + "****" + t.slice(7) : "";
|
|
454
602
|
}
|
|
455
|
-
},
|
|
603
|
+
}, F = {
|
|
456
604
|
/**
|
|
457
605
|
* 生成随机颜色
|
|
458
606
|
* @returns 随机颜色值
|
|
@@ -466,8 +614,8 @@ const m = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], w = /*
|
|
|
466
614
|
* @param max 最大值
|
|
467
615
|
* @returns 随机数
|
|
468
616
|
*/
|
|
469
|
-
int(t,
|
|
470
|
-
return Math.floor(Math.random() * (
|
|
617
|
+
int(t, r) {
|
|
618
|
+
return Math.floor(Math.random() * (r - t + 1)) + t;
|
|
471
619
|
},
|
|
472
620
|
/**
|
|
473
621
|
* 生成唯一ID(时间戳+随机数)
|
|
@@ -476,7 +624,7 @@ const m = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], w = /*
|
|
|
476
624
|
uniqueId() {
|
|
477
625
|
return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
|
|
478
626
|
}
|
|
479
|
-
},
|
|
627
|
+
}, R = {
|
|
480
628
|
/**
|
|
481
629
|
* 通过key值获取 localStorage 中存储的某个值
|
|
482
630
|
* @param key 获取的key
|
|
@@ -490,8 +638,8 @@ const m = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], w = /*
|
|
|
490
638
|
* @param key 设置的key
|
|
491
639
|
* @param value 设置的value
|
|
492
640
|
*/
|
|
493
|
-
setLocal(t,
|
|
494
|
-
localStorage.setItem(t,
|
|
641
|
+
setLocal(t, r) {
|
|
642
|
+
localStorage.setItem(t, r);
|
|
495
643
|
},
|
|
496
644
|
/**
|
|
497
645
|
* 删除localStorage中的某个值
|
|
@@ -513,8 +661,8 @@ const m = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], w = /*
|
|
|
513
661
|
* @param key 设置的key
|
|
514
662
|
* @param value 设置的value
|
|
515
663
|
*/
|
|
516
|
-
setSession(t,
|
|
517
|
-
sessionStorage.setItem(t,
|
|
664
|
+
setSession(t, r) {
|
|
665
|
+
sessionStorage.setItem(t, r);
|
|
518
666
|
},
|
|
519
667
|
/**
|
|
520
668
|
* 删除sessionStorage中的某个值
|
|
@@ -523,18 +671,18 @@ const m = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], w = /*
|
|
|
523
671
|
removeSession(t) {
|
|
524
672
|
sessionStorage.removeItem(t);
|
|
525
673
|
}
|
|
526
|
-
},
|
|
674
|
+
}, D = {
|
|
527
675
|
/**
|
|
528
676
|
* 判断某元素是否在字符串中-比includes()方法更兼容,includes为ES6新增方法,IE不支持。小程序也不支持
|
|
529
677
|
* @param str 字符串
|
|
530
678
|
* @param element 查询元素
|
|
531
679
|
* @returns 是否存在。true 存在;false 不存在
|
|
532
680
|
*/
|
|
533
|
-
isExist(t,
|
|
534
|
-
if (!t || !
|
|
681
|
+
isExist(t, r) {
|
|
682
|
+
if (!t || !r)
|
|
535
683
|
return !1;
|
|
536
|
-
const
|
|
537
|
-
return console.log("判断某元素是否在字符串中",
|
|
684
|
+
const e = t.split(",");
|
|
685
|
+
return console.log("判断某元素是否在字符串中", e.indexOf(r) === -1), e.indexOf(r) !== -1;
|
|
538
686
|
},
|
|
539
687
|
/**
|
|
540
688
|
* 判断某元素是否在字符串中-比isExist()方法更高效。
|
|
@@ -542,8 +690,8 @@ const m = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], w = /*
|
|
|
542
690
|
* @param element 查询元素
|
|
543
691
|
* @returns 是否存在。true 存在;false 不存在
|
|
544
692
|
*/
|
|
545
|
-
includes(t,
|
|
546
|
-
return !t || !
|
|
693
|
+
includes(t, r) {
|
|
694
|
+
return !t || !r ? !1 : t.includes(r);
|
|
547
695
|
},
|
|
548
696
|
/**
|
|
549
697
|
* 判断字符串是否为 JSON
|
|
@@ -556,20 +704,53 @@ const m = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], w = /*
|
|
|
556
704
|
} catch {
|
|
557
705
|
return !1;
|
|
558
706
|
}
|
|
707
|
+
},
|
|
708
|
+
/**
|
|
709
|
+
* 查找某个元素在字符串中重复出现的位置
|
|
710
|
+
* @param _string 字符串
|
|
711
|
+
* @param element 元素
|
|
712
|
+
* @returns 位置数组
|
|
713
|
+
*/
|
|
714
|
+
indexsOfAppear(t, r) {
|
|
715
|
+
let e = -1;
|
|
716
|
+
const o = [];
|
|
717
|
+
do
|
|
718
|
+
e = t.indexOf(r, e + 1), e !== -1 && o.push(e);
|
|
719
|
+
while (e !== -1);
|
|
720
|
+
return o;
|
|
721
|
+
},
|
|
722
|
+
/**
|
|
723
|
+
* 获取字符串中出现次数最多的字符和次数
|
|
724
|
+
* @param string 字符串
|
|
725
|
+
* @returns 数组,第一个元素为出现次数,第二个元素为出现次数最多的字符
|
|
726
|
+
*/
|
|
727
|
+
getMaxTimesAndVal(t) {
|
|
728
|
+
const r = [0, ""], e = {};
|
|
729
|
+
for (let s = 0; s < t.length; s++) {
|
|
730
|
+
const l = t.charAt(s);
|
|
731
|
+
e[l] ? e[l]++ : e[l] = 1;
|
|
732
|
+
}
|
|
733
|
+
let o = 1;
|
|
734
|
+
for (const s in e)
|
|
735
|
+
o < e[s] && (o = e[s]);
|
|
736
|
+
const n = [];
|
|
737
|
+
for (const s in e)
|
|
738
|
+
o == e[s] && n.push(s);
|
|
739
|
+
return r[0] = o, r[1] = n.join(), r;
|
|
559
740
|
}
|
|
560
741
|
}, U = (t) => {
|
|
561
|
-
const
|
|
562
|
-
return
|
|
742
|
+
const e = new RegExp("[?&]" + t + "=([^&#]*)", "i").exec(window.location.href);
|
|
743
|
+
return e ? decodeURIComponent(e[1]) : null;
|
|
563
744
|
};
|
|
564
|
-
function
|
|
745
|
+
function E(t) {
|
|
565
746
|
return new URLSearchParams(window.location.search).get(t);
|
|
566
747
|
}
|
|
567
|
-
const
|
|
748
|
+
const x = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
568
749
|
__proto__: null,
|
|
569
750
|
getQueryInfoByName: U,
|
|
570
|
-
getQueryParam:
|
|
571
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
572
|
-
...
|
|
751
|
+
getQueryParam: E
|
|
752
|
+
}, Symbol.toStringTag, { value: "Module" })), V = {
|
|
753
|
+
...x,
|
|
573
754
|
/**
|
|
574
755
|
* 获取当前域名
|
|
575
756
|
* @returns 当前url链接的host信息
|
|
@@ -584,41 +765,42 @@ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
584
765
|
getPath() {
|
|
585
766
|
return window.location.pathname;
|
|
586
767
|
}
|
|
587
|
-
},
|
|
768
|
+
}, $ = {
|
|
588
769
|
/**
|
|
589
770
|
* 处理瀑布流数据,使其适合瀑布流布局展示
|
|
590
771
|
* @param list 瀑布流数据-数组
|
|
591
772
|
* @param columnsNum 需要展示的列数
|
|
592
773
|
* @returns 适合瀑布流布局的数组
|
|
593
774
|
*/
|
|
594
|
-
toList(t,
|
|
595
|
-
console.log(t,
|
|
596
|
-
const
|
|
597
|
-
for (let
|
|
598
|
-
|
|
599
|
-
t.forEach((
|
|
775
|
+
toList(t, r = 2) {
|
|
776
|
+
console.log(t, r);
|
|
777
|
+
const e = {};
|
|
778
|
+
for (let n = 0; n < r; n++)
|
|
779
|
+
e[n] = [];
|
|
780
|
+
t.forEach((n, s) => e[s % r].push(n));
|
|
600
781
|
const o = [];
|
|
601
|
-
for (const
|
|
602
|
-
o.push(...
|
|
782
|
+
for (const n in e)
|
|
783
|
+
o.push(...e[n]);
|
|
603
784
|
return o;
|
|
604
785
|
}
|
|
605
786
|
};
|
|
606
787
|
export {
|
|
607
|
-
|
|
788
|
+
I as MoneyFormatter,
|
|
608
789
|
A as arrayUtils,
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
P as
|
|
620
|
-
|
|
621
|
-
R as
|
|
622
|
-
|
|
623
|
-
|
|
790
|
+
L as base64Utils,
|
|
791
|
+
m as booleanUtils,
|
|
792
|
+
j as cookieUtils,
|
|
793
|
+
C as dateUtils,
|
|
794
|
+
T as documentUtils,
|
|
795
|
+
k as downloadUtils,
|
|
796
|
+
_ as letterUtils,
|
|
797
|
+
v as mapUtils,
|
|
798
|
+
B as numberUtils,
|
|
799
|
+
N as objectUtils,
|
|
800
|
+
P as phoneUtils,
|
|
801
|
+
F as randomUtils,
|
|
802
|
+
R as storageUtils,
|
|
803
|
+
D as stringUtils,
|
|
804
|
+
V as urlUtils,
|
|
805
|
+
$ as waterfallUtils
|
|
624
806
|
};
|
package/dist/utils.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(i,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(i=typeof globalThis<"u"?globalThis:i||self,b(i.yhkitUtils={}))})(this,function(i){"use strict";const w=Object.assign({unique(t){return t?Array.from(new Set(t)):[]},isExist(t,r){return!t||!r?!1:t.indexOf(r)!==-1},countOfAppear(t,r){let e=0;for(const n of t)n===r&&e++;return e},indexsOfAppear(t,r){let e=-1;const n=[];do e=t.indexOf(r,e+1),e!==-1&&n.push(e);while(e!==-1);return n},sort(t,r="asc"){return t?t.sort((e,n)=>r==="asc"?e>n?1:-1:e<n?1:-1):[]},shuffle(t){if(!t)return[];for(let r=t.length-1;r>0;r--){const e=Math.floor(Math.random()*(r+1));[t[r],t[e]]=[t[e],t[r]]}return t},getMaxValue(t){return t?Math.max(...t):0},getMinValue(t){return t?Math.min(...t):0}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:t=>{if(!t||!t.length)return{};const r={};return t.forEach(e=>{const n=Object.assign({label:e.label,text:e.label},e);r[e==null?void 0:e.value]=n}),r}},Symbol.toStringTag,{value:"Module"}))}),U={toBlob(t,r="",e=512){const o=(t.split(",")[1]||t).replace(/-/g,"+").replace(/_/g,"/"),s="=".repeat((4-o.length%4)%4),u=o+s;try{const a=atob(u),l=[];for(let h=0;h<a.length;h+=e){const c=a.slice(h,h+e),d=new Array(c.length);for(let f=0;f<c.length;f++)d[f]=c.charCodeAt(f);const g=new Uint8Array(d);l.push(g)}return new Blob(l,{type:r})}catch(a){return console.error("Failed to convert base64 to blob:",a),null}},toFile(t,r="file.txt",e="text/plain"){const o=t.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),s="=".repeat((4-o.length%4)%4),u=o+s,a=atob(u),l=[];for(let c=0;c<a.length;c+=512){const d=a.slice(c,c+512),g=new Array(d.length);for(let f=0;f<d.length;f++)g[f]=d.charCodeAt(f);l.push(new Uint8Array(g))}const h=new Blob(l,{type:e});return new File([h],r,{type:e})}},m={isEmptyString(t){return typeof t=="string"&&t.trim()===""},isNumber(t){return typeof t=="number"&&!isNaN(t)},isObject(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)},isEmptyObject(t){return t?Object.keys(t).length===0&&t.constructor===Object:!0},isBoolean(t){return typeof t=="boolean"},isArray(t){return Array.isArray(t)},isFunction(t){return typeof t=="function"},isPromise(t){return!!t&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function"},isElement(t){return t instanceof Element},isPhone(t){return/^1[3-9]\d{9}$/.test(t)},isEmail(t){return/^[\w.-]+@[\w.-]+\.\w+$/.test(t)},isJSON(t){try{return JSON.parse(t),!0}catch{return!1}},isImageLoaded(t){return t.complete&&t.naturalWidth!==0},isInViewport(t){const r=t.getBoundingClientRect();return r.top>=0&&r.left>=0&&r.bottom<=window.innerHeight&&r.right<=window.innerWidth},isLeapYear(t){return t%4===0&&t%100!==0||t%400===0},isMobile(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}},S={getCookie(t){if(!t)return;const r=document.cookie.match(new RegExp("(^| )"+t+"=([^;]+)"));return r?decodeURIComponent(r[2]):null},setCookie(t,r,e=7){const n=new Date;n.setTime(n.getTime()+e*24*60*60*1e3),document.cookie=`${t}=${encodeURIComponent(r)};expires=${n.toUTCString()};path=/`},deleteCookie(t){this.setCookie(t,"",-1)}},M={getTimeString(t,r=!1){return r?new Date().toLocaleString(t,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(t,r){const e=new Date(t).getTime(),n=new Date(r).getTime();return e>n?Math.abs(Math.floor((e-n)/(24*3600*1e3))):Math.abs(Math.floor((n-e)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)},getWhichDays(t,r,e){let n=e;for(let o=1;o<r;o++)switch(o){case 1:case 3:case 5:case 7:case 8:case 10:case 12:n+=31;break;case 2:m.isLeapYear(t)?n+=29:n+=28;break;default:n+=30;break}return n}},O={getOffsetTop(t){if(!t)throw new Error("Element is not provided");if(t instanceof SVGElement){const e=t.getBoundingClientRect(),n=window.pageYOffset||document.documentElement.scrollTop;return e.top+n}let r=0;for(;t;)r+=t.offsetTop,t=t.offsetParent;return r},getScrollValue(){const t={scrollLeft:0,scrollTop:0};return t.scrollLeft=document.body.scrollLeft||document.documentElement.scrollLeft,t.scrollTop=document.body.scrollTop||document.documentElement.scrollTop,t},getPageValue(t){t=t||window.event;const r=t.pageX||t.clientX+this.getScrollValue().scrollLeft,e=t.pageY||t.clientY+this.getScrollValue().scrollTop;return{pageX:r,pageY:e}},addEventListener(t,r,e){t.addEventListener?t.addEventListener(r,e):t.attachEvent?t.attachEvent("on"+r,e):t["on"+r]=e}},E={saveAsBlob(t,r){const e=document.createElement("a"),n=window.URL.createObjectURL(t);e.href=n,e.download=r,document.body.appendChild(e),e.click(),URL.revokeObjectURL(n),document.body.removeChild(e)}},j={sortFromA2Z(t){return t!=null&&t.length?t.sort((e,n)=>{const o=e.toUpperCase(),s=n.toUpperCase();return o<s?-1:o>s?1:0}):void 0}},L={rad(t){return t*Math.PI/180},getDistance(t,r,e,n){const o=this.rad(t),s=this.rad(e),u=o-s,a=this.rad(r)-this.rad(n);let l=2*Math.asin(Math.sqrt(Math.pow(Math.sin(u/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin(a/2),2)));return l=l*6378.137,l=Math.round(l*1e4)/1e4,l=+l.toFixed(2),console.log("经纬度计算的距离为:"+l),l}};class A{static toStandardFormat(r){try{const e=typeof r=="string"?parseFloat(r):r;if(isNaN(e))throw new Error("输入不是有效的数字");if(!isFinite(e))throw new Error("输入是无穷大");return e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}catch(e){return console.error("格式化失败:",e),"格式错误"}}static toChineseFormat(r){try{const e=typeof r=="string"?parseFloat(r):r;if(isNaN(e))throw new Error("输入不是有效的数字");if(e>9999999999999e-2||e<-9999999999999e-2)throw new Error("输入数字超出范围");const n=e<0,o=Math.abs(e),s=Math.floor(o),u=Math.round((o-s)*100),a=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],l=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],h=["角","分"];let c="",d=s;if(d===0)c=a[0];else{let y=0;for(;d>0;){const p=d%10;p!==0?c=a[p]+l[y]+c:c.charAt(0)!==a[0]&&(c=a[p]+c),d=Math.floor(d/10),y++}c=c.replace(/零+/g,"零"),c=c.replace(/零+$/,"")}let g="";if(u>0){const y=Math.floor(u/10),p=u%10;y>0&&(g+=a[y]+h[0]),p>0&&(g+=a[p]+h[1])}else g="整";let f=(n?"负":"")+c+"圆"+g;return f==="零圆整"&&(f="零圆"),f}catch(e){return console.error("转换失败:",e),"格式错误"}}}const T={...Object.freeze(Object.defineProperty({__proto__:null,toLetter:t=>t>25||t<0?"":"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t]},Symbol.toStringTag,{value:"Module"})),...Object.freeze(Object.defineProperty({__proto__:null,toMoney:t=>t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},Symbol.toStringTag,{value:"Module"})),isNumber(t){return typeof t=="number"&&!isNaN(t)}},C={isEmptyObject(t){return t?Object.keys(t).length===0&&t.constructor===Object:!0},copy(t,r){for(const e in t)r[e]=t[e]},deepCopy(t,r){for(const e in t){const n=t[e];n instanceof Object?(r[e]={},this.deepCopy(n,r[e])):n instanceof Array?(r[e]=[],this.deepCopy(n,r[e])):r[e]=t[e]}}},k={desensitize(t){return t?t.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||t.slice(0,3)+"****"+t.slice(7):""}},_={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(t,r){return Math.floor(Math.random()*(r-t+1))+t},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},v={getLocal(t){return localStorage.getItem(t)},setLocal(t,r){localStorage.setItem(t,r)},removeLocal(t){localStorage.removeItem(t)},getSession(t){return sessionStorage.getItem(t)},setSession(t,r){sessionStorage.setItem(t,r)},removeSession(t){sessionStorage.removeItem(t)}},I={isExist(t,r){if(!t||!r)return!1;const e=t.split(",");return console.log("判断某元素是否在字符串中",e.indexOf(r)===-1),e.indexOf(r)!==-1},includes(t,r){return!t||!r?!1:t.includes(r)},isJSON(t){try{return JSON.parse(t),!0}catch{return!1}},indexsOfAppear(t,r){let e=-1;const n=[];do e=t.indexOf(r,e+1),e!==-1&&n.push(e);while(e!==-1);return n},getMaxTimesAndVal(t){const r=[0,""],e={};for(let s=0;s<t.length;s++){const u=t.charAt(s);e[u]?e[u]++:e[u]=1}let n=1;for(const s in e)n<e[s]&&(n=e[s]);const o=[];for(const s in e)n==e[s]&&o.push(s);return r[0]=n,r[1]=o.join(),r}},B=t=>{const e=new RegExp("[?&]"+t+"=([^&#]*)","i").exec(window.location.href);return e?decodeURIComponent(e[1]):null};function N(t){return new URLSearchParams(window.location.search).get(t)}const P={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:B,getQueryParam:N},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},F={toList(t,r=2){console.log(t,r);const e={};for(let o=0;o<r;o++)e[o]=[];t.forEach((o,s)=>e[s%r].push(o));const n=[];for(const o in e)n.push(...e[o]);return n}};i.MoneyFormatter=A,i.arrayUtils=w,i.base64Utils=U,i.booleanUtils=m,i.cookieUtils=S,i.dateUtils=M,i.documentUtils=O,i.downloadUtils=E,i.letterUtils=j,i.mapUtils=L,i.numberUtils=T,i.objectUtils=C,i.phoneUtils=k,i.randomUtils=_,i.storageUtils=v,i.stringUtils=I,i.urlUtils=P,i.waterfallUtils=F,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -22,6 +22,13 @@ export declare const arrayUtils: {
|
|
|
22
22
|
* @returns 出现次数
|
|
23
23
|
*/
|
|
24
24
|
countOfAppear<T>(arr: T[], target: T): number;
|
|
25
|
+
/**
|
|
26
|
+
* 查找某个元素在数组中重复出现的位置
|
|
27
|
+
* @param array 数组
|
|
28
|
+
* @param element 元素
|
|
29
|
+
* @returns 位置数组
|
|
30
|
+
*/
|
|
31
|
+
indexsOfAppear<T>(array: T[], element: T): number[];
|
|
25
32
|
/**
|
|
26
33
|
* 数组排序-默认升序
|
|
27
34
|
* @param arr 数组
|
|
@@ -41,6 +48,18 @@ export declare const arrayUtils: {
|
|
|
41
48
|
* @returns
|
|
42
49
|
*/
|
|
43
50
|
shuffle<T>(arr: T[]): T[];
|
|
51
|
+
/**
|
|
52
|
+
* 获取数组中的最大值
|
|
53
|
+
* @param arr 数组
|
|
54
|
+
* @returns 最大值
|
|
55
|
+
*/
|
|
56
|
+
getMaxValue(arr: number[]): number;
|
|
57
|
+
/**
|
|
58
|
+
* 获取数组中的最小值
|
|
59
|
+
* @param arr 数组
|
|
60
|
+
* @returns 最小值
|
|
61
|
+
*/
|
|
62
|
+
getMinValue(arr: number[]): number;
|
|
44
63
|
} & {
|
|
45
64
|
toEnumObj: (arr: import("@yh-kit/types").IOptionItem[]) => import("@yh-kit/types").TValueEnum;
|
|
46
65
|
};
|
|
@@ -21,4 +21,12 @@ export declare const dateUtils: {
|
|
|
21
21
|
* @returns 唯一ID
|
|
22
22
|
*/
|
|
23
23
|
uniqueId(): string;
|
|
24
|
+
/**
|
|
25
|
+
* 获取指定日期是当年的第几天
|
|
26
|
+
* @param year 年份
|
|
27
|
+
* @param month 月份 数字:1-12;1:代表一月;12:代表十二月
|
|
28
|
+
* @param day 日期
|
|
29
|
+
* @returns 当年的第几天
|
|
30
|
+
*/
|
|
31
|
+
getWhichDays(year: number, month: number, day: number): number;
|
|
24
32
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 元素【Dom】相关工具函数
|
|
3
|
+
*/
|
|
4
|
+
export declare const documentUtils: {
|
|
5
|
+
/**
|
|
6
|
+
* 获取元素相对于文档顶部的偏移量(距离)
|
|
7
|
+
* 处理了SVG元素的特殊情况。
|
|
8
|
+
* @param el 元素
|
|
9
|
+
* @returns 偏移量(距离值)
|
|
10
|
+
*/
|
|
11
|
+
getOffsetTop(el: HTMLElement): number;
|
|
12
|
+
/**
|
|
13
|
+
* 获取文档的滚动值
|
|
14
|
+
* @returns 包含滚动值的对象 { scrollLeft: 水平滚动值, scrollTop: 垂直滚动值 }
|
|
15
|
+
*/
|
|
16
|
+
getScrollValue(): {
|
|
17
|
+
scrollLeft: number;
|
|
18
|
+
scrollTop: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* 获取鼠标事件的页面坐标
|
|
22
|
+
* 已解决pageX、pageY兼容性问题
|
|
23
|
+
* e.pageX = e.clientX + 页面滚动的横向距离 ;
|
|
24
|
+
* e.pageY = e.clientY + 页面滚动的纵向距离 ;
|
|
25
|
+
* @param e 鼠标事件
|
|
26
|
+
* @returns 包含页面坐标的对象 { pageX: 水平页面坐标, pageY: 垂直页面坐标 }
|
|
27
|
+
*/
|
|
28
|
+
getPageValue(e: MouseEvent): {
|
|
29
|
+
pageX: number;
|
|
30
|
+
pageY: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* 给元素添加事件监听器 - 判断并处理了监听事件的兼容性问题
|
|
34
|
+
* 实例应用: addEventListenerFn(btn, 'click', function(){})
|
|
35
|
+
* @param element 元素
|
|
36
|
+
* @param eventName 事件名称
|
|
37
|
+
* @param fn 事件处理函数
|
|
38
|
+
*/
|
|
39
|
+
addEventListener(element: any, eventName: string, fn: any): void;
|
|
40
|
+
};
|
|
@@ -3,9 +3,10 @@ export * from "./base64";
|
|
|
3
3
|
export * from "./boolean";
|
|
4
4
|
export * from "./cookie";
|
|
5
5
|
export * from "./date";
|
|
6
|
+
export * from "./document";
|
|
6
7
|
export * from "./download";
|
|
7
|
-
export * from "./element";
|
|
8
8
|
export * from "./letter";
|
|
9
|
+
export * from "./map";
|
|
9
10
|
export * from "./money";
|
|
10
11
|
export * from "./number";
|
|
11
12
|
export * from "./object";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 地图相关工具函数
|
|
3
|
+
*/
|
|
4
|
+
export declare const mapUtils: {
|
|
5
|
+
/**
|
|
6
|
+
* 计算弧度
|
|
7
|
+
* 在数学和编程里,角度有两种常用单位,分别是度(°)和弧度(rad)。
|
|
8
|
+
* 1 个完整的圆周,用角度表示是 360°,用弧度表示则是 2π rad。
|
|
9
|
+
* 角度和弧度的换算关系为:弧度 = 角度 × π / 180。
|
|
10
|
+
* @param d 经度值或纬度值
|
|
11
|
+
* @returns 弧度值
|
|
12
|
+
*/
|
|
13
|
+
rad(d: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* 根据经纬度计算距离
|
|
16
|
+
* @param userLat 用户纬度
|
|
17
|
+
* @param userLng 用户经度
|
|
18
|
+
* @param targetLat 目标纬度
|
|
19
|
+
* @param targetLng 目标经度
|
|
20
|
+
* @returns 距离值 单位:km
|
|
21
|
+
*/
|
|
22
|
+
getDistance(userLat: number, userLng: number, targetLat: number, targetLng: number): number;
|
|
23
|
+
};
|
|
@@ -8,4 +8,24 @@ export declare const objectUtils: {
|
|
|
8
8
|
* @returns 是否为空。true 为空;false 不为空
|
|
9
9
|
*/
|
|
10
10
|
isEmptyObject(obj: object): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 复制对象【对象的浅拷贝 把obj1的成员,复制给obj2】
|
|
13
|
+
* @param obj1 源对象
|
|
14
|
+
* @param obj2 目标对象
|
|
15
|
+
*/
|
|
16
|
+
copy(obj1: {
|
|
17
|
+
[x: string]: any;
|
|
18
|
+
}, obj2: {
|
|
19
|
+
[x: string]: any;
|
|
20
|
+
}): void;
|
|
21
|
+
/**
|
|
22
|
+
* 对象的深拷贝 把o1 的成员,复制给o2
|
|
23
|
+
* @param o1
|
|
24
|
+
* @param o2
|
|
25
|
+
*/
|
|
26
|
+
deepCopy(o1: {
|
|
27
|
+
[x: string]: any;
|
|
28
|
+
}, o2: {
|
|
29
|
+
[x: string]: any;
|
|
30
|
+
}): void;
|
|
11
31
|
};
|
|
@@ -22,4 +22,17 @@ export declare const stringUtils: {
|
|
|
22
22
|
* @returns
|
|
23
23
|
*/
|
|
24
24
|
isJSON(str: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 查找某个元素在字符串中重复出现的位置
|
|
27
|
+
* @param _string 字符串
|
|
28
|
+
* @param element 元素
|
|
29
|
+
* @returns 位置数组
|
|
30
|
+
*/
|
|
31
|
+
indexsOfAppear(_string: string, element: string): number[];
|
|
32
|
+
/**
|
|
33
|
+
* 获取字符串中出现次数最多的字符和次数
|
|
34
|
+
* @param string 字符串
|
|
35
|
+
* @returns 数组,第一个元素为出现次数,第二个元素为出现次数最多的字符
|
|
36
|
+
*/
|
|
37
|
+
getMaxTimesAndVal(string: string): [number, string];
|
|
25
38
|
};
|