@yh-kit/utils 1.6.1 → 1.7.1

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,14 +1,14 @@
1
1
  const y = (e) => {
2
2
  if (!e || !e.length) return {};
3
- const r = {};
3
+ const n = {};
4
4
  return e.forEach((t) => {
5
- const n = Object.assign({ label: t.label, text: t.label }, t);
6
- r[t == null ? void 0 : t.value] = n;
7
- }), r;
5
+ const r = Object.assign({ label: t.label, text: t.label }, t);
6
+ n[t == null ? void 0 : t.value] = r;
7
+ }), n;
8
8
  }, b = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
9
9
  __proto__: null,
10
10
  toEnumObj: y
11
- }, Symbol.toStringTag, { value: "Module" })), L = Object.assign(
11
+ }, Symbol.toStringTag, { value: "Module" })), m = Object.assign(
12
12
  {
13
13
  /**
14
14
  * 数组去重
@@ -24,8 +24,8 @@ const y = (e) => {
24
24
  * @param element 查询元素
25
25
  * @returns 是否存在。true 存在;false 不存在
26
26
  */
27
- isExist(e, r) {
28
- return !e || !r ? !1 : e.indexOf(r) !== -1;
27
+ isExist(e, n) {
28
+ return !e || !n ? !1 : e.indexOf(n) !== -1;
29
29
  },
30
30
  /**
31
31
  * 统计数组中某元素出现的次数:对于大型数组,手动循环的性能略优于 filter 和 reduce。
@@ -33,10 +33,10 @@ const y = (e) => {
33
33
  * @param target 目标元素
34
34
  * @returns 出现次数
35
35
  */
36
- countOfAppear(e, r) {
36
+ countOfAppear(e, n) {
37
37
  let t = 0;
38
- for (const n of e)
39
- n === r && t++;
38
+ for (const r of e)
39
+ r === n && t++;
40
40
  return t;
41
41
  },
42
42
  /**
@@ -45,13 +45,13 @@ const y = (e) => {
45
45
  * @param element 元素
46
46
  * @returns 位置数组
47
47
  */
48
- indexsOfAppear(e, r) {
48
+ indexsOfAppear(e, n) {
49
49
  let t = -1;
50
- const n = [];
50
+ const r = [];
51
51
  do
52
- t = e.indexOf(r, t + 1), t !== -1 && n.push(t);
52
+ t = e.indexOf(n, t + 1), t !== -1 && r.push(t);
53
53
  while (t !== -1);
54
- return n;
54
+ return r;
55
55
  },
56
56
  /**
57
57
  * 数组排序-默认升序
@@ -59,8 +59,8 @@ const y = (e) => {
59
59
  * @param order 排序方式:asc 升序;desc 降序
60
60
  * @returns 排序后的数组
61
61
  */
62
- sort(e, r = "asc") {
63
- return e ? e.sort((t, n) => r === "asc" ? t > n ? 1 : -1 : t < n ? 1 : -1) : [];
62
+ sort(e, n = "asc") {
63
+ return e ? e.sort((t, r) => n === "asc" ? t > r ? 1 : -1 : t < r ? 1 : -1) : [];
64
64
  },
65
65
  /**
66
66
  * 数组乱序(洗牌算法)
@@ -76,9 +76,9 @@ const y = (e) => {
76
76
  shuffle(e) {
77
77
  if (!e)
78
78
  return [];
79
- for (let r = e.length - 1; r > 0; r--) {
80
- const t = Math.floor(Math.random() * (r + 1));
81
- [e[r], e[t]] = [e[t], e[r]];
79
+ for (let n = e.length - 1; n > 0; n--) {
80
+ const t = Math.floor(Math.random() * (n + 1));
81
+ [e[n], e[t]] = [e[t], e[n]];
82
82
  }
83
83
  return e;
84
84
  },
@@ -97,12 +97,42 @@ const y = (e) => {
97
97
  */
98
98
  getMinValue(e) {
99
99
  return e ? Math.min(...e) : 0;
100
+ },
101
+ /**
102
+ * 获取数组中的最小值和索引
103
+ * @param array 数组
104
+ * @returns 最小值和索引
105
+ */
106
+ getMinValueAndIndex(e) {
107
+ if (e.length === 0) return { value: 0, index: 0 };
108
+ const n = {
109
+ /** 最小值 */
110
+ value: e[0],
111
+ /** 最小值索引 */
112
+ index: 0
113
+ };
114
+ for (let t = 1, r = e.length; t < r; t++) {
115
+ const o = e[t];
116
+ n.value > o && (n.value = o, n.index = t);
117
+ }
118
+ return n;
119
+ },
120
+ /**
121
+ * 获取数组中的最大值和索引
122
+ * @param arr 数组
123
+ * @returns 最大值和索引
124
+ */
125
+ getMaxValueAndIndex(e) {
126
+ return e.length === 0 ? { value: 0, index: 0 } : e.reduce(
127
+ (n, t, r) => t < n.value ? { value: t, index: r } : n,
128
+ { value: e[0], index: 0 }
129
+ );
100
130
  }
101
131
  },
102
132
  {
103
133
  ...b
104
134
  }
105
- ), A = {
135
+ ), E = {
106
136
  /**
107
137
  * 将Base64编码的字符串转换为Blob对象。
108
138
  * Blob对象用于表示二进制大型对象,可以在浏览器环境中处理大文件或二进制数据。
@@ -112,20 +142,20 @@ const y = (e) => {
112
142
  * @param sliceSize 可选参数,表示分片大小,默认为512字节。用于控制每次处理的Base64字符串长度,以优化大文件的处理。
113
143
  * @returns 返回转换后的Blob对象,如果转换失败,则返回null。
114
144
  */
115
- toBlob(e, r = "", t = 512) {
116
- const o = (e.split(",")[1] || e).replace(/-/g, "+").replace(/_/g, "/"), s = "=".repeat((4 - o.length % 4) % 4), c = o + s;
145
+ toBlob(e, n = "", t = 512) {
146
+ const o = (e.split(",")[1] || e).replace(/-/g, "+").replace(/_/g, "/"), s = "=".repeat((4 - o.length % 4) % 4), l = o + s;
117
147
  try {
118
- const i = atob(c), l = [];
119
- for (let h = 0; h < i.length; h += t) {
120
- const a = i.slice(h, h + t), d = new Array(a.length);
121
- for (let u = 0; u < a.length; u++)
122
- d[u] = a.charCodeAt(u);
123
- const f = new Uint8Array(d);
124
- l.push(f);
148
+ const c = atob(l), i = [];
149
+ for (let g = 0; g < c.length; g += t) {
150
+ const a = c.slice(g, g + t), u = new Array(a.length);
151
+ for (let d = 0; d < a.length; d++)
152
+ u[d] = a.charCodeAt(d);
153
+ const f = new Uint8Array(u);
154
+ i.push(f);
125
155
  }
126
- return new Blob(l, { type: r });
127
- } catch (i) {
128
- return console.error("Failed to convert base64 to blob:", i), null;
156
+ return new Blob(i, { type: n });
157
+ } catch (c) {
158
+ return console.error("Failed to convert base64 to blob:", c), null;
129
159
  }
130
160
  },
131
161
  /**
@@ -138,18 +168,18 @@ const y = (e) => {
138
168
  * @param mimeType MIME类型,默认为"text/plain"。
139
169
  * @returns 返回一个File对象,包含解码后的数据。
140
170
  */
141
- toFile(e, r = "file.txt", t = "text/plain") {
142
- const o = e.replace(/^data:.+;base64,/, "").replace(/-/g, "+").replace(/_/g, "/"), s = "=".repeat((4 - o.length % 4) % 4), c = o + s, i = atob(c), l = [];
143
- for (let a = 0; a < i.length; a += 512) {
144
- const d = i.slice(a, a + 512), f = new Array(d.length);
145
- for (let u = 0; u < d.length; u++)
146
- f[u] = d.charCodeAt(u);
147
- l.push(new Uint8Array(f));
171
+ toFile(e, n = "file.txt", t = "text/plain") {
172
+ const o = e.replace(/^data:.+;base64,/, "").replace(/-/g, "+").replace(/_/g, "/"), s = "=".repeat((4 - o.length % 4) % 4), l = o + s, c = atob(l), i = [];
173
+ for (let a = 0; a < c.length; a += 512) {
174
+ const u = c.slice(a, a + 512), f = new Array(u.length);
175
+ for (let d = 0; d < u.length; d++)
176
+ f[d] = u.charCodeAt(d);
177
+ i.push(new Uint8Array(f));
148
178
  }
149
- const h = new Blob(l, { type: t });
150
- return new File([h], r, { type: t });
179
+ const g = new Blob(i, { type: t });
180
+ return new File([g], n, { type: t });
151
181
  }
152
- }, m = {
182
+ }, w = {
153
183
  /**
154
184
  * 检查是否为空字符串
155
185
  * @param str 要检查的字符串
@@ -268,8 +298,8 @@ const y = (e) => {
268
298
  * @returns true 表示元素在可视区域内,false 表示元素不在可视区域内
269
299
  */
270
300
  isInViewport(e) {
271
- const r = e.getBoundingClientRect();
272
- return r.top >= 0 && r.left >= 0 && r.bottom <= window.innerHeight && r.right <= window.innerWidth;
301
+ const n = e.getBoundingClientRect();
302
+ return n.top >= 0 && n.left >= 0 && n.bottom <= window.innerHeight && n.right <= window.innerWidth;
273
303
  },
274
304
  /**
275
305
  * 判断是否为闰年
@@ -293,7 +323,7 @@ const y = (e) => {
293
323
  isMobile() {
294
324
  return /Mobi|Android|iPhone/i.test(navigator.userAgent);
295
325
  }
296
- }, v = {
326
+ }, L = {
297
327
  /**
298
328
  * 通过传入的name获取cookie的值
299
329
  * @param name cookie的name
@@ -301,8 +331,8 @@ const y = (e) => {
301
331
  */
302
332
  getCookie(e) {
303
333
  if (!e) return;
304
- const r = document.cookie.match(new RegExp("(^| )" + e + "=([^;]+)"));
305
- return r ? decodeURIComponent(r[2]) : null;
334
+ const n = document.cookie.match(new RegExp("(^| )" + e + "=([^;]+)"));
335
+ return n ? decodeURIComponent(n[2]) : null;
306
336
  },
307
337
  /**
308
338
  * 设置 cookie
@@ -311,9 +341,9 @@ const y = (e) => {
311
341
  * @param days cookie的过期时间,默认7天。如果为0,则表示cookie在会话结束时过期。如果为负数,则表示cookie已过期。
312
342
  * @returns void
313
343
  */
314
- setCookie(e, r, t = 7) {
315
- const n = /* @__PURE__ */ new Date();
316
- n.setTime(n.getTime() + t * 24 * 60 * 60 * 1e3), document.cookie = `${e}=${encodeURIComponent(r)};expires=${n.toUTCString()};path=/`;
344
+ setCookie(e, n, t = 7) {
345
+ const r = /* @__PURE__ */ new Date();
346
+ r.setTime(r.getTime() + t * 24 * 60 * 60 * 1e3), document.cookie = `${e}=${encodeURIComponent(n)};expires=${r.toUTCString()};path=/`;
317
347
  },
318
348
  /**
319
349
  * 删除cookie
@@ -323,15 +353,15 @@ const y = (e) => {
323
353
  deleteCookie(e) {
324
354
  this.setCookie(e, "", -1);
325
355
  }
326
- }, R = {
356
+ }, j = {
327
357
  /**
328
358
  * 获取当前时间字符串
329
359
  * @param locales 区域设置。如:'zh-CN','en-US',"chinese"。默认'zh-CN'。
330
360
  * @param hour12 是否使用12小时制。默认false,使用24小时制。
331
361
  * @returns 当前时间的字符串。如:'2025/5/27 16:54:45'
332
362
  */
333
- getTimeString(e, r = !1) {
334
- return r ? (/* @__PURE__ */ new Date()).toLocaleString(e, { hour12: !0 }) : (/* @__PURE__ */ new Date()).toLocaleString("chinese", { hour12: !1 });
363
+ getTimeString(e, n = !1) {
364
+ return n ? (/* @__PURE__ */ new Date()).toLocaleString(e, { hour12: !0 }) : (/* @__PURE__ */ new Date()).toLocaleString("chinese", { hour12: !1 });
335
365
  },
336
366
  /**
337
367
  * 计算两个日期相差天数
@@ -339,9 +369,9 @@ const y = (e) => {
339
369
  * @param date2 日期2
340
370
  * @returns 相差天数
341
371
  */
342
- diffDays(e, r) {
343
- const t = new Date(e).getTime(), n = new Date(r).getTime();
344
- return t > n ? Math.abs(Math.floor((t - n) / (24 * 3600 * 1e3))) : Math.abs(Math.floor((n - t) / (24 * 3600 * 1e3)));
372
+ diffDays(e, n) {
373
+ const t = new Date(e).getTime(), r = new Date(n).getTime();
374
+ return t > r ? Math.abs(Math.floor((t - r) / (24 * 3600 * 1e3))) : Math.abs(Math.floor((r - t) / (24 * 3600 * 1e3)));
345
375
  },
346
376
  /**
347
377
  * 生成唯一ID(时间戳+随机数)
@@ -357,9 +387,9 @@ const y = (e) => {
357
387
  * @param day 日期
358
388
  * @returns 当年的第几天
359
389
  */
360
- getWhichDays(e, r, t) {
361
- let n = t;
362
- for (let o = 1; o < r; o++)
390
+ getWhichDays(e, n, t) {
391
+ let r = t;
392
+ for (let o = 1; o < n; o++)
363
393
  switch (o) {
364
394
  case 1:
365
395
  case 3:
@@ -368,18 +398,18 @@ const y = (e) => {
368
398
  case 8:
369
399
  case 10:
370
400
  case 12:
371
- n += 31;
401
+ r += 31;
372
402
  break;
373
403
  case 2:
374
- m.isLeapYear(e) ? n += 29 : n += 28;
404
+ w.isLeapYear(e) ? r += 29 : r += 28;
375
405
  break;
376
406
  default:
377
- n += 30;
407
+ r += 30;
378
408
  break;
379
409
  }
380
- return n;
410
+ return r;
381
411
  }
382
- }, j = {
412
+ }, R = {
383
413
  /**
384
414
  * 获取元素相对于文档顶部的偏移量(距离)
385
415
  * 处理了SVG元素的特殊情况。
@@ -390,13 +420,13 @@ const y = (e) => {
390
420
  if (!e)
391
421
  throw new Error("Element is not provided");
392
422
  if (e instanceof SVGElement) {
393
- const t = e.getBoundingClientRect(), n = window.pageYOffset || document.documentElement.scrollTop;
394
- return t.top + n;
423
+ const t = e.getBoundingClientRect(), r = window.pageYOffset || document.documentElement.scrollTop;
424
+ return t.top + r;
395
425
  }
396
- let r = 0;
426
+ let n = 0;
397
427
  for (; e; )
398
- r += e.offsetTop, e = e.offsetParent;
399
- return r;
428
+ n += e.offsetTop, e = e.offsetParent;
429
+ return n;
400
430
  },
401
431
  /**
402
432
  * 获取文档的滚动值
@@ -419,9 +449,9 @@ const y = (e) => {
419
449
  */
420
450
  getPageValue(e) {
421
451
  e = e || window.event;
422
- const r = e.pageX || e.clientX + this.getScrollValue().scrollLeft, t = e.pageY || e.clientY + this.getScrollValue().scrollTop;
452
+ const n = e.pageX || e.clientX + this.getScrollValue().scrollLeft, t = e.pageY || e.clientY + this.getScrollValue().scrollTop;
423
453
  return {
424
- pageX: r,
454
+ pageX: n,
425
455
  pageY: t
426
456
  };
427
457
  },
@@ -433,8 +463,8 @@ const y = (e) => {
433
463
  * @param fn 事件处理函数
434
464
  */
435
465
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
436
- addEventListener(e, r, t) {
437
- e.addEventListener ? e.addEventListener(r, t) : e.attachEvent ? e.attachEvent("on" + r, t) : e["on" + r] = t;
466
+ addEventListener(e, n, t) {
467
+ e.addEventListener ? e.addEventListener(n, t) : e.attachEvent ? e.attachEvent("on" + n, t) : e["on" + n] = t;
438
468
  }
439
469
  }, C = {
440
470
  /**
@@ -442,9 +472,9 @@ const y = (e) => {
442
472
  * @param blob blob对象
443
473
  * @param filename 文件名
444
474
  */
445
- saveAsBlob(e, r) {
446
- const t = document.createElement("a"), n = window.URL.createObjectURL(e);
447
- t.href = n, t.download = r, document.body.appendChild(t), t.click(), URL.revokeObjectURL(n), document.body.removeChild(t);
475
+ saveAsBlob(e, n) {
476
+ const t = document.createElement("a"), r = window.URL.createObjectURL(e);
477
+ t.href = r, t.download = n, document.body.appendChild(t), t.click(), URL.revokeObjectURL(r), document.body.removeChild(t);
448
478
  }
449
479
  }, k = {
450
480
  /**
@@ -453,8 +483,8 @@ const y = (e) => {
453
483
  * @returns
454
484
  */
455
485
  sortFromA2Z(e) {
456
- return e != null && e.length ? e.sort((t, n) => {
457
- const o = t.toUpperCase(), s = n.toUpperCase();
486
+ return e != null && e.length ? e.sort((t, r) => {
487
+ const o = t.toUpperCase(), s = r.toUpperCase();
458
488
  return o < s ? -1 : o > s ? 1 : 0;
459
489
  }) : void 0;
460
490
  }
@@ -478,14 +508,14 @@ const y = (e) => {
478
508
  * @param targetLng 目标经度
479
509
  * @returns 距离值 单位:km
480
510
  */
481
- getDistance(e, r, t, n) {
482
- const o = this.degrees2Radians(e), s = this.degrees2Radians(t), c = o - s, i = this.degrees2Radians(r) - this.degrees2Radians(n);
483
- let l = 2 * Math.asin(
511
+ getDistance(e, n, t, r) {
512
+ const o = this.degrees2Radians(e), s = this.degrees2Radians(t), l = o - s, c = this.degrees2Radians(n) - this.degrees2Radians(r);
513
+ let i = 2 * Math.asin(
484
514
  Math.sqrt(
485
- Math.pow(Math.sin(c / 2), 2) + Math.cos(o) * Math.cos(s) * Math.pow(Math.sin(i / 2), 2)
515
+ Math.pow(Math.sin(l / 2), 2) + Math.cos(o) * Math.cos(s) * Math.pow(Math.sin(c / 2), 2)
486
516
  )
487
517
  );
488
- return l = l * 6378.137, l = Math.round(l * 1e4) / 1e4, l = +l.toFixed(2), console.log("经纬度计算的距离为:" + l), l;
518
+ return i = i * 6378.137, i = Math.round(i * 1e4) / 1e4, i = +i.toFixed(2), console.log("经纬度计算的距离为:" + i), i;
489
519
  },
490
520
  /**
491
521
  * 计算两个坐标点之间的距离(Haversine公式)
@@ -502,23 +532,23 @@ const y = (e) => {
502
532
  * @param unit 距离单位,默认单位为千米。可选值:km(千米)、m(米)、mi(英里)、nmi(海里)
503
533
  * @returns 距离值
504
534
  */
505
- calculateDistanceByHaversine(e, r, t = "km") {
506
- const n = this, o = e.longitude ?? e.lng, s = e.latitude ?? e.lat, c = r.longitude ?? r.lng, i = r.latitude ?? r.lat;
507
- if (o === void 0 || s === void 0 || c === void 0 || i === void 0)
535
+ calculateDistanceByHaversine(e, n, t = "km") {
536
+ const r = this, o = e.longitude ?? e.lng, s = e.latitude ?? e.lat, l = n.longitude ?? n.lng, c = n.latitude ?? n.lat;
537
+ if (o === void 0 || s === void 0 || l === void 0 || c === void 0)
508
538
  throw new Error("无效的坐标格式,缺少经纬度信息");
509
- const l = 6371, h = n.degrees2Radians(s), a = n.degrees2Radians(i), d = n.degrees2Radians(i - s), f = n.degrees2Radians(c - o), u = Math.sin(d / 2) * Math.sin(d / 2) + Math.cos(h) * Math.cos(a) * Math.sin(f / 2) * Math.sin(f / 2), p = 2 * Math.atan2(Math.sqrt(u), Math.sqrt(1 - u)), g = l * p;
539
+ const i = 6371, g = r.degrees2Radians(s), a = r.degrees2Radians(c), u = r.degrees2Radians(c - s), f = r.degrees2Radians(l - o), d = Math.sin(u / 2) * Math.sin(u / 2) + Math.cos(g) * Math.cos(a) * Math.sin(f / 2) * Math.sin(f / 2), p = 2 * Math.atan2(Math.sqrt(d), Math.sqrt(1 - d)), h = i * p;
510
540
  switch (t) {
511
541
  case "m":
512
- return g * 1e3;
542
+ return h * 1e3;
513
543
  // 米
514
544
  case "mi":
515
- return g * 0.621371;
545
+ return h * 0.621371;
516
546
  // 英里
517
547
  case "nmi":
518
- return g * 0.539957;
548
+ return h * 0.539957;
519
549
  // 海里
520
550
  default:
521
- return g;
551
+ return h;
522
552
  }
523
553
  },
524
554
  /**
@@ -528,31 +558,31 @@ const y = (e) => {
528
558
  * @param closed 是否闭合路径,默认不闭合
529
559
  * @returns 距离结果对象。包含每个距离段的数组(segments)和总距离(total)。
530
560
  */
531
- calculateDistancesByHaversine(e, r = "km", t = !1) {
561
+ calculateDistancesByHaversine(e, n = "km", t = !1) {
532
562
  if (e.length < 2)
533
563
  return { segments: [], total: 0 };
534
- const n = [];
564
+ const r = [];
535
565
  let o = 0;
536
566
  for (let s = 0; s < e.length - 1; s++) {
537
- const c = this.calculateDistanceByHaversine(e[s], e[s + 1], r);
538
- n.push(c), o += c;
567
+ const l = this.calculateDistanceByHaversine(e[s], e[s + 1], n);
568
+ r.push(l), o += l;
539
569
  }
540
570
  if (t && e.length > 2) {
541
- const s = this.calculateDistanceByHaversine(e[e.length - 1], e[0], r);
542
- n.push(s), o += s;
571
+ const s = this.calculateDistanceByHaversine(e[e.length - 1], e[0], n);
572
+ r.push(s), o += s;
543
573
  }
544
- return { segments: n, total: o };
574
+ return { segments: r, total: o };
545
575
  }
546
576
  };
547
- class T {
577
+ class I {
548
578
  /**
549
579
  * 转换为标准金额格式(带千分位和两位小数)
550
580
  * @param num 要转换的数字
551
581
  * @returns 格式化后的字符串
552
582
  */
553
- static toStandardFormat(r) {
583
+ static toStandardFormat(n) {
554
584
  try {
555
- const t = typeof r == "string" ? parseFloat(r) : r;
585
+ const t = typeof n == "string" ? parseFloat(n) : n;
556
586
  if (isNaN(t))
557
587
  throw new Error("输入不是有效的数字");
558
588
  if (!isFinite(t))
@@ -567,46 +597,46 @@ class T {
567
597
  * @param num 要转换的数字
568
598
  * @returns 中文大写金额字符串
569
599
  */
570
- static toChineseFormat(r) {
600
+ static toChineseFormat(n) {
571
601
  try {
572
- const t = typeof r == "string" ? parseFloat(r) : r;
602
+ const t = typeof n == "string" ? parseFloat(n) : n;
573
603
  if (isNaN(t))
574
604
  throw new Error("输入不是有效的数字");
575
605
  if (t > 9999999999999e-2 || t < -9999999999999e-2)
576
606
  throw new Error("输入数字超出范围");
577
- const n = t < 0, o = Math.abs(t), s = Math.floor(o), c = Math.round((o - s) * 100), i = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"], l = ["", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟"], h = ["角", "分"];
578
- let a = "", d = s;
579
- if (d === 0)
580
- a = i[0];
607
+ const r = t < 0, o = Math.abs(t), s = Math.floor(o), l = Math.round((o - s) * 100), c = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"], i = ["", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟"], g = ["角", "分"];
608
+ let a = "", u = s;
609
+ if (u === 0)
610
+ a = c[0];
581
611
  else {
582
612
  let p = 0;
583
- for (; d > 0; ) {
584
- const g = d % 10;
585
- g !== 0 ? a = i[g] + l[p] + a : a.charAt(0) !== i[0] && (a = i[g] + a), d = Math.floor(d / 10), p++;
613
+ for (; u > 0; ) {
614
+ const h = u % 10;
615
+ h !== 0 ? a = c[h] + i[p] + a : a.charAt(0) !== c[0] && (a = c[h] + a), u = Math.floor(u / 10), p++;
586
616
  }
587
617
  a = a.replace(/零+/g, "零"), a = a.replace(/零+$/, "");
588
618
  }
589
619
  let f = "";
590
- if (c > 0) {
591
- const p = Math.floor(c / 10), g = c % 10;
592
- p > 0 && (f += i[p] + h[0]), g > 0 && (f += i[g] + h[1]);
620
+ if (l > 0) {
621
+ const p = Math.floor(l / 10), h = l % 10;
622
+ p > 0 && (f += c[p] + g[0]), h > 0 && (f += c[h] + g[1]);
593
623
  } else
594
624
  f = "整";
595
- let u = (n ? "负" : "") + a + "圆" + f;
596
- return u === "零圆整" && (u = "零圆"), u;
625
+ let d = (r ? "负" : "") + a + "圆" + f;
626
+ return d === "零圆整" && (d = "零圆"), d;
597
627
  } catch (t) {
598
628
  return console.error("转换失败:", t), "格式错误";
599
629
  }
600
630
  }
601
631
  }
602
- const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
632
+ const M = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], x = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
603
633
  __proto__: null,
604
- toLetter: w
634
+ toLetter: M
605
635
  }, Symbol.toStringTag, { value: "Module" })), S = (e) => e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
606
636
  __proto__: null,
607
637
  toMoney: S
608
638
  }, Symbol.toStringTag, { value: "Module" })), _ = {
609
- ...M,
639
+ ...x,
610
640
  ...O,
611
641
  /**
612
642
  * 判断是否为数字
@@ -616,7 +646,7 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
616
646
  isNumber(e) {
617
647
  return typeof e == "number" && !isNaN(e);
618
648
  }
619
- }, I = {
649
+ }, T = {
620
650
  /**
621
651
  * 判断对象是否为空
622
652
  * @param obj 对象
@@ -631,9 +661,9 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
631
661
  * @param obj2 目标对象
632
662
  */
633
663
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
634
- copy(e, r) {
664
+ copy(e, n) {
635
665
  for (const t in e)
636
- r[t] = e[t];
666
+ n[t] = e[t];
637
667
  },
638
668
  /**
639
669
  * 对象的深拷贝 把o1 的成员,复制给o2
@@ -641,13 +671,13 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
641
671
  * @param o2
642
672
  */
643
673
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
644
- deepCopy(e, r) {
674
+ deepCopy(e, n) {
645
675
  for (const t in e) {
646
- const n = e[t];
647
- n instanceof Object ? (r[t] = {}, this.deepCopy(n, r[t])) : n instanceof Array ? (r[t] = [], this.deepCopy(n, r[t])) : r[t] = e[t];
676
+ const r = e[t];
677
+ r instanceof Object ? (n[t] = {}, this.deepCopy(r, n[t])) : r instanceof Array ? (n[t] = [], this.deepCopy(r, n[t])) : n[t] = e[t];
648
678
  }
649
679
  }
650
- }, N = {
680
+ }, $ = {
651
681
  /**
652
682
  * 脱敏
653
683
  * @param phone 电话号码/手机号码
@@ -656,7 +686,7 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
656
686
  desensitize(e) {
657
687
  return e ? e.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2") || e.slice(0, 3) + "****" + e.slice(7) : "";
658
688
  }
659
- }, D = {
689
+ }, N = {
660
690
  /**
661
691
  * 生成随机颜色
662
692
  * @returns 随机颜色值
@@ -670,8 +700,8 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
670
700
  * @param max 最大值
671
701
  * @returns 随机数
672
702
  */
673
- int(e, r) {
674
- return Math.floor(Math.random() * (r - e + 1)) + e;
703
+ int(e, n) {
704
+ return Math.floor(Math.random() * (n - e + 1)) + e;
675
705
  },
676
706
  /**
677
707
  * 生成唯一ID(时间戳+随机数)
@@ -681,6 +711,43 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
681
711
  return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
682
712
  }
683
713
  }, P = {
714
+ /**
715
+ * 验证手机号
716
+ */
717
+ mobile: /^1[3-9]\d{9}$/,
718
+ /**
719
+ * 验证邮箱
720
+ */
721
+ email: /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
722
+ /**
723
+ * 验证中文
724
+ */
725
+ chinese: /^[\u4e00-\u9fa5]+$/,
726
+ /**
727
+ * 验证英文
728
+ */
729
+ english: /^[a-zA-Z]+$/,
730
+ /**
731
+ * 验证中文开头其他结束
732
+ */
733
+ chineseStart: /^[\u4e00-\u9fa5]+\w*$/,
734
+ /**
735
+ * 验证正整数
736
+ */
737
+ integer: /^\d+$/,
738
+ /**
739
+ * 验证零+正整数
740
+ */
741
+ integerAndzero: /^(0|[1-9]+[0-9]*)$/,
742
+ /**
743
+ * 验证强密码正则:密码须由大小字母+数字、大小字母+特殊符号、数字+特殊字符等组合,且存在字母时,必须包含大小写字母。长度必须8位以上
744
+ */
745
+ strongPassword: /^(?!.*[\s\p{C}])(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[\d\W])|(?=.*\d)(?=.*[^\w\s])).{8,}$/u,
746
+ /**
747
+ * 验证0.01~0.99正则:最多两位小数。0.1、0.10、0.9、0.90
748
+ */
749
+ decimal: /^0\.(0[1-9]|[1-9][0-9]*)$/
750
+ }, D = {
684
751
  /**
685
752
  * 通过key值获取 localStorage 中存储的某个值
686
753
  * @param key 获取的key
@@ -694,8 +761,8 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
694
761
  * @param key 设置的key
695
762
  * @param value 设置的value
696
763
  */
697
- setLocal(e, r) {
698
- localStorage.setItem(e, r);
764
+ setLocal(e, n) {
765
+ localStorage.setItem(e, n);
699
766
  },
700
767
  /**
701
768
  * 删除localStorage中的某个值
@@ -717,8 +784,8 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
717
784
  * @param key 设置的key
718
785
  * @param value 设置的value
719
786
  */
720
- setSession(e, r) {
721
- sessionStorage.setItem(e, r);
787
+ setSession(e, n) {
788
+ sessionStorage.setItem(e, n);
722
789
  },
723
790
  /**
724
791
  * 删除sessionStorage中的某个值
@@ -734,11 +801,11 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
734
801
  * @param element 查询元素
735
802
  * @returns 是否存在。true 存在;false 不存在
736
803
  */
737
- isExist(e, r) {
738
- if (!e || !r)
804
+ isExist(e, n) {
805
+ if (!e || !n)
739
806
  return !1;
740
807
  const t = e.split(",");
741
- return console.log("判断某元素是否在字符串中", t.indexOf(r) === -1), t.indexOf(r) !== -1;
808
+ return console.log("判断某元素是否在字符串中", t.indexOf(n) === -1), t.indexOf(n) !== -1;
742
809
  },
743
810
  /**
744
811
  * 判断某元素是否在字符串中-比isExist()方法更高效。
@@ -746,8 +813,8 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
746
813
  * @param element 查询元素
747
814
  * @returns 是否存在。true 存在;false 不存在
748
815
  */
749
- includes(e, r) {
750
- return !e || !r ? !1 : e.includes(r);
816
+ includes(e, n) {
817
+ return !e || !n ? !1 : e.includes(n);
751
818
  },
752
819
  /**
753
820
  * 判断字符串是否为 JSON
@@ -767,13 +834,13 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
767
834
  * @param element 元素
768
835
  * @returns 位置数组
769
836
  */
770
- indexsOfAppear(e, r) {
837
+ indexsOfAppear(e, n) {
771
838
  let t = -1;
772
- const n = [];
839
+ const r = [];
773
840
  do
774
- t = e.indexOf(r, t + 1), t !== -1 && n.push(t);
841
+ t = e.indexOf(n, t + 1), t !== -1 && r.push(t);
775
842
  while (t !== -1);
776
- return n;
843
+ return r;
777
844
  },
778
845
  /**
779
846
  * 获取字符串中出现次数最多的字符和次数
@@ -781,32 +848,32 @@ const w = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], M = /*
781
848
  * @returns 数组,第一个元素为出现次数,第二个元素为出现次数最多的字符
782
849
  */
783
850
  getMaxTimesAndVal(e) {
784
- const r = [0, ""], t = {};
851
+ const n = [0, ""], t = {};
785
852
  for (let s = 0; s < e.length; s++) {
786
- const c = e.charAt(s);
787
- t[c] ? t[c]++ : t[c] = 1;
853
+ const l = e.charAt(s);
854
+ t[l] ? t[l]++ : t[l] = 1;
788
855
  }
789
- let n = 1;
856
+ let r = 1;
790
857
  for (const s in t)
791
- n < t[s] && (n = t[s]);
858
+ r < t[s] && (r = t[s]);
792
859
  const o = [];
793
860
  for (const s in t)
794
- n == t[s] && o.push(s);
795
- return r[0] = n, r[1] = o.join(), r;
861
+ r == t[s] && o.push(s);
862
+ return n[0] = r, n[1] = o.join(), n;
796
863
  }
797
- }, U = (e) => {
864
+ }, A = (e) => {
798
865
  const t = new RegExp("[?&]" + e + "=([^&#]*)", "i").exec(window.location.href);
799
866
  return t ? decodeURIComponent(t[1]) : null;
800
867
  };
801
- function E(e) {
868
+ function v(e) {
802
869
  return new URLSearchParams(window.location.search).get(e);
803
870
  }
804
- const x = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
871
+ const U = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
805
872
  __proto__: null,
806
- getQueryInfoByName: U,
807
- getQueryParam: E
873
+ getQueryInfoByName: A,
874
+ getQueryParam: v
808
875
  }, Symbol.toStringTag, { value: "Module" })), V = {
809
- ...x,
876
+ ...U,
810
877
  /**
811
878
  * 获取当前域名
812
879
  * @returns 当前url链接的host信息
@@ -821,42 +888,61 @@ const x = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
821
888
  getPath() {
822
889
  return window.location.pathname;
823
890
  }
824
- }, $ = {
891
+ }, z = {
825
892
  /**
826
- * 处理瀑布流数据,使其适合瀑布流布局展示
893
+ * 处理瀑布流数据,使其竖向瀑布流布局呈现横向瀑布流的展现形式。适用于 column-gap: 20rpx; column-count: 2; 布局的瀑布流
827
894
  * @param list 瀑布流数据-数组
828
895
  * @param columnsNum 需要展示的列数
829
896
  * @returns 适合瀑布流布局的数组
830
897
  */
831
- toList(e, r = 2) {
832
- console.log(e, r);
898
+ toList(e, n = 2) {
899
+ console.log(e, n);
833
900
  const t = {};
834
- for (let o = 0; o < r; o++)
901
+ for (let o = 0; o < n; o++)
835
902
  t[o] = [];
836
- e.forEach((o, s) => t[s % r].push(o));
837
- const n = [];
903
+ e.forEach((o, s) => t[s % n].push(o));
904
+ const r = [];
838
905
  for (const o in t)
839
- n.push(...t[o]);
840
- return n;
906
+ r.push(...t[o]);
907
+ return r;
908
+ },
909
+ /**
910
+ * js瀑布流布局
911
+ * @param itemBox 瀑布流容器
912
+ * @param items 瀑布流元素
913
+ * @param step 间距
914
+ */
915
+ jsLayout(e, n, t) {
916
+ const r = e.offsetWidth, o = n[0].offsetWidth, s = parseInt((r / o).toString()), l = (r - o * s) / (s - 1), c = [];
917
+ for (let i = 0, g = n.length; i < g; i++) {
918
+ const a = n[i];
919
+ if (i < s)
920
+ a.style.left = (o + l) * i + "px", c[i] = a.offsetHeight;
921
+ else {
922
+ const { index: u, value: f } = m.getMinValueAndIndex(c);
923
+ a.style.left = (o + l) * u + "px", a.style.top = f + t + "px", c[u] = a.offsetHeight + t + f;
924
+ }
925
+ }
841
926
  }
842
927
  };
843
928
  export {
844
- T as MoneyFormatter,
845
- L as arrayUtils,
846
- A as base64Utils,
847
- m as booleanUtils,
848
- v as cookieUtils,
849
- R as dateUtils,
850
- j as documentUtils,
929
+ I as MoneyFormatter,
930
+ m as arrayUtils,
931
+ E as base64Utils,
932
+ w as booleanUtils,
933
+ L as cookieUtils,
934
+ j as dateUtils,
935
+ R as documentUtils,
851
936
  C as downloadUtils,
852
937
  k as letterUtils,
853
938
  B as mapUtils,
854
939
  _ as numberUtils,
855
- I as objectUtils,
856
- N as phoneUtils,
857
- D as randomUtils,
858
- P as storageUtils,
940
+ T as objectUtils,
941
+ $ as phoneUtils,
942
+ N as randomUtils,
943
+ P as regexpUtils,
944
+ D as storageUtils,
859
945
  F as stringUtils,
860
946
  V as urlUtils,
861
- $ as waterfallUtils
947
+ z as waterfallUtils
862
948
  };
@@ -1 +1 @@
1
- (function(i,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(i=typeof globalThis<"u"?globalThis:i||self,p(i.yhkitUtils={}))})(this,function(i){"use strict";const w=Object.assign({unique(e){return e?Array.from(new Set(e)):[]},isExist(e,n){return!e||!n?!1:e.indexOf(n)!==-1},countOfAppear(e,n){let t=0;for(const r of e)r===n&&t++;return t},indexsOfAppear(e,n){let t=-1;const r=[];do t=e.indexOf(n,t+1),t!==-1&&r.push(t);while(t!==-1);return r},sort(e,n="asc"){return e?e.sort((t,r)=>n==="asc"?t>r?1:-1:t<r?1:-1):[]},shuffle(e){if(!e)return[];for(let n=e.length-1;n>0;n--){const t=Math.floor(Math.random()*(n+1));[e[n],e[t]]=[e[t],e[n]]}return e},getMaxValue(e){return e?Math.max(...e):0},getMinValue(e){return e?Math.min(...e):0}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:e=>{if(!e||!e.length)return{};const n={};return e.forEach(t=>{const r=Object.assign({label:t.label,text:t.label},t);n[t==null?void 0:t.value]=r}),n}},Symbol.toStringTag,{value:"Module"}))}),M={toBlob(e,n="",t=512){const o=(e.split(",")[1]||e).replace(/-/g,"+").replace(/_/g,"/"),s="=".repeat((4-o.length%4)%4),l=o+s;try{const c=atob(l),u=[];for(let g=0;g<c.length;g+=t){const a=c.slice(g,g+t),f=new Array(a.length);for(let d=0;d<a.length;d++)f[d]=a.charCodeAt(d);const h=new Uint8Array(f);u.push(h)}return new Blob(u,{type:n})}catch(c){return console.error("Failed to convert base64 to blob:",c),null}},toFile(e,n="file.txt",t="text/plain"){const o=e.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),s="=".repeat((4-o.length%4)%4),l=o+s,c=atob(l),u=[];for(let a=0;a<c.length;a+=512){const f=c.slice(a,a+512),h=new Array(f.length);for(let d=0;d<f.length;d++)h[d]=f.charCodeAt(d);u.push(new Uint8Array(h))}const g=new Blob(u,{type:t});return new File([g],n,{type:t})}},m={isEmptyString(e){return typeof e=="string"&&e.trim()===""},isNumber(e){return typeof e=="number"&&!isNaN(e)},isObject(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)},isEmptyObject(e){return e?Object.keys(e).length===0&&e.constructor===Object:!0},isBoolean(e){return typeof e=="boolean"},isArray(e){return Array.isArray(e)},isFunction(e){return typeof e=="function"},isPromise(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"},isElement(e){return e instanceof Element},isPhone(e){return/^1[3-9]\d{9}$/.test(e)},isEmail(e){return/^[\w.-]+@[\w.-]+\.\w+$/.test(e)},isJSON(e){try{return JSON.parse(e),!0}catch{return!1}},isImageLoaded(e){return e.complete&&e.naturalWidth!==0},isInViewport(e){const n=e.getBoundingClientRect();return n.top>=0&&n.left>=0&&n.bottom<=window.innerHeight&&n.right<=window.innerWidth},isLeapYear(e){return e%4===0&&e%100!==0||e%400===0},isMobile(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}},U={getCookie(e){if(!e)return;const n=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return n?decodeURIComponent(n[2]):null},setCookie(e,n,t=7){const r=new Date;r.setTime(r.getTime()+t*24*60*60*1e3),document.cookie=`${e}=${encodeURIComponent(n)};expires=${r.toUTCString()};path=/`},deleteCookie(e){this.setCookie(e,"",-1)}},S={getTimeString(e,n=!1){return n?new Date().toLocaleString(e,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(e,n){const t=new Date(e).getTime(),r=new Date(n).getTime();return t>r?Math.abs(Math.floor((t-r)/(24*3600*1e3))):Math.abs(Math.floor((r-t)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)},getWhichDays(e,n,t){let r=t;for(let o=1;o<n;o++)switch(o){case 1:case 3:case 5:case 7:case 8:case 10:case 12:r+=31;break;case 2:m.isLeapYear(e)?r+=29:r+=28;break;default:r+=30;break}return r}},O={getOffsetTop(e){if(!e)throw new Error("Element is not provided");if(e instanceof SVGElement){const t=e.getBoundingClientRect(),r=window.pageYOffset||document.documentElement.scrollTop;return t.top+r}let n=0;for(;e;)n+=e.offsetTop,e=e.offsetParent;return n},getScrollValue(){const e={scrollLeft:0,scrollTop:0};return e.scrollLeft=document.body.scrollLeft||document.documentElement.scrollLeft,e.scrollTop=document.body.scrollTop||document.documentElement.scrollTop,e},getPageValue(e){e=e||window.event;const n=e.pageX||e.clientX+this.getScrollValue().scrollLeft,t=e.pageY||e.clientY+this.getScrollValue().scrollTop;return{pageX:n,pageY:t}},addEventListener(e,n,t){e.addEventListener?e.addEventListener(n,t):e.attachEvent?e.attachEvent("on"+n,t):e["on"+n]=t}},E={saveAsBlob(e,n){const t=document.createElement("a"),r=window.URL.createObjectURL(e);t.href=r,t.download=n,document.body.appendChild(t),t.click(),URL.revokeObjectURL(r),document.body.removeChild(t)}},L={sortFromA2Z(e){return e!=null&&e.length?e.sort((t,r)=>{const o=t.toUpperCase(),s=r.toUpperCase();return o<s?-1:o>s?1:0}):void 0}},j={degrees2Radians(e){return e*Math.PI/180},getDistance(e,n,t,r){const o=this.degrees2Radians(e),s=this.degrees2Radians(t),l=o-s,c=this.degrees2Radians(n)-this.degrees2Radians(r);let u=2*Math.asin(Math.sqrt(Math.pow(Math.sin(l/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin(c/2),2)));return u=u*6378.137,u=Math.round(u*1e4)/1e4,u=+u.toFixed(2),console.log("经纬度计算的距离为:"+u),u},calculateDistanceByHaversine(e,n,t="km"){const r=this,o=e.longitude??e.lng,s=e.latitude??e.lat,l=n.longitude??n.lng,c=n.latitude??n.lat;if(o===void 0||s===void 0||l===void 0||c===void 0)throw new Error("无效的坐标格式,缺少经纬度信息");const u=6371,g=r.degrees2Radians(s),a=r.degrees2Radians(c),f=r.degrees2Radians(c-s),h=r.degrees2Radians(l-o),d=Math.sin(f/2)*Math.sin(f/2)+Math.cos(g)*Math.cos(a)*Math.sin(h/2)*Math.sin(h/2),b=2*Math.atan2(Math.sqrt(d),Math.sqrt(1-d)),y=u*b;switch(t){case"m":return y*1e3;case"mi":return y*.621371;case"nmi":return y*.539957;default:return y}},calculateDistancesByHaversine(e,n="km",t=!1){if(e.length<2)return{segments:[],total:0};const r=[];let o=0;for(let s=0;s<e.length-1;s++){const l=this.calculateDistanceByHaversine(e[s],e[s+1],n);r.push(l),o+=l}if(t&&e.length>2){const s=this.calculateDistanceByHaversine(e[e.length-1],e[0],n);r.push(s),o+=s}return{segments:r,total:o}}};class v{static toStandardFormat(n){try{const t=typeof n=="string"?parseFloat(n):n;if(isNaN(t))throw new Error("输入不是有效的数字");if(!isFinite(t))throw new Error("输入是无穷大");return t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}catch(t){return console.error("格式化失败:",t),"格式错误"}}static toChineseFormat(n){try{const t=typeof n=="string"?parseFloat(n):n;if(isNaN(t))throw new Error("输入不是有效的数字");if(t>9999999999999e-2||t<-9999999999999e-2)throw new Error("输入数字超出范围");const r=t<0,o=Math.abs(t),s=Math.floor(o),l=Math.round((o-s)*100),c=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],u=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],g=["角","分"];let a="",f=s;if(f===0)a=c[0];else{let b=0;for(;f>0;){const y=f%10;y!==0?a=c[y]+u[b]+a:a.charAt(0)!==c[0]&&(a=c[y]+a),f=Math.floor(f/10),b++}a=a.replace(/零+/g,"零"),a=a.replace(/零+$/,"")}let h="";if(l>0){const b=Math.floor(l/10),y=l%10;b>0&&(h+=c[b]+g[0]),y>0&&(h+=c[y]+g[1])}else h="整";let d=(r?"负":"")+a+"圆"+h;return d==="零圆整"&&(d="零圆"),d}catch(t){return console.error("转换失败:",t),"格式错误"}}}const A={...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"})),isNumber(e){return typeof e=="number"&&!isNaN(e)}},R={isEmptyObject(e){return e?Object.keys(e).length===0&&e.constructor===Object:!0},copy(e,n){for(const t in e)n[t]=e[t]},deepCopy(e,n){for(const t in e){const r=e[t];r instanceof Object?(n[t]={},this.deepCopy(r,n[t])):r instanceof Array?(n[t]=[],this.deepCopy(r,n[t])):n[t]=e[t]}}},k={desensitize(e){return e?e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||e.slice(0,3)+"****"+e.slice(7):""}},T={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(e,n){return Math.floor(Math.random()*(n-e+1))+e},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},C={getLocal(e){return localStorage.getItem(e)},setLocal(e,n){localStorage.setItem(e,n)},removeLocal(e){localStorage.removeItem(e)},getSession(e){return sessionStorage.getItem(e)},setSession(e,n){sessionStorage.setItem(e,n)},removeSession(e){sessionStorage.removeItem(e)}},B={isExist(e,n){if(!e||!n)return!1;const t=e.split(",");return console.log("判断某元素是否在字符串中",t.indexOf(n)===-1),t.indexOf(n)!==-1},includes(e,n){return!e||!n?!1:e.includes(n)},isJSON(e){try{return JSON.parse(e),!0}catch{return!1}},indexsOfAppear(e,n){let t=-1;const r=[];do t=e.indexOf(n,t+1),t!==-1&&r.push(t);while(t!==-1);return r},getMaxTimesAndVal(e){const n=[0,""],t={};for(let s=0;s<e.length;s++){const l=e.charAt(s);t[l]?t[l]++:t[l]=1}let r=1;for(const s in t)r<t[s]&&(r=t[s]);const o=[];for(const s in t)r==t[s]&&o.push(s);return n[0]=r,n[1]=o.join(),n}},_=e=>{const t=new RegExp("[?&]"+e+"=([^&#]*)","i").exec(window.location.href);return t?decodeURIComponent(t[1]):null};function I(e){return new URLSearchParams(window.location.search).get(e)}const N={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:_,getQueryParam:I},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},P={toList(e,n=2){console.log(e,n);const t={};for(let o=0;o<n;o++)t[o]=[];e.forEach((o,s)=>t[s%n].push(o));const r=[];for(const o in t)r.push(...t[o]);return r}};i.MoneyFormatter=v,i.arrayUtils=w,i.base64Utils=M,i.booleanUtils=m,i.cookieUtils=U,i.dateUtils=S,i.documentUtils=O,i.downloadUtils=E,i.letterUtils=L,i.mapUtils=j,i.numberUtils=A,i.objectUtils=R,i.phoneUtils=k,i.randomUtils=T,i.storageUtils=C,i.stringUtils=B,i.urlUtils=N,i.waterfallUtils=P,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(l,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(l=typeof globalThis<"u"?globalThis:l||self,b(l.yhkitUtils={}))})(this,function(l){"use strict";const m=Object.assign({unique(e){return e?Array.from(new Set(e)):[]},isExist(e,n){return!e||!n?!1:e.indexOf(n)!==-1},countOfAppear(e,n){let t=0;for(const r of e)r===n&&t++;return t},indexsOfAppear(e,n){let t=-1;const r=[];do t=e.indexOf(n,t+1),t!==-1&&r.push(t);while(t!==-1);return r},sort(e,n="asc"){return e?e.sort((t,r)=>n==="asc"?t>r?1:-1:t<r?1:-1):[]},shuffle(e){if(!e)return[];for(let n=e.length-1;n>0;n--){const t=Math.floor(Math.random()*(n+1));[e[n],e[t]]=[e[t],e[n]]}return e},getMaxValue(e){return e?Math.max(...e):0},getMinValue(e){return e?Math.min(...e):0},getMinValueAndIndex(e){if(e.length===0)return{value:0,index:0};const n={value:e[0],index:0};for(let t=1,r=e.length;t<r;t++){const o=e[t];n.value>o&&(n.value=o,n.index=t)}return n},getMaxValueAndIndex(e){return e.length===0?{value:0,index:0}:e.reduce((n,t,r)=>t<n.value?{value:t,index:r}:n,{value:e[0],index:0})}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:e=>{if(!e||!e.length)return{};const n={};return e.forEach(t=>{const r=Object.assign({label:t.label,text:t.label},t);n[t==null?void 0:t.value]=r}),n}},Symbol.toStringTag,{value:"Module"}))}),M={toBlob(e,n="",t=512){const o=(e.split(",")[1]||e).replace(/-/g,"+").replace(/_/g,"/"),s="=".repeat((4-o.length%4)%4),u=o+s;try{const c=atob(u),a=[];for(let h=0;h<c.length;h+=t){const i=c.slice(h,h+t),d=new Array(i.length);for(let f=0;f<i.length;f++)d[f]=i.charCodeAt(f);const g=new Uint8Array(d);a.push(g)}return new Blob(a,{type:n})}catch(c){return console.error("Failed to convert base64 to blob:",c),null}},toFile(e,n="file.txt",t="text/plain"){const o=e.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),s="=".repeat((4-o.length%4)%4),u=o+s,c=atob(u),a=[];for(let i=0;i<c.length;i+=512){const d=c.slice(i,i+512),g=new Array(d.length);for(let f=0;f<d.length;f++)g[f]=d.charCodeAt(f);a.push(new Uint8Array(g))}const h=new Blob(a,{type:t});return new File([h],n,{type:t})}},w={isEmptyString(e){return typeof e=="string"&&e.trim()===""},isNumber(e){return typeof e=="number"&&!isNaN(e)},isObject(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)},isEmptyObject(e){return e?Object.keys(e).length===0&&e.constructor===Object:!0},isBoolean(e){return typeof e=="boolean"},isArray(e){return Array.isArray(e)},isFunction(e){return typeof e=="function"},isPromise(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"},isElement(e){return e instanceof Element},isPhone(e){return/^1[3-9]\d{9}$/.test(e)},isEmail(e){return/^[\w.-]+@[\w.-]+\.\w+$/.test(e)},isJSON(e){try{return JSON.parse(e),!0}catch{return!1}},isImageLoaded(e){return e.complete&&e.naturalWidth!==0},isInViewport(e){const n=e.getBoundingClientRect();return n.top>=0&&n.left>=0&&n.bottom<=window.innerHeight&&n.right<=window.innerWidth},isLeapYear(e){return e%4===0&&e%100!==0||e%400===0},isMobile(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}},U={getCookie(e){if(!e)return;const n=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return n?decodeURIComponent(n[2]):null},setCookie(e,n,t=7){const r=new Date;r.setTime(r.getTime()+t*24*60*60*1e3),document.cookie=`${e}=${encodeURIComponent(n)};expires=${r.toUTCString()};path=/`},deleteCookie(e){this.setCookie(e,"",-1)}},S={getTimeString(e,n=!1){return n?new Date().toLocaleString(e,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(e,n){const t=new Date(e).getTime(),r=new Date(n).getTime();return t>r?Math.abs(Math.floor((t-r)/(24*3600*1e3))):Math.abs(Math.floor((r-t)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)},getWhichDays(e,n,t){let r=t;for(let o=1;o<n;o++)switch(o){case 1:case 3:case 5:case 7:case 8:case 10:case 12:r+=31;break;case 2:w.isLeapYear(e)?r+=29:r+=28;break;default:r+=30;break}return r}},O={getOffsetTop(e){if(!e)throw new Error("Element is not provided");if(e instanceof SVGElement){const t=e.getBoundingClientRect(),r=window.pageYOffset||document.documentElement.scrollTop;return t.top+r}let n=0;for(;e;)n+=e.offsetTop,e=e.offsetParent;return n},getScrollValue(){const e={scrollLeft:0,scrollTop:0};return e.scrollLeft=document.body.scrollLeft||document.documentElement.scrollLeft,e.scrollTop=document.body.scrollTop||document.documentElement.scrollTop,e},getPageValue(e){e=e||window.event;const n=e.pageX||e.clientX+this.getScrollValue().scrollLeft,t=e.pageY||e.clientY+this.getScrollValue().scrollTop;return{pageX:n,pageY:t}},addEventListener(e,n,t){e.addEventListener?e.addEventListener(n,t):e.attachEvent?e.attachEvent("on"+n,t):e["on"+n]=t}},v={saveAsBlob(e,n){const t=document.createElement("a"),r=window.URL.createObjectURL(e);t.href=r,t.download=n,document.body.appendChild(t),t.click(),URL.revokeObjectURL(r),document.body.removeChild(t)}},A={sortFromA2Z(e){return e!=null&&e.length?e.sort((t,r)=>{const o=t.toUpperCase(),s=r.toUpperCase();return o<s?-1:o>s?1:0}):void 0}},E={degrees2Radians(e){return e*Math.PI/180},getDistance(e,n,t,r){const o=this.degrees2Radians(e),s=this.degrees2Radians(t),u=o-s,c=this.degrees2Radians(n)-this.degrees2Radians(r);let a=2*Math.asin(Math.sqrt(Math.pow(Math.sin(u/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin(c/2),2)));return a=a*6378.137,a=Math.round(a*1e4)/1e4,a=+a.toFixed(2),console.log("经纬度计算的距离为:"+a),a},calculateDistanceByHaversine(e,n,t="km"){const r=this,o=e.longitude??e.lng,s=e.latitude??e.lat,u=n.longitude??n.lng,c=n.latitude??n.lat;if(o===void 0||s===void 0||u===void 0||c===void 0)throw new Error("无效的坐标格式,缺少经纬度信息");const a=6371,h=r.degrees2Radians(s),i=r.degrees2Radians(c),d=r.degrees2Radians(c-s),g=r.degrees2Radians(u-o),f=Math.sin(d/2)*Math.sin(d/2)+Math.cos(h)*Math.cos(i)*Math.sin(g/2)*Math.sin(g/2),p=2*Math.atan2(Math.sqrt(f),Math.sqrt(1-f)),y=a*p;switch(t){case"m":return y*1e3;case"mi":return y*.621371;case"nmi":return y*.539957;default:return y}},calculateDistancesByHaversine(e,n="km",t=!1){if(e.length<2)return{segments:[],total:0};const r=[];let o=0;for(let s=0;s<e.length-1;s++){const u=this.calculateDistanceByHaversine(e[s],e[s+1],n);r.push(u),o+=u}if(t&&e.length>2){const s=this.calculateDistanceByHaversine(e[e.length-1],e[0],n);r.push(s),o+=s}return{segments:r,total:o}}};class j{static toStandardFormat(n){try{const t=typeof n=="string"?parseFloat(n):n;if(isNaN(t))throw new Error("输入不是有效的数字");if(!isFinite(t))throw new Error("输入是无穷大");return t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}catch(t){return console.error("格式化失败:",t),"格式错误"}}static toChineseFormat(n){try{const t=typeof n=="string"?parseFloat(n):n;if(isNaN(t))throw new Error("输入不是有效的数字");if(t>9999999999999e-2||t<-9999999999999e-2)throw new Error("输入数字超出范围");const r=t<0,o=Math.abs(t),s=Math.floor(o),u=Math.round((o-s)*100),c=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],a=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],h=["角","分"];let i="",d=s;if(d===0)i=c[0];else{let p=0;for(;d>0;){const y=d%10;y!==0?i=c[y]+a[p]+i:i.charAt(0)!==c[0]&&(i=c[y]+i),d=Math.floor(d/10),p++}i=i.replace(/零+/g,"零"),i=i.replace(/零+$/,"")}let g="";if(u>0){const p=Math.floor(u/10),y=u%10;p>0&&(g+=c[p]+h[0]),y>0&&(g+=c[y]+h[1])}else g="整";let f=(r?"负":"")+i+"圆"+g;return f==="零圆整"&&(f="零圆"),f}catch(t){return console.error("转换失败:",t),"格式错误"}}}const 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"})),isNumber(e){return typeof e=="number"&&!isNaN(e)}},x={isEmptyObject(e){return e?Object.keys(e).length===0&&e.constructor===Object:!0},copy(e,n){for(const t in e)n[t]=e[t]},deepCopy(e,n){for(const t in e){const r=e[t];r instanceof Object?(n[t]={},this.deepCopy(r,n[t])):r instanceof Array?(n[t]=[],this.deepCopy(r,n[t])):n[t]=e[t]}}},R={desensitize(e){return e?e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||e.slice(0,3)+"****"+e.slice(7):""}},k={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(e,n){return Math.floor(Math.random()*(n-e+1))+e},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},C={mobile:/^1[3-9]\d{9}$/,email:/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,chinese:/^[\u4e00-\u9fa5]+$/,english:/^[a-zA-Z]+$/,chineseStart:/^[\u4e00-\u9fa5]+\w*$/,integer:/^\d+$/,integerAndzero:/^(0|[1-9]+[0-9]*)$/,strongPassword:/^(?!.*[\s\p{C}])(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[\d\W])|(?=.*\d)(?=.*[^\w\s])).{8,}$/u,decimal:/^0\.(0[1-9]|[1-9][0-9]*)$/},T={getLocal(e){return localStorage.getItem(e)},setLocal(e,n){localStorage.setItem(e,n)},removeLocal(e){localStorage.removeItem(e)},getSession(e){return sessionStorage.getItem(e)},setSession(e,n){sessionStorage.setItem(e,n)},removeSession(e){sessionStorage.removeItem(e)}},B={isExist(e,n){if(!e||!n)return!1;const t=e.split(",");return console.log("判断某元素是否在字符串中",t.indexOf(n)===-1),t.indexOf(n)!==-1},includes(e,n){return!e||!n?!1:e.includes(n)},isJSON(e){try{return JSON.parse(e),!0}catch{return!1}},indexsOfAppear(e,n){let t=-1;const r=[];do t=e.indexOf(n,t+1),t!==-1&&r.push(t);while(t!==-1);return r},getMaxTimesAndVal(e){const n=[0,""],t={};for(let s=0;s<e.length;s++){const u=e.charAt(s);t[u]?t[u]++:t[u]=1}let r=1;for(const s in t)r<t[s]&&(r=t[s]);const o=[];for(const s in t)r==t[s]&&o.push(s);return n[0]=r,n[1]=o.join(),n}},I=e=>{const t=new RegExp("[?&]"+e+"=([^&#]*)","i").exec(window.location.href);return t?decodeURIComponent(t[1]):null};function _(e){return new URLSearchParams(window.location.search).get(e)}const $={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:I,getQueryParam:_},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},P={toList(e,n=2){console.log(e,n);const t={};for(let o=0;o<n;o++)t[o]=[];e.forEach((o,s)=>t[s%n].push(o));const r=[];for(const o in t)r.push(...t[o]);return r},jsLayout(e,n,t){const r=e.offsetWidth,o=n[0].offsetWidth,s=parseInt((r/o).toString()),u=(r-o*s)/(s-1),c=[];for(let a=0,h=n.length;a<h;a++){const i=n[a];if(a<s)i.style.left=(o+u)*a+"px",c[a]=i.offsetHeight;else{const{index:d,value:g}=m.getMinValueAndIndex(c);i.style.left=(o+u)*d+"px",i.style.top=g+t+"px",c[d]=i.offsetHeight+t+g}}}};l.MoneyFormatter=j,l.arrayUtils=m,l.base64Utils=M,l.booleanUtils=w,l.cookieUtils=U,l.dateUtils=S,l.documentUtils=O,l.downloadUtils=v,l.letterUtils=A,l.mapUtils=E,l.numberUtils=L,l.objectUtils=x,l.phoneUtils=R,l.randomUtils=k,l.regexpUtils=C,l.storageUtils=T,l.stringUtils=B,l.urlUtils=$,l.waterfallUtils=P,Object.defineProperty(l,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.6.1",
4
+ "version": "1.7.1",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -60,6 +60,24 @@ export declare const arrayUtils: {
60
60
  * @returns 最小值
61
61
  */
62
62
  getMinValue(arr: number[]): number;
63
+ /**
64
+ * 获取数组中的最小值和索引
65
+ * @param array 数组
66
+ * @returns 最小值和索引
67
+ */
68
+ getMinValueAndIndex(array: number[]): {
69
+ value: number;
70
+ index: number;
71
+ };
72
+ /**
73
+ * 获取数组中的最大值和索引
74
+ * @param arr 数组
75
+ * @returns 最大值和索引
76
+ */
77
+ getMaxValueAndIndex(arr: number[]): {
78
+ value: number;
79
+ index: number;
80
+ };
63
81
  } & {
64
82
  toEnumObj: (arr: import("@yh-kit/types").IOptionItem[]) => import("@yh-kit/types").TValueEnum;
65
83
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 元素【Dom】相关工具函数
2
+ * 元素【Dom 文档流】相关工具函数
3
3
  */
4
4
  export declare const documentUtils: {
5
5
  /**
@@ -12,6 +12,7 @@ export * from "./number";
12
12
  export * from "./object";
13
13
  export * from "./phone";
14
14
  export * from "./random";
15
+ export * from "./regexp";
15
16
  export * from "./storage";
16
17
  export * from "./string";
17
18
  export * from "./url";
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 常用正则表达式
3
+ */
4
+ export declare const regexpUtils: {
5
+ /**
6
+ * 验证手机号
7
+ */
8
+ mobile: RegExp;
9
+ /**
10
+ * 验证邮箱
11
+ */
12
+ email: RegExp;
13
+ /**
14
+ * 验证中文
15
+ */
16
+ chinese: RegExp;
17
+ /**
18
+ * 验证英文
19
+ */
20
+ english: RegExp;
21
+ /**
22
+ * 验证中文开头其他结束
23
+ */
24
+ chineseStart: RegExp;
25
+ /**
26
+ * 验证正整数
27
+ */
28
+ integer: RegExp;
29
+ /**
30
+ * 验证零+正整数
31
+ */
32
+ integerAndzero: RegExp;
33
+ /**
34
+ * 验证强密码正则:密码须由大小字母+数字、大小字母+特殊符号、数字+特殊字符等组合,且存在字母时,必须包含大小写字母。长度必须8位以上
35
+ */
36
+ strongPassword: RegExp;
37
+ /**
38
+ * 验证0.01~0.99正则:最多两位小数。0.1、0.10、0.9、0.90
39
+ */
40
+ decimal: RegExp;
41
+ };
@@ -3,10 +3,17 @@
3
3
  */
4
4
  export declare const waterfallUtils: {
5
5
  /**
6
- * 处理瀑布流数据,使其适合瀑布流布局展示
6
+ * 处理瀑布流数据,使其竖向瀑布流布局呈现横向瀑布流的展现形式。适用于 column-gap: 20rpx; column-count: 2; 布局的瀑布流
7
7
  * @param list 瀑布流数据-数组
8
8
  * @param columnsNum 需要展示的列数
9
9
  * @returns 适合瀑布流布局的数组
10
10
  */
11
11
  toList<T>(list: T[], columnsNum?: number): any[];
12
+ /**
13
+ * js瀑布流布局
14
+ * @param itemBox 瀑布流容器
15
+ * @param items 瀑布流元素
16
+ * @param step 间距
17
+ */
18
+ jsLayout(itemBox: HTMLElement, items: HTMLElement[], step: number): void;
12
19
  };