@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 CHANGED
@@ -1,10 +1,10 @@
1
1
  const b = (t) => {
2
2
  if (!t || !t.length) return {};
3
- const e = {};
4
- return t.forEach((r) => {
5
- const o = Object.assign({ label: r.label, text: r.label }, r);
6
- e[r == null ? void 0 : r.value] = o;
7
- }), e;
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, e) {
28
- return !t || !e ? !1 : t.indexOf(e) !== -1;
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, e) {
37
- let r = 0;
36
+ countOfAppear(t, r) {
37
+ let e = 0;
38
38
  for (const o of t)
39
- o === e && r++;
40
- return r;
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, e = "asc") {
49
- return t ? t.sort((r, o) => e === "asc" ? r > o ? 1 : -1 : r < o ? 1 : -1) : [];
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 e = t.length - 1; e > 0; e--) {
66
- const r = Math.floor(Math.random() * (e + 1));
67
- [t[e], t[r]] = [t[r], t[e]];
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
- ), j = {
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, e = "", r = 512) {
86
- const s = (t.split(",")[1] || t).replace(/-/g, "+").replace(/_/g, "/"), l = "=".repeat((4 - s.length % 4) % 4), d = s + l;
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 i = atob(d), g = [];
89
- for (let u = 0; u < i.length; u += r) {
90
- const n = i.slice(u, u + r), a = new Array(n.length);
91
- for (let c = 0; c < n.length; c++)
92
- a[c] = n.charCodeAt(c);
93
- const f = new Uint8Array(a);
94
- g.push(f);
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(g, { type: e });
97
- } catch (i) {
98
- return console.error("Failed to convert base64 to blob:", i), null;
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, e = "file.txt", r = "text/plain") {
112
- const s = t.replace(/^data:.+;base64,/, "").replace(/-/g, "+").replace(/_/g, "/"), l = "=".repeat((4 - s.length % 4) % 4), d = s + l, i = atob(d), g = [];
113
- for (let n = 0; n < i.length; n += 512) {
114
- const a = i.slice(n, n + 512), f = new Array(a.length);
115
- for (let c = 0; c < a.length; c++)
116
- f[c] = a.charCodeAt(c);
117
- g.push(new Uint8Array(f));
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 u = new Blob(g, { type: r });
120
- return new File([u], e, { type: r });
149
+ const d = new Blob(a, { type: e });
150
+ return new File([d], r, { type: e });
121
151
  }
122
- }, x = {
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 e = t.getBoundingClientRect();
242
- return e.top >= 0 && e.left >= 0 && e.bottom <= window.innerHeight && e.right <= window.innerWidth;
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
- }, C = {
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 e = document.cookie.match(new RegExp("(^| )" + t + "=([^;]+)"));
275
- return e ? decodeURIComponent(e[2]) : null;
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, e, r = 7) {
314
+ setCookie(t, r, e = 7) {
285
315
  const o = /* @__PURE__ */ new Date();
286
- o.setTime(o.getTime() + r * 24 * 60 * 60 * 1e3), document.cookie = `${t}=${encodeURIComponent(e)};expires=${o.toUTCString()};path=/`;
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, e = !1) {
304
- return e ? (/* @__PURE__ */ new Date()).toLocaleString(t, { hour12: !0 }) : (/* @__PURE__ */ new Date()).toLocaleString("chinese", { hour12: !1 });
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, e) {
313
- const r = new Date(t).getTime(), o = new Date(e).getTime();
314
- return r > o ? Math.abs(Math.floor((r - o) / (24 * 3600 * 1e3))) : Math.abs(Math.floor((o - r) / (24 * 3600 * 1e3)));
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
- * 将blob对象转化成文件并导出到本地
326
- * @param blob blob对象
327
- * @param filename 文件名
328
- */
329
- saveAsBlob(t, e) {
330
- const r = document.createElement("a"), o = window.URL.createObjectURL(t);
331
- r.href = o, r.download = e, document.body.appendChild(r), r.click(), URL.revokeObjectURL(o), document.body.removeChild(r);
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
- }, B = {
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 r = t.getBoundingClientRect(), o = window.pageYOffset || document.documentElement.scrollTop;
345
- return r.top + o;
393
+ const e = t.getBoundingClientRect(), o = window.pageYOffset || document.documentElement.scrollTop;
394
+ return e.top + o;
346
395
  }
347
- let e = 0;
396
+ let r = 0;
348
397
  for (; t; )
349
- e += t.offsetTop, t = t.offsetParent;
350
- return e;
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
- }, I = {
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((r, o) => {
360
- const s = r.toUpperCase(), l = o.toUpperCase();
361
- return s < l ? -1 : s > l ? 1 : 0;
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 L {
491
+ class I {
366
492
  /**
367
493
  * 转换为标准金额格式(带千分位和两位小数)
368
494
  * @param num 要转换的数字
369
495
  * @returns 格式化后的字符串
370
496
  */
371
- static toStandardFormat(e) {
497
+ static toStandardFormat(r) {
372
498
  try {
373
- const r = typeof e == "string" ? parseFloat(e) : e;
374
- if (isNaN(r))
499
+ const e = typeof r == "string" ? parseFloat(r) : r;
500
+ if (isNaN(e))
375
501
  throw new Error("输入不是有效的数字");
376
- if (!isFinite(r))
502
+ if (!isFinite(e))
377
503
  throw new Error("输入是无穷大");
378
- return r.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
379
- } catch (r) {
380
- return console.error("格式化失败:", r), "格式错误";
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(e) {
514
+ static toChineseFormat(r) {
389
515
  try {
390
- const r = typeof e == "string" ? parseFloat(e) : e;
391
- if (isNaN(r))
516
+ const e = typeof r == "string" ? parseFloat(r) : r;
517
+ if (isNaN(e))
392
518
  throw new Error("输入不是有效的数字");
393
- if (r > 9999999999999e-2 || r < -9999999999999e-2)
519
+ if (e > 9999999999999e-2 || e < -9999999999999e-2)
394
520
  throw new Error("输入数字超出范围");
395
- const o = r < 0, s = Math.abs(r), l = Math.floor(s), d = Math.round((s - l) * 100), i = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"], g = ["", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟"], u = ["角", "分"];
396
- let n = "", a = l;
397
- if (a === 0)
398
- n = i[0];
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 h = 0;
401
- for (; a > 0; ) {
402
- const p = a % 10;
403
- p !== 0 ? n = i[p] + g[h] + n : n.charAt(0) !== i[0] && (n = i[p] + n), a = Math.floor(a / 10), h++;
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
- n = n.replace(/零+/g, "零"), n = n.replace(/零+$/, "");
531
+ i = i.replace(/零+/g, "零"), i = i.replace(/零+$/, "");
406
532
  }
407
- let f = "";
408
- if (d > 0) {
409
- const h = Math.floor(d / 10), p = d % 10;
410
- h > 0 && (f += i[h] + u[0]), p > 0 && (f += i[p] + u[1]);
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
- f = "整";
413
- let c = (o ? "负" : "") + n + "圆" + f;
414
- return c === "零圆整" && (c = "零圆"), c;
415
- } catch (r) {
416
- return console.error("转换失败:", r), "格式错误";
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 m = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], w = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
546
+ const w = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], S = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
421
547
  __proto__: null,
422
- toLetter: m
423
- }, Symbol.toStringTag, { value: "Module" })), S = (t) => t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
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: S
426
- }, Symbol.toStringTag, { value: "Module" })), T = {
427
- ...w,
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
- }, v = {
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
- }, F = {
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
- }, P = {
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, e) {
470
- return Math.floor(Math.random() * (e - t + 1)) + t;
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
- }, k = {
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, e) {
494
- localStorage.setItem(t, e);
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, e) {
517
- sessionStorage.setItem(t, e);
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
- }, R = {
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, e) {
534
- if (!t || !e)
681
+ isExist(t, r) {
682
+ if (!t || !r)
535
683
  return !1;
536
- const r = t.split(",");
537
- return console.log("判断某元素是否在字符串中", r.indexOf(e) === -1), r.indexOf(e) !== -1;
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, e) {
546
- return !t || !e ? !1 : t.includes(e);
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 r = new RegExp("[?&]" + t + "=([^&#]*)", "i").exec(window.location.href);
562
- return r ? decodeURIComponent(r[1]) : null;
742
+ const e = new RegExp("[?&]" + t + "=([^&#]*)", "i").exec(window.location.href);
743
+ return e ? decodeURIComponent(e[1]) : null;
563
744
  };
564
- function M(t) {
745
+ function E(t) {
565
746
  return new URLSearchParams(window.location.search).get(t);
566
747
  }
567
- const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
748
+ const x = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
568
749
  __proto__: null,
569
750
  getQueryInfoByName: U,
570
- getQueryParam: M
571
- }, Symbol.toStringTag, { value: "Module" })), $ = {
572
- ...E,
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
- }, D = {
768
+ }, $ = {
588
769
  /**
589
770
  * 处理瀑布流数据,使其适合瀑布流布局展示
590
771
  * @param list 瀑布流数据-数组
591
772
  * @param columnsNum 需要展示的列数
592
773
  * @returns 适合瀑布流布局的数组
593
774
  */
594
- toList(t, e = 2) {
595
- console.log(t, e);
596
- const r = {};
597
- for (let s = 0; s < e; s++)
598
- r[s] = [];
599
- t.forEach((s, l) => r[l % e].push(s));
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 s in r)
602
- o.push(...r[s]);
782
+ for (const n in e)
783
+ o.push(...e[n]);
603
784
  return o;
604
785
  }
605
786
  };
606
787
  export {
607
- L as MoneyFormatter,
788
+ I as MoneyFormatter,
608
789
  A as arrayUtils,
609
- j as base64Utils,
610
- x as booleanUtils,
611
- C as cookieUtils,
612
- _ as dateUtils,
613
- N as downloadUtils,
614
- B as elementUtils,
615
- I as letterUtils,
616
- T as numberUtils,
617
- v as objectUtils,
618
- F as phoneUtils,
619
- P as randomUtils,
620
- k as storageUtils,
621
- R as stringUtils,
622
- $ as urlUtils,
623
- D as waterfallUtils
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
  };
@@ -1 +1 @@
1
- (function(o,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(o=typeof globalThis<"u"?globalThis:o||self,p(o.yhkitUtils={}))})(this,function(o){"use strict";const m=Object.assign({unique(t){return t?Array.from(new Set(t)):[]},isExist(t,e){return!t||!e?!1:t.indexOf(e)!==-1},countOfAppear(t,e){let r=0;for(const n of t)n===e&&r++;return r},sort(t,e="asc"){return t?t.sort((r,n)=>e==="asc"?r>n?1:-1:r<n?1:-1):[]},shuffle(t){if(!t)return[];for(let e=t.length-1;e>0;e--){const r=Math.floor(Math.random()*(e+1));[t[e],t[r]]=[t[r],t[e]]}return t}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:t=>{if(!t||!t.length)return{};const e={};return t.forEach(r=>{const n=Object.assign({label:r.label,text:r.label},r);e[r==null?void 0:r.value]=n}),e}},Symbol.toStringTag,{value:"Module"}))}),w={toBlob(t,e="",r=512){const i=(t.split(",")[1]||t).replace(/-/g,"+").replace(/_/g,"/"),u="=".repeat((4-i.length%4)%4),g=i+u;try{const c=atob(g),h=[];for(let f=0;f<c.length;f+=r){const s=c.slice(f,f+r),a=new Array(s.length);for(let l=0;l<s.length;l++)a[l]=s.charCodeAt(l);const d=new Uint8Array(a);h.push(d)}return new Blob(h,{type:e})}catch(c){return console.error("Failed to convert base64 to blob:",c),null}},toFile(t,e="file.txt",r="text/plain"){const i=t.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),u="=".repeat((4-i.length%4)%4),g=i+u,c=atob(g),h=[];for(let s=0;s<c.length;s+=512){const a=c.slice(s,s+512),d=new Array(a.length);for(let l=0;l<a.length;l++)d[l]=a.charCodeAt(l);h.push(new Uint8Array(d))}const f=new Blob(h,{type:r});return new File([f],e,{type:r})}},U={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 e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=window.innerHeight&&e.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 e=document.cookie.match(new RegExp("(^| )"+t+"=([^;]+)"));return e?decodeURIComponent(e[2]):null},setCookie(t,e,r=7){const n=new Date;n.setTime(n.getTime()+r*24*60*60*1e3),document.cookie=`${t}=${encodeURIComponent(e)};expires=${n.toUTCString()};path=/`},deleteCookie(t){this.setCookie(t,"",-1)}},O={getTimeString(t,e=!1){return e?new Date().toLocaleString(t,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(t,e){const r=new Date(t).getTime(),n=new Date(e).getTime();return r>n?Math.abs(Math.floor((r-n)/(24*3600*1e3))):Math.abs(Math.floor((n-r)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},M={saveAsBlob(t,e){const r=document.createElement("a"),n=window.URL.createObjectURL(t);r.href=n,r.download=e,document.body.appendChild(r),r.click(),URL.revokeObjectURL(n),document.body.removeChild(r)}},j={getOffsetTop(t){if(!t)throw new Error("Element is not provided");if(t instanceof SVGElement){const r=t.getBoundingClientRect(),n=window.pageYOffset||document.documentElement.scrollTop;return r.top+n}let e=0;for(;t;)e+=t.offsetTop,t=t.offsetParent;return e}},E={sortFromA2Z(t){return t!=null&&t.length?t.sort((r,n)=>{const i=r.toUpperCase(),u=n.toUpperCase();return i<u?-1:i>u?1:0}):void 0}};class A{static toStandardFormat(e){try{const r=typeof e=="string"?parseFloat(e):e;if(isNaN(r))throw new Error("输入不是有效的数字");if(!isFinite(r))throw new Error("输入是无穷大");return r.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}catch(r){return console.error("格式化失败:",r),"格式错误"}}static toChineseFormat(e){try{const r=typeof e=="string"?parseFloat(e):e;if(isNaN(r))throw new Error("输入不是有效的数字");if(r>9999999999999e-2||r<-9999999999999e-2)throw new Error("输入数字超出范围");const n=r<0,i=Math.abs(r),u=Math.floor(i),g=Math.round((i-u)*100),c=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],h=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],f=["角","分"];let s="",a=u;if(a===0)s=c[0];else{let y=0;for(;a>0;){const b=a%10;b!==0?s=c[b]+h[y]+s:s.charAt(0)!==c[0]&&(s=c[b]+s),a=Math.floor(a/10),y++}s=s.replace(/零+/g,"零"),s=s.replace(/零+$/,"")}let d="";if(g>0){const y=Math.floor(g/10),b=g%10;y>0&&(d+=c[y]+f[0]),b>0&&(d+=c[b]+f[1])}else d="整";let l=(n?"负":"")+s+"圆"+d;return l==="零圆整"&&(l="零圆"),l}catch(r){return console.error("转换失败:",r),"格式错误"}}}const C={...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)}},_={isEmptyObject(t){return t?Object.keys(t).length===0&&t.constructor===Object:!0}},N={desensitize(t){return t?t.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||t.slice(0,3)+"****"+t.slice(7):""}},T={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(t,e){return Math.floor(Math.random()*(e-t+1))+t},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},B={getLocal(t){return localStorage.getItem(t)},setLocal(t,e){localStorage.setItem(t,e)},removeLocal(t){localStorage.removeItem(t)},getSession(t){return sessionStorage.getItem(t)},setSession(t,e){sessionStorage.setItem(t,e)},removeSession(t){sessionStorage.removeItem(t)}},I={isExist(t,e){if(!t||!e)return!1;const r=t.split(",");return console.log("判断某元素是否在字符串中",r.indexOf(e)===-1),r.indexOf(e)!==-1},includes(t,e){return!t||!e?!1:t.includes(e)},isJSON(t){try{return JSON.parse(t),!0}catch{return!1}}},L=t=>{const r=new RegExp("[?&]"+t+"=([^&#]*)","i").exec(window.location.href);return r?decodeURIComponent(r[1]):null};function k(t){return new URLSearchParams(window.location.search).get(t)}const v={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:L,getQueryParam:k},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},F={toList(t,e=2){console.log(t,e);const r={};for(let i=0;i<e;i++)r[i]=[];t.forEach((i,u)=>r[u%e].push(i));const n=[];for(const i in r)n.push(...r[i]);return n}};o.MoneyFormatter=A,o.arrayUtils=m,o.base64Utils=w,o.booleanUtils=U,o.cookieUtils=S,o.dateUtils=O,o.downloadUtils=M,o.elementUtils=j,o.letterUtils=E,o.numberUtils=C,o.objectUtils=_,o.phoneUtils=N,o.randomUtils=T,o.storageUtils=B,o.stringUtils=I,o.urlUtils=v,o.waterfallUtils=F,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yh-kit/utils",
3
3
  "private": false,
4
- "version": "1.5.0",
4
+ "version": "1.6.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -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
  };
@@ -1,12 +0,0 @@
1
- /**
2
- * 元素相关工具函数
3
- */
4
- export declare const elementUtils: {
5
- /**
6
- * 获取元素相对于文档顶部的偏移量(距离)
7
- * 处理了SVG元素的特殊情况。
8
- * @param el 元素
9
- * @returns 偏移量(距离值)
10
- */
11
- getOffsetTop(el: HTMLElement): number;
12
- };