@yh-kit/utils 1.8.0 → 1.9.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 +193 -182
- package/dist/utils.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/utils/lib/document/index.d.ts +10 -0
- package/types/utils/lib/number/index.d.ts +5 -1
package/dist/utils.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
var b = (t, n, e) => n in t ? m(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;
|
|
3
|
-
var y = (t, n, e) => b(t, typeof n != "symbol" ? n + "" : n, e);
|
|
4
|
-
const A = (t) => {
|
|
1
|
+
const y = (t) => {
|
|
5
2
|
if (!t || !t.length) return {};
|
|
6
3
|
const n = {};
|
|
7
4
|
return t.forEach((e) => {
|
|
8
|
-
const
|
|
9
|
-
n[e
|
|
5
|
+
const r = Object.assign({ label: e.label, text: e.label }, e);
|
|
6
|
+
n[e?.value] = r;
|
|
10
7
|
}), n;
|
|
11
|
-
},
|
|
8
|
+
}, m = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
12
9
|
__proto__: null,
|
|
13
|
-
toEnumObj:
|
|
14
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
10
|
+
toEnumObj: y
|
|
11
|
+
}, Symbol.toStringTag, { value: "Module" })), w = Object.assign(
|
|
15
12
|
{
|
|
16
13
|
/**
|
|
17
14
|
* 数组去重
|
|
@@ -38,8 +35,8 @@ const A = (t) => {
|
|
|
38
35
|
*/
|
|
39
36
|
countOfAppear(t, n) {
|
|
40
37
|
let e = 0;
|
|
41
|
-
for (const
|
|
42
|
-
|
|
38
|
+
for (const r of t)
|
|
39
|
+
r === n && e++;
|
|
43
40
|
return e;
|
|
44
41
|
},
|
|
45
42
|
/**
|
|
@@ -50,11 +47,11 @@ const A = (t) => {
|
|
|
50
47
|
*/
|
|
51
48
|
indexsOfAppear(t, n) {
|
|
52
49
|
let e = -1;
|
|
53
|
-
const
|
|
50
|
+
const r = [];
|
|
54
51
|
do
|
|
55
|
-
e = t.indexOf(n, e + 1), e !== -1 &&
|
|
52
|
+
e = t.indexOf(n, e + 1), e !== -1 && r.push(e);
|
|
56
53
|
while (e !== -1);
|
|
57
|
-
return
|
|
54
|
+
return r;
|
|
58
55
|
},
|
|
59
56
|
/**
|
|
60
57
|
* 数组排序-默认升序
|
|
@@ -63,7 +60,7 @@ const A = (t) => {
|
|
|
63
60
|
* @returns 排序后的数组
|
|
64
61
|
*/
|
|
65
62
|
sort(t, n = "asc") {
|
|
66
|
-
return t ? t.sort((e,
|
|
63
|
+
return t ? t.sort((e, r) => n === "asc" ? e > r ? 1 : -1 : e < r ? 1 : -1) : [];
|
|
67
64
|
},
|
|
68
65
|
/**
|
|
69
66
|
* 数组乱序(洗牌算法)
|
|
@@ -114,9 +111,9 @@ const A = (t) => {
|
|
|
114
111
|
/** 最小值索引 */
|
|
115
112
|
index: 0
|
|
116
113
|
};
|
|
117
|
-
for (let e = 1,
|
|
118
|
-
const
|
|
119
|
-
n.value >
|
|
114
|
+
for (let e = 1, r = t.length; e < r; e++) {
|
|
115
|
+
const o = t[e];
|
|
116
|
+
n.value > o && (n.value = o, n.index = e);
|
|
120
117
|
}
|
|
121
118
|
return n;
|
|
122
119
|
},
|
|
@@ -127,16 +124,18 @@ const A = (t) => {
|
|
|
127
124
|
*/
|
|
128
125
|
getMaxValueAndIndex(t) {
|
|
129
126
|
return t.length === 0 ? { value: 0, index: 0 } : t.reduce(
|
|
130
|
-
(n, e,
|
|
127
|
+
(n, e, r) => e < n.value ? { value: e, index: r } : n,
|
|
131
128
|
{ value: t[0], index: 0 }
|
|
132
129
|
);
|
|
133
130
|
}
|
|
134
131
|
},
|
|
135
132
|
{
|
|
136
|
-
...
|
|
133
|
+
...m
|
|
137
134
|
}
|
|
138
135
|
);
|
|
139
|
-
class
|
|
136
|
+
class _ {
|
|
137
|
+
/** Base64 编码表 */
|
|
138
|
+
static BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
140
139
|
/**
|
|
141
140
|
* 将Base64编码的字符串转换为Blob对象。
|
|
142
141
|
* Blob对象用于表示二进制大型对象,可以在浏览器环境中处理大文件或二进制数据。
|
|
@@ -146,18 +145,18 @@ class M {
|
|
|
146
145
|
* @param sliceSize 可选参数,表示分片大小,默认为512字节。用于控制每次处理的Base64字符串长度,以优化大文件的处理。
|
|
147
146
|
* @returns 返回转换后的Blob对象,如果转换失败,则返回null。
|
|
148
147
|
*/
|
|
149
|
-
static toBlob(n, e = "",
|
|
148
|
+
static toBlob(n, e = "", r = 512) {
|
|
150
149
|
const s = (n.split(",")[1] || n).replace(/-/g, "+").replace(/_/g, "/"), c = "=".repeat((4 - s.length % 4) % 4), l = s + c;
|
|
151
150
|
try {
|
|
152
|
-
const i = atob(l),
|
|
153
|
-
for (let a = 0; a < i.length; a +=
|
|
154
|
-
const u = i.slice(a, a +
|
|
151
|
+
const i = atob(l), d = [];
|
|
152
|
+
for (let a = 0; a < i.length; a += r) {
|
|
153
|
+
const u = i.slice(a, a + r), h = new Array(u.length);
|
|
155
154
|
for (let f = 0; f < u.length; f++)
|
|
156
|
-
|
|
157
|
-
const g = new Uint8Array(
|
|
158
|
-
|
|
155
|
+
h[f] = u.charCodeAt(f);
|
|
156
|
+
const g = new Uint8Array(h);
|
|
157
|
+
d.push(g);
|
|
159
158
|
}
|
|
160
|
-
return new Blob(
|
|
159
|
+
return new Blob(d, { type: e });
|
|
161
160
|
} catch (i) {
|
|
162
161
|
return console.error("Failed to convert base64 to blob:", i), null;
|
|
163
162
|
}
|
|
@@ -172,16 +171,16 @@ class M {
|
|
|
172
171
|
* @param mimeType MIME类型,默认为"text/plain"。
|
|
173
172
|
* @returns 返回一个File对象,包含解码后的数据。
|
|
174
173
|
*/
|
|
175
|
-
static toFile(n, e = "file.txt",
|
|
176
|
-
const s = n.replace(/^data:.+;base64,/, "").replace(/-/g, "+").replace(/_/g, "/"), c = "=".repeat((4 - s.length % 4) % 4), l = s + c, i = atob(l),
|
|
174
|
+
static toFile(n, e = "file.txt", r = "text/plain") {
|
|
175
|
+
const s = n.replace(/^data:.+;base64,/, "").replace(/-/g, "+").replace(/_/g, "/"), c = "=".repeat((4 - s.length % 4) % 4), l = s + c, i = atob(l), d = [];
|
|
177
176
|
for (let u = 0; u < i.length; u += 512) {
|
|
178
|
-
const
|
|
179
|
-
for (let f = 0; f <
|
|
180
|
-
g[f] =
|
|
181
|
-
|
|
177
|
+
const h = i.slice(u, u + 512), g = new Array(h.length);
|
|
178
|
+
for (let f = 0; f < h.length; f++)
|
|
179
|
+
g[f] = h.charCodeAt(f);
|
|
180
|
+
d.push(new Uint8Array(g));
|
|
182
181
|
}
|
|
183
|
-
const a = new Blob(
|
|
184
|
-
return new File([a], e, { type:
|
|
182
|
+
const a = new Blob(d, { type: r });
|
|
183
|
+
return new File([a], e, { type: r });
|
|
185
184
|
}
|
|
186
185
|
/**
|
|
187
186
|
* base64加密 -- 普通字符串转 Base64 编码
|
|
@@ -209,20 +208,20 @@ class M {
|
|
|
209
208
|
*/
|
|
210
209
|
static _stringToUtf8Bytes(n) {
|
|
211
210
|
const e = [];
|
|
212
|
-
for (let
|
|
213
|
-
let
|
|
214
|
-
if (
|
|
215
|
-
e.push(
|
|
216
|
-
else if (
|
|
217
|
-
e.push(192 |
|
|
218
|
-
else if (
|
|
219
|
-
e.push(224 |
|
|
211
|
+
for (let r = 0; r < n.length; r++) {
|
|
212
|
+
let o = n.charCodeAt(r);
|
|
213
|
+
if (o < 128)
|
|
214
|
+
e.push(o);
|
|
215
|
+
else if (o < 2048)
|
|
216
|
+
e.push(192 | o >> 6), e.push(128 | o & 63);
|
|
217
|
+
else if (o < 55296 || o >= 57344)
|
|
218
|
+
e.push(224 | o >> 12), e.push(128 | o >> 6 & 63), e.push(128 | o & 63);
|
|
220
219
|
else {
|
|
221
|
-
|
|
222
|
-
const s =
|
|
220
|
+
r++;
|
|
221
|
+
const s = o, c = n.charCodeAt(r);
|
|
223
222
|
if (isNaN(c))
|
|
224
223
|
throw new Error("代理对不完整");
|
|
225
|
-
|
|
224
|
+
o = 65536 + ((s & 1023) << 10) + (c & 1023), e.push(240 | o >> 18), e.push(128 | o >> 12 & 63), e.push(128 | o >> 6 & 63), e.push(128 | o & 63);
|
|
226
225
|
}
|
|
227
226
|
}
|
|
228
227
|
return e;
|
|
@@ -231,20 +230,20 @@ class M {
|
|
|
231
230
|
* UTF-8 字节数组转字符串
|
|
232
231
|
*/
|
|
233
232
|
static _utf8BytesToString(n) {
|
|
234
|
-
let e = "",
|
|
235
|
-
for (;
|
|
236
|
-
const
|
|
237
|
-
if (
|
|
238
|
-
e += String.fromCharCode(
|
|
239
|
-
else if (
|
|
240
|
-
const s = n[
|
|
241
|
-
e += String.fromCharCode((
|
|
242
|
-
} else if (
|
|
243
|
-
const s = n[
|
|
244
|
-
e += String.fromCharCode((
|
|
245
|
-
} else if (
|
|
246
|
-
const s = n[
|
|
247
|
-
e += String.fromCharCode(
|
|
233
|
+
let e = "", r = 0;
|
|
234
|
+
for (; r < n.length; ) {
|
|
235
|
+
const o = n[r++];
|
|
236
|
+
if (o < 128)
|
|
237
|
+
e += String.fromCharCode(o);
|
|
238
|
+
else if (o >= 192 && o < 224) {
|
|
239
|
+
const s = n[r++] & 63;
|
|
240
|
+
e += String.fromCharCode((o & 31) << 6 | s);
|
|
241
|
+
} else if (o >= 224 && o < 240) {
|
|
242
|
+
const s = n[r++] & 63, c = n[r++] & 63;
|
|
243
|
+
e += String.fromCharCode((o & 15) << 12 | s << 6 | c);
|
|
244
|
+
} else if (o >= 240 && o < 248) {
|
|
245
|
+
const s = n[r++] & 63, c = n[r++] & 63, l = n[r++] & 63, i = (o & 7) << 18 | s << 12 | c << 6 | l, d = Math.floor((i - 65536) / 1024) + 55296, a = (i - 65536) % 1024 + 56320;
|
|
246
|
+
e += String.fromCharCode(d, a);
|
|
248
247
|
} else
|
|
249
248
|
e += "�";
|
|
250
249
|
}
|
|
@@ -254,10 +253,10 @@ class M {
|
|
|
254
253
|
* 字节数组转 Base64 编码
|
|
255
254
|
*/
|
|
256
255
|
static _bytesToBase64(n) {
|
|
257
|
-
let e = "",
|
|
258
|
-
for (;
|
|
259
|
-
const
|
|
260
|
-
s ? l ? e += this.BASE64_CHARS.charAt(
|
|
256
|
+
let e = "", r = 0;
|
|
257
|
+
for (; r < n.length; ) {
|
|
258
|
+
const o = n[r++], s = r < n.length, c = s ? n[r++] : 0, l = r < n.length, i = l ? n[r++] : 0, d = o >> 2, a = (o & 3) << 4 | c >> 4, u = (c & 15) << 2 | i >> 6, h = i & 63;
|
|
259
|
+
s ? l ? e += this.BASE64_CHARS.charAt(d) + this.BASE64_CHARS.charAt(a) + this.BASE64_CHARS.charAt(u) + this.BASE64_CHARS.charAt(h) : e += this.BASE64_CHARS.charAt(d) + this.BASE64_CHARS.charAt(a) + this.BASE64_CHARS.charAt(u) + "=" : e += this.BASE64_CHARS.charAt(d) + this.BASE64_CHARS.charAt(a) + "==";
|
|
261
260
|
}
|
|
262
261
|
return e;
|
|
263
262
|
}
|
|
@@ -266,21 +265,21 @@ class M {
|
|
|
266
265
|
*/
|
|
267
266
|
static _base64ToBytes(n) {
|
|
268
267
|
const e = n.length;
|
|
269
|
-
let
|
|
270
|
-
e >= 2 && (n[e - 1] === "=" &&
|
|
271
|
-
const
|
|
272
|
-
for (let
|
|
273
|
-
c[this.BASE64_CHARS.charCodeAt(
|
|
268
|
+
let r = 0;
|
|
269
|
+
e >= 2 && (n[e - 1] === "=" && r++, n[e - 2] === "=" && r++);
|
|
270
|
+
const o = Math.floor(e * 3 / 4) - r, s = new Array(o), c = new Array(256).fill(-1);
|
|
271
|
+
for (let d = 0; d < this.BASE64_CHARS.length; d++)
|
|
272
|
+
c[this.BASE64_CHARS.charCodeAt(d)] = d;
|
|
274
273
|
let l = 0, i = 0;
|
|
275
274
|
for (; i < e; ) {
|
|
276
|
-
const
|
|
277
|
-
if (
|
|
275
|
+
const d = c[n.charCodeAt(i++)], a = c[n.charCodeAt(i++)], u = i < e ? c[n.charCodeAt(i++)] : -1, h = i < e ? c[n.charCodeAt(i++)] : -1;
|
|
276
|
+
if (d === -1 || a === -1)
|
|
278
277
|
throw new Error("无效的 Base64 字符");
|
|
279
|
-
const g =
|
|
278
|
+
const g = d << 2 | a >> 4;
|
|
280
279
|
if (s[l++] = g, u !== -1) {
|
|
281
280
|
const f = (a & 15) << 4 | u >> 2;
|
|
282
|
-
if (s[l++] = f,
|
|
283
|
-
const p = (u & 3) << 6 |
|
|
281
|
+
if (s[l++] = f, h !== -1) {
|
|
282
|
+
const p = (u & 3) << 6 | h;
|
|
284
283
|
s[l++] = p;
|
|
285
284
|
}
|
|
286
285
|
}
|
|
@@ -288,9 +287,7 @@ class M {
|
|
|
288
287
|
return s;
|
|
289
288
|
}
|
|
290
289
|
}
|
|
291
|
-
|
|
292
|
-
y(M, "BASE64_CHARS", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
|
|
293
|
-
const C = {
|
|
290
|
+
const b = {
|
|
294
291
|
/**
|
|
295
292
|
* 检查是否为空字符串
|
|
296
293
|
* @param str 要检查的字符串
|
|
@@ -434,7 +431,7 @@ const C = {
|
|
|
434
431
|
isMobile() {
|
|
435
432
|
return /Mobi|Android|iPhone/i.test(navigator.userAgent);
|
|
436
433
|
}
|
|
437
|
-
},
|
|
434
|
+
}, O = {
|
|
438
435
|
/**
|
|
439
436
|
* 通过传入的name获取cookie的值
|
|
440
437
|
* @param name cookie的name
|
|
@@ -453,8 +450,8 @@ const C = {
|
|
|
453
450
|
* @returns void
|
|
454
451
|
*/
|
|
455
452
|
setCookie(t, n, e = 7) {
|
|
456
|
-
const
|
|
457
|
-
|
|
453
|
+
const r = /* @__PURE__ */ new Date();
|
|
454
|
+
r.setTime(r.getTime() + e * 24 * 60 * 60 * 1e3), document.cookie = `${t}=${encodeURIComponent(n)};expires=${r.toUTCString()};path=/`;
|
|
458
455
|
},
|
|
459
456
|
/**
|
|
460
457
|
* 删除cookie
|
|
@@ -464,7 +461,7 @@ const C = {
|
|
|
464
461
|
deleteCookie(t) {
|
|
465
462
|
this.setCookie(t, "", -1);
|
|
466
463
|
}
|
|
467
|
-
},
|
|
464
|
+
}, R = {
|
|
468
465
|
/**
|
|
469
466
|
* 获取当前时间字符串
|
|
470
467
|
* @param locales 区域设置。如:'zh-CN','en-US',"chinese"。默认'zh-CN'。
|
|
@@ -481,8 +478,8 @@ const C = {
|
|
|
481
478
|
* @returns 相差天数
|
|
482
479
|
*/
|
|
483
480
|
diffDays(t, n) {
|
|
484
|
-
const e = new Date(t).getTime(),
|
|
485
|
-
return e >
|
|
481
|
+
const e = new Date(t).getTime(), r = new Date(n).getTime();
|
|
482
|
+
return e > r ? Math.abs(Math.floor((e - r) / (24 * 3600 * 1e3))) : Math.abs(Math.floor((r - e) / (24 * 3600 * 1e3)));
|
|
486
483
|
},
|
|
487
484
|
/**
|
|
488
485
|
* 生成唯一ID(时间戳+随机数)
|
|
@@ -499,9 +496,9 @@ const C = {
|
|
|
499
496
|
* @returns 当年的第几天
|
|
500
497
|
*/
|
|
501
498
|
getWhichDays(t, n, e) {
|
|
502
|
-
let
|
|
503
|
-
for (let
|
|
504
|
-
switch (
|
|
499
|
+
let r = e;
|
|
500
|
+
for (let o = 1; o < n; o++)
|
|
501
|
+
switch (o) {
|
|
505
502
|
case 1:
|
|
506
503
|
case 3:
|
|
507
504
|
case 5:
|
|
@@ -509,18 +506,18 @@ const C = {
|
|
|
509
506
|
case 8:
|
|
510
507
|
case 10:
|
|
511
508
|
case 12:
|
|
512
|
-
|
|
509
|
+
r += 31;
|
|
513
510
|
break;
|
|
514
511
|
case 2:
|
|
515
|
-
|
|
512
|
+
b.isLeapYear(t) ? r += 29 : r += 28;
|
|
516
513
|
break;
|
|
517
514
|
default:
|
|
518
|
-
|
|
515
|
+
r += 30;
|
|
519
516
|
break;
|
|
520
517
|
}
|
|
521
|
-
return
|
|
518
|
+
return r;
|
|
522
519
|
}
|
|
523
|
-
},
|
|
520
|
+
}, v = {
|
|
524
521
|
/**
|
|
525
522
|
* 获取元素相对于文档顶部的偏移量(距离)
|
|
526
523
|
* 处理了SVG元素的特殊情况。
|
|
@@ -531,8 +528,8 @@ const C = {
|
|
|
531
528
|
if (!t)
|
|
532
529
|
throw new Error("Element is not provided");
|
|
533
530
|
if (t instanceof SVGElement) {
|
|
534
|
-
const e = t.getBoundingClientRect(),
|
|
535
|
-
return e.top +
|
|
531
|
+
const e = t.getBoundingClientRect(), r = window.pageYOffset || document.documentElement.scrollTop;
|
|
532
|
+
return e.top + r;
|
|
536
533
|
}
|
|
537
534
|
let n = 0;
|
|
538
535
|
for (; t; )
|
|
@@ -576,30 +573,44 @@ const C = {
|
|
|
576
573
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
577
574
|
addEventListener(t, n, e) {
|
|
578
575
|
t.addEventListener ? t.addEventListener(n, e) : t.attachEvent ? t.attachEvent("on" + n, e) : t["on" + n] = e;
|
|
576
|
+
},
|
|
577
|
+
/**
|
|
578
|
+
* 获取视口宽度
|
|
579
|
+
* @returns 视口宽度
|
|
580
|
+
*/
|
|
581
|
+
getViewportWidth() {
|
|
582
|
+
return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
|
583
|
+
},
|
|
584
|
+
/**
|
|
585
|
+
* 获取视口高度
|
|
586
|
+
* @returns 视口高度
|
|
587
|
+
*/
|
|
588
|
+
getViewportHeight() {
|
|
589
|
+
return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
|
579
590
|
}
|
|
580
|
-
},
|
|
591
|
+
}, U = {
|
|
581
592
|
/**
|
|
582
593
|
* 将blob对象转化成文件并导出到本地
|
|
583
594
|
* @param blob blob对象
|
|
584
595
|
* @param filename 文件名
|
|
585
596
|
*/
|
|
586
597
|
saveAsBlob(t, n) {
|
|
587
|
-
const e = document.createElement("a"),
|
|
588
|
-
e.href =
|
|
598
|
+
const e = document.createElement("a"), r = window.URL.createObjectURL(t);
|
|
599
|
+
e.href = r, e.download = n, document.body.appendChild(e), e.click(), URL.revokeObjectURL(r), document.body.removeChild(e);
|
|
589
600
|
}
|
|
590
|
-
},
|
|
601
|
+
}, L = {
|
|
591
602
|
/**
|
|
592
603
|
* 将选中的字母数组从A-Z排序:用于试题选择答案的排序实例
|
|
593
604
|
* @param arr 字母数组
|
|
594
605
|
* @returns
|
|
595
606
|
*/
|
|
596
607
|
sortFromA2Z(t) {
|
|
597
|
-
return t
|
|
598
|
-
const
|
|
599
|
-
return
|
|
608
|
+
return t?.length ? t.sort((e, r) => {
|
|
609
|
+
const o = e.toUpperCase(), s = r.toUpperCase();
|
|
610
|
+
return o < s ? -1 : o > s ? 1 : 0;
|
|
600
611
|
}) : void 0;
|
|
601
612
|
}
|
|
602
|
-
},
|
|
613
|
+
}, T = {
|
|
603
614
|
/**
|
|
604
615
|
* 角度(度数)转弧度
|
|
605
616
|
* 在数学和编程里,角度有两种常用单位,分别是度(°)和弧度(rad)。
|
|
@@ -619,11 +630,11 @@ const C = {
|
|
|
619
630
|
* @param targetLng 目标经度
|
|
620
631
|
* @returns 距离值 单位:km
|
|
621
632
|
*/
|
|
622
|
-
getDistance(t, n, e,
|
|
623
|
-
const
|
|
633
|
+
getDistance(t, n, e, r) {
|
|
634
|
+
const o = this.degrees2Radians(t), s = this.degrees2Radians(e), c = o - s, l = this.degrees2Radians(n) - this.degrees2Radians(r);
|
|
624
635
|
let i = 2 * Math.asin(
|
|
625
636
|
Math.sqrt(
|
|
626
|
-
Math.pow(Math.sin(c / 2), 2) + Math.cos(
|
|
637
|
+
Math.pow(Math.sin(c / 2), 2) + Math.cos(o) * Math.cos(s) * Math.pow(Math.sin(l / 2), 2)
|
|
627
638
|
)
|
|
628
639
|
);
|
|
629
640
|
return i = i * 6378.137, i = Math.round(i * 1e4) / 1e4, i = +i.toFixed(2), console.log("经纬度计算的距离为:" + i), i;
|
|
@@ -644,10 +655,10 @@ const C = {
|
|
|
644
655
|
* @returns 距离值
|
|
645
656
|
*/
|
|
646
657
|
calculateDistanceByHaversine(t, n, e = "km") {
|
|
647
|
-
const
|
|
648
|
-
if (
|
|
658
|
+
const r = this, o = t.longitude ?? t.lng, s = t.latitude ?? t.lat, c = n.longitude ?? n.lng, l = n.latitude ?? n.lat;
|
|
659
|
+
if (o === void 0 || s === void 0 || c === void 0 || l === void 0)
|
|
649
660
|
throw new Error("无效的坐标格式,缺少经纬度信息");
|
|
650
|
-
const i = 6371,
|
|
661
|
+
const i = 6371, d = r.degrees2Radians(s), a = r.degrees2Radians(l), u = r.degrees2Radians(l - s), h = r.degrees2Radians(c - o), g = Math.sin(u / 2) * Math.sin(u / 2) + Math.cos(d) * Math.cos(a) * Math.sin(h / 2) * Math.sin(h / 2), f = 2 * Math.atan2(Math.sqrt(g), Math.sqrt(1 - g)), p = i * f;
|
|
651
662
|
switch (e) {
|
|
652
663
|
case "m":
|
|
653
664
|
return p * 1e3;
|
|
@@ -672,20 +683,20 @@ const C = {
|
|
|
672
683
|
calculateDistancesByHaversine(t, n = "km", e = !1) {
|
|
673
684
|
if (t.length < 2)
|
|
674
685
|
return { segments: [], total: 0 };
|
|
675
|
-
const
|
|
676
|
-
let
|
|
686
|
+
const r = [];
|
|
687
|
+
let o = 0;
|
|
677
688
|
for (let s = 0; s < t.length - 1; s++) {
|
|
678
689
|
const c = this.calculateDistanceByHaversine(t[s], t[s + 1], n);
|
|
679
|
-
|
|
690
|
+
r.push(c), o += c;
|
|
680
691
|
}
|
|
681
692
|
if (e && t.length > 2) {
|
|
682
693
|
const s = this.calculateDistanceByHaversine(t[t.length - 1], t[0], n);
|
|
683
|
-
|
|
694
|
+
r.push(s), o += s;
|
|
684
695
|
}
|
|
685
|
-
return { segments:
|
|
696
|
+
return { segments: r, total: o };
|
|
686
697
|
}
|
|
687
698
|
};
|
|
688
|
-
class
|
|
699
|
+
class j {
|
|
689
700
|
/**
|
|
690
701
|
* 转换为标准金额格式(带千分位和两位小数)
|
|
691
702
|
* @param num 要转换的数字
|
|
@@ -715,7 +726,7 @@ class N {
|
|
|
715
726
|
throw new Error("输入不是有效的数字");
|
|
716
727
|
if (e > 9999999999999e-2 || e < -9999999999999e-2)
|
|
717
728
|
throw new Error("输入数字超出范围");
|
|
718
|
-
const
|
|
729
|
+
const r = e < 0, o = Math.abs(e), s = Math.floor(o), c = Math.round((o - s) * 100), l = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"], i = ["", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟"], d = ["角", "分"];
|
|
719
730
|
let a = "", u = s;
|
|
720
731
|
if (u === 0)
|
|
721
732
|
a = l[0];
|
|
@@ -727,28 +738,28 @@ class N {
|
|
|
727
738
|
}
|
|
728
739
|
a = a.replace(/零+/g, "零"), a = a.replace(/零+$/, "");
|
|
729
740
|
}
|
|
730
|
-
let
|
|
741
|
+
let h = "";
|
|
731
742
|
if (c > 0) {
|
|
732
743
|
const f = Math.floor(c / 10), p = c % 10;
|
|
733
|
-
f > 0 && (
|
|
744
|
+
f > 0 && (h += l[f] + d[0]), p > 0 && (h += l[p] + d[1]);
|
|
734
745
|
} else
|
|
735
|
-
|
|
736
|
-
let g = (
|
|
746
|
+
h = "整";
|
|
747
|
+
let g = (r ? "负" : "") + a + "圆" + h;
|
|
737
748
|
return g === "零圆整" && (g = "零圆"), g;
|
|
738
749
|
} catch (e) {
|
|
739
750
|
return console.error("转换失败:", e), "格式错误";
|
|
740
751
|
}
|
|
741
752
|
}
|
|
742
753
|
}
|
|
743
|
-
const
|
|
754
|
+
const A = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], S = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
744
755
|
__proto__: null,
|
|
745
|
-
toLetter:
|
|
746
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
756
|
+
toLetter: A
|
|
757
|
+
}, Symbol.toStringTag, { value: "Module" })), M = (t) => t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), C = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
747
758
|
__proto__: null,
|
|
748
|
-
toMoney:
|
|
749
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
750
|
-
...
|
|
751
|
-
...
|
|
759
|
+
toMoney: M
|
|
760
|
+
}, Symbol.toStringTag, { value: "Module" })), H = {
|
|
761
|
+
...S,
|
|
762
|
+
...C,
|
|
752
763
|
/**
|
|
753
764
|
* 判断是否为数字
|
|
754
765
|
* @param val 待判断的值
|
|
@@ -757,7 +768,7 @@ const B = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], E = /*
|
|
|
757
768
|
isNumber(t) {
|
|
758
769
|
return typeof t == "number" && !isNaN(t);
|
|
759
770
|
}
|
|
760
|
-
},
|
|
771
|
+
}, k = {
|
|
761
772
|
/**
|
|
762
773
|
* 判断对象是否为空
|
|
763
774
|
* @param obj 对象
|
|
@@ -784,11 +795,11 @@ const B = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], E = /*
|
|
|
784
795
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
785
796
|
deepCopy(t, n) {
|
|
786
797
|
for (const e in t) {
|
|
787
|
-
const
|
|
788
|
-
|
|
798
|
+
const r = t[e];
|
|
799
|
+
r instanceof Object ? (n[e] = {}, this.deepCopy(r, n[e])) : r instanceof Array ? (n[e] = [], this.deepCopy(r, n[e])) : n[e] = t[e];
|
|
789
800
|
}
|
|
790
801
|
}
|
|
791
|
-
},
|
|
802
|
+
}, I = {
|
|
792
803
|
/**
|
|
793
804
|
* 脱敏
|
|
794
805
|
* @param phone 电话号码/手机号码
|
|
@@ -797,7 +808,7 @@ const B = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], E = /*
|
|
|
797
808
|
desensitize(t) {
|
|
798
809
|
return t ? t.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2") || t.slice(0, 3) + "****" + t.slice(7) : "";
|
|
799
810
|
}
|
|
800
|
-
},
|
|
811
|
+
}, N = {
|
|
801
812
|
/**
|
|
802
813
|
* 生成随机颜色
|
|
803
814
|
* @returns 随机颜色值
|
|
@@ -821,7 +832,7 @@ const B = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], E = /*
|
|
|
821
832
|
uniqueId() {
|
|
822
833
|
return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
|
|
823
834
|
}
|
|
824
|
-
},
|
|
835
|
+
}, P = {
|
|
825
836
|
/**
|
|
826
837
|
* 验证手机号
|
|
827
838
|
*/
|
|
@@ -858,7 +869,7 @@ const B = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], E = /*
|
|
|
858
869
|
* 验证0.01~0.99正则:最多两位小数。0.1、0.10、0.9、0.90
|
|
859
870
|
*/
|
|
860
871
|
decimal: /^0\.(0[1-9]|[1-9][0-9]*)$/
|
|
861
|
-
},
|
|
872
|
+
}, $ = {
|
|
862
873
|
/**
|
|
863
874
|
* 通过key值获取 localStorage 中存储的某个值
|
|
864
875
|
* @param key 获取的key
|
|
@@ -905,7 +916,7 @@ const B = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], E = /*
|
|
|
905
916
|
removeSession(t) {
|
|
906
917
|
sessionStorage.removeItem(t);
|
|
907
918
|
}
|
|
908
|
-
},
|
|
919
|
+
}, D = {
|
|
909
920
|
/**
|
|
910
921
|
* 判断某元素是否在字符串中-比includes()方法更兼容,includes为ES6新增方法,IE不支持。小程序也不支持
|
|
911
922
|
* @param str 字符串
|
|
@@ -947,11 +958,11 @@ const B = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], E = /*
|
|
|
947
958
|
*/
|
|
948
959
|
indexsOfAppear(t, n) {
|
|
949
960
|
let e = -1;
|
|
950
|
-
const
|
|
961
|
+
const r = [];
|
|
951
962
|
do
|
|
952
|
-
e = t.indexOf(n, e + 1), e !== -1 &&
|
|
963
|
+
e = t.indexOf(n, e + 1), e !== -1 && r.push(e);
|
|
953
964
|
while (e !== -1);
|
|
954
|
-
return
|
|
965
|
+
return r;
|
|
955
966
|
},
|
|
956
967
|
/**
|
|
957
968
|
* 获取字符串中出现次数最多的字符和次数
|
|
@@ -964,27 +975,27 @@ const B = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], E = /*
|
|
|
964
975
|
const c = t.charAt(s);
|
|
965
976
|
e[c] ? e[c]++ : e[c] = 1;
|
|
966
977
|
}
|
|
967
|
-
let
|
|
978
|
+
let r = 1;
|
|
968
979
|
for (const s in e)
|
|
969
|
-
|
|
970
|
-
const
|
|
980
|
+
r < e[s] && (r = e[s]);
|
|
981
|
+
const o = [];
|
|
971
982
|
for (const s in e)
|
|
972
|
-
|
|
973
|
-
return n[0] =
|
|
983
|
+
r == e[s] && o.push(s);
|
|
984
|
+
return n[0] = r, n[1] = o.join(), n;
|
|
974
985
|
}
|
|
975
|
-
},
|
|
986
|
+
}, B = (t) => {
|
|
976
987
|
const e = new RegExp("[?&]" + t + "=([^&#]*)", "i").exec(window.location.href);
|
|
977
988
|
return e ? decodeURIComponent(e[1]) : null;
|
|
978
989
|
};
|
|
979
|
-
function
|
|
990
|
+
function E(t) {
|
|
980
991
|
return new URLSearchParams(window.location.search).get(t);
|
|
981
992
|
}
|
|
982
|
-
const
|
|
993
|
+
const x = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
983
994
|
__proto__: null,
|
|
984
|
-
getQueryInfoByName:
|
|
985
|
-
getQueryParam:
|
|
986
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
987
|
-
...
|
|
995
|
+
getQueryInfoByName: B,
|
|
996
|
+
getQueryParam: E
|
|
997
|
+
}, Symbol.toStringTag, { value: "Module" })), F = {
|
|
998
|
+
...x,
|
|
988
999
|
/**
|
|
989
1000
|
* 获取当前域名
|
|
990
1001
|
* @returns 当前url链接的host信息
|
|
@@ -999,7 +1010,7 @@ const v = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
999
1010
|
getPath() {
|
|
1000
1011
|
return window.location.pathname;
|
|
1001
1012
|
}
|
|
1002
|
-
},
|
|
1013
|
+
}, V = {
|
|
1003
1014
|
/**
|
|
1004
1015
|
* 处理瀑布流数据,使其竖向瀑布流布局呈现横向瀑布流的展现形式。适用于 column-gap: 20rpx; column-count: 2; 布局的瀑布流
|
|
1005
1016
|
* @param list 瀑布流数据-数组
|
|
@@ -1009,13 +1020,13 @@ const v = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1009
1020
|
toList(t, n = 2) {
|
|
1010
1021
|
console.log(t, n);
|
|
1011
1022
|
const e = {};
|
|
1012
|
-
for (let
|
|
1013
|
-
e[
|
|
1014
|
-
t.forEach((
|
|
1015
|
-
const
|
|
1016
|
-
for (const
|
|
1017
|
-
|
|
1018
|
-
return
|
|
1023
|
+
for (let o = 0; o < n; o++)
|
|
1024
|
+
e[o] = [];
|
|
1025
|
+
t.forEach((o, s) => e[s % n].push(o));
|
|
1026
|
+
const r = [];
|
|
1027
|
+
for (const o in e)
|
|
1028
|
+
r.push(...e[o]);
|
|
1029
|
+
return r;
|
|
1019
1030
|
},
|
|
1020
1031
|
/**
|
|
1021
1032
|
* js瀑布流布局
|
|
@@ -1024,36 +1035,36 @@ const v = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1024
1035
|
* @param step 间距
|
|
1025
1036
|
*/
|
|
1026
1037
|
jsLayout(t, n, e) {
|
|
1027
|
-
const
|
|
1028
|
-
for (let i = 0,
|
|
1038
|
+
const r = t.offsetWidth, o = n[0].offsetWidth, s = parseInt((r / o).toString()), c = (r - o * s) / (s - 1), l = [];
|
|
1039
|
+
for (let i = 0, d = n.length; i < d; i++) {
|
|
1029
1040
|
const a = n[i];
|
|
1030
1041
|
if (i < s)
|
|
1031
|
-
a.style.left = (
|
|
1042
|
+
a.style.left = (o + c) * i + "px", l[i] = a.offsetHeight;
|
|
1032
1043
|
else {
|
|
1033
|
-
const { index: u, value:
|
|
1034
|
-
a.style.left = (
|
|
1044
|
+
const { index: u, value: h } = w.getMinValueAndIndex(l);
|
|
1045
|
+
a.style.left = (o + c) * u + "px", a.style.top = h + e + "px", l[u] = a.offsetHeight + e + h;
|
|
1035
1046
|
}
|
|
1036
1047
|
}
|
|
1037
1048
|
}
|
|
1038
1049
|
};
|
|
1039
1050
|
export {
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1051
|
+
_ as Base64Utils,
|
|
1052
|
+
j as MoneyFormatter,
|
|
1053
|
+
w as arrayUtils,
|
|
1054
|
+
b as booleanUtils,
|
|
1055
|
+
O as cookieUtils,
|
|
1056
|
+
R as dateUtils,
|
|
1057
|
+
v as documentUtils,
|
|
1058
|
+
U as downloadUtils,
|
|
1059
|
+
L as letterUtils,
|
|
1060
|
+
T as mapUtils,
|
|
1061
|
+
H as numberUtils,
|
|
1062
|
+
k as objectUtils,
|
|
1063
|
+
I as phoneUtils,
|
|
1064
|
+
N as randomUtils,
|
|
1065
|
+
P as regexpUtils,
|
|
1066
|
+
$ as storageUtils,
|
|
1067
|
+
D as stringUtils,
|
|
1068
|
+
F as urlUtils,
|
|
1069
|
+
V as waterfallUtils
|
|
1059
1070
|
};
|
package/dist/utils.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(l=typeof globalThis<"u"?globalThis:l||self,m(l.yhkitUtils={}))})(this,function(l){"use strict";var D=Object.defineProperty;var F=(l,m,b)=>m in l?D(l,m,{enumerable:!0,configurable:!0,writable:!0,value:b}):l[m]=b;var M=(l,m,b)=>F(l,typeof m!="symbol"?m+"":m,b);const w=Object.assign({unique(t){return t?Array.from(new Set(t)):[]},isExist(t,n){return!t||!n?!1:t.indexOf(n)!==-1},countOfAppear(t,n){let e=0;for(const o of t)o===n&&e++;return e},indexsOfAppear(t,n){let e=-1;const o=[];do e=t.indexOf(n,e+1),e!==-1&&o.push(e);while(e!==-1);return o},sort(t,n="asc"){return t?t.sort((e,o)=>n==="asc"?e>o?1:-1:e<o?1:-1):[]},shuffle(t){if(!t)return[];for(let n=t.length-1;n>0;n--){const e=Math.floor(Math.random()*(n+1));[t[n],t[e]]=[t[e],t[n]]}return t},getMaxValue(t){return t?Math.max(...t):0},getMinValue(t){return t?Math.min(...t):0},getMinValueAndIndex(t){if(t.length===0)return{value:0,index:0};const n={value:t[0],index:0};for(let e=1,o=t.length;e<o;e++){const r=t[e];n.value>r&&(n.value=r,n.index=e)}return n},getMaxValueAndIndex(t){return t.length===0?{value:0,index:0}:t.reduce((n,e,o)=>e<n.value?{value:e,index:o}:n,{value:t[0],index:0})}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:t=>{if(!t||!t.length)return{};const n={};return t.forEach(e=>{const o=Object.assign({label:e.label,text:e.label},e);n[e==null?void 0:e.value]=o}),n}},Symbol.toStringTag,{value:"Module"}))});class A{static toBlob(n,e="",o=512){const s=(n.split(",")[1]||n).replace(/-/g,"+").replace(/_/g,"/"),c="=".repeat((4-s.length%4)%4),u=s+c;try{const i=atob(u),f=[];for(let a=0;a<i.length;a+=o){const d=i.slice(a,a+o),h=new Array(d.length);for(let g=0;g<d.length;g++)h[g]=d.charCodeAt(g);const y=new Uint8Array(h);f.push(y)}return new Blob(f,{type:e})}catch(i){return console.error("Failed to convert base64 to blob:",i),null}}static toFile(n,e="file.txt",o="text/plain"){const s=n.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),c="=".repeat((4-s.length%4)%4),u=s+c,i=atob(u),f=[];for(let d=0;d<i.length;d+=512){const h=i.slice(d,d+512),y=new Array(h.length);for(let g=0;g<h.length;g++)y[g]=h.charCodeAt(g);f.push(new Uint8Array(y))}const a=new Blob(f,{type:o});return new File([a],e,{type:o})}static encode(n){if(!n)return"";const e=this._stringToUtf8Bytes(n);return this._bytesToBase64(e)}static decode(n){if(!n)return"";n=n.replace(/\s/g,"");const e=this._base64ToBytes(n);return this._utf8BytesToString(e)}static _stringToUtf8Bytes(n){const e=[];for(let o=0;o<n.length;o++){let r=n.charCodeAt(o);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6),e.push(128|r&63);else if(r<55296||r>=57344)e.push(224|r>>12),e.push(128|r>>6&63),e.push(128|r&63);else{o++;const s=r,c=n.charCodeAt(o);if(isNaN(c))throw new Error("代理对不完整");r=65536+((s&1023)<<10)+(c&1023),e.push(240|r>>18),e.push(128|r>>12&63),e.push(128|r>>6&63),e.push(128|r&63)}}return e}static _utf8BytesToString(n){let e="",o=0;for(;o<n.length;){const r=n[o++];if(r<128)e+=String.fromCharCode(r);else if(r>=192&&r<224){const s=n[o++]&63;e+=String.fromCharCode((r&31)<<6|s)}else if(r>=224&&r<240){const s=n[o++]&63,c=n[o++]&63;e+=String.fromCharCode((r&15)<<12|s<<6|c)}else if(r>=240&&r<248){const s=n[o++]&63,c=n[o++]&63,u=n[o++]&63,i=(r&7)<<18|s<<12|c<<6|u,f=Math.floor((i-65536)/1024)+55296,a=(i-65536)%1024+56320;e+=String.fromCharCode(f,a)}else e+="�"}return e}static _bytesToBase64(n){let e="",o=0;for(;o<n.length;){const r=n[o++],s=o<n.length,c=s?n[o++]:0,u=o<n.length,i=u?n[o++]:0,f=r>>2,a=(r&3)<<4|c>>4,d=(c&15)<<2|i>>6,h=i&63;s?u?e+=this.BASE64_CHARS.charAt(f)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(h):e+=this.BASE64_CHARS.charAt(f)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(d)+"=":e+=this.BASE64_CHARS.charAt(f)+this.BASE64_CHARS.charAt(a)+"=="}return e}static _base64ToBytes(n){const e=n.length;let o=0;e>=2&&(n[e-1]==="="&&o++,n[e-2]==="="&&o++);const r=Math.floor(e*3/4)-o,s=new Array(r),c=new Array(256).fill(-1);for(let f=0;f<this.BASE64_CHARS.length;f++)c[this.BASE64_CHARS.charCodeAt(f)]=f;let u=0,i=0;for(;i<e;){const f=c[n.charCodeAt(i++)],a=c[n.charCodeAt(i++)],d=i<e?c[n.charCodeAt(i++)]:-1,h=i<e?c[n.charCodeAt(i++)]:-1;if(f===-1||a===-1)throw new Error("无效的 Base64 字符");const y=f<<2|a>>4;if(s[u++]=y,d!==-1){const g=(a&15)<<4|d>>2;if(s[u++]=g,h!==-1){const p=(d&3)<<6|h;s[u++]=p}}}return s}}M(A,"BASE64_CHARS","ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");const S={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 n=t.getBoundingClientRect();return n.top>=0&&n.left>=0&&n.bottom<=window.innerHeight&&n.right<=window.innerWidth},isLeapYear(t){return t%4===0&&t%100!==0||t%400===0},isMobile(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}},U={getCookie(t){if(!t)return;const n=document.cookie.match(new RegExp("(^| )"+t+"=([^;]+)"));return n?decodeURIComponent(n[2]):null},setCookie(t,n,e=7){const o=new Date;o.setTime(o.getTime()+e*24*60*60*1e3),document.cookie=`${t}=${encodeURIComponent(n)};expires=${o.toUTCString()};path=/`},deleteCookie(t){this.setCookie(t,"",-1)}},C={getTimeString(t,n=!1){return n?new Date().toLocaleString(t,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(t,n){const e=new Date(t).getTime(),o=new Date(n).getTime();return e>o?Math.abs(Math.floor((e-o)/(24*3600*1e3))):Math.abs(Math.floor((o-e)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)},getWhichDays(t,n,e){let o=e;for(let r=1;r<n;r++)switch(r){case 1:case 3:case 5:case 7:case 8:case 10:case 12:o+=31;break;case 2:S.isLeapYear(t)?o+=29:o+=28;break;default:o+=30;break}return o}},B={getOffsetTop(t){if(!t)throw new Error("Element is not provided");if(t instanceof SVGElement){const e=t.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop;return e.top+o}let n=0;for(;t;)n+=t.offsetTop,t=t.offsetParent;return n},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 n=t.pageX||t.clientX+this.getScrollValue().scrollLeft,e=t.pageY||t.clientY+this.getScrollValue().scrollTop;return{pageX:n,pageY:e}},addEventListener(t,n,e){t.addEventListener?t.addEventListener(n,e):t.attachEvent?t.attachEvent("on"+n,e):t["on"+n]=e}},E={saveAsBlob(t,n){const e=document.createElement("a"),o=window.URL.createObjectURL(t);e.href=o,e.download=n,document.body.appendChild(e),e.click(),URL.revokeObjectURL(o),document.body.removeChild(e)}},_={sortFromA2Z(t){return t!=null&&t.length?t.sort((e,o)=>{const r=e.toUpperCase(),s=o.toUpperCase();return r<s?-1:r>s?1:0}):void 0}},O={degrees2Radians(t){return t*Math.PI/180},getDistance(t,n,e,o){const r=this.degrees2Radians(t),s=this.degrees2Radians(e),c=r-s,u=this.degrees2Radians(n)-this.degrees2Radians(o);let i=2*Math.asin(Math.sqrt(Math.pow(Math.sin(c/2),2)+Math.cos(r)*Math.cos(s)*Math.pow(Math.sin(u/2),2)));return i=i*6378.137,i=Math.round(i*1e4)/1e4,i=+i.toFixed(2),console.log("经纬度计算的距离为:"+i),i},calculateDistanceByHaversine(t,n,e="km"){const o=this,r=t.longitude??t.lng,s=t.latitude??t.lat,c=n.longitude??n.lng,u=n.latitude??n.lat;if(r===void 0||s===void 0||c===void 0||u===void 0)throw new Error("无效的坐标格式,缺少经纬度信息");const i=6371,f=o.degrees2Radians(s),a=o.degrees2Radians(u),d=o.degrees2Radians(u-s),h=o.degrees2Radians(c-r),y=Math.sin(d/2)*Math.sin(d/2)+Math.cos(f)*Math.cos(a)*Math.sin(h/2)*Math.sin(h/2),g=2*Math.atan2(Math.sqrt(y),Math.sqrt(1-y)),p=i*g;switch(e){case"m":return p*1e3;case"mi":return p*.621371;case"nmi":return p*.539957;default:return p}},calculateDistancesByHaversine(t,n="km",e=!1){if(t.length<2)return{segments:[],total:0};const o=[];let r=0;for(let s=0;s<t.length-1;s++){const c=this.calculateDistanceByHaversine(t[s],t[s+1],n);o.push(c),r+=c}if(e&&t.length>2){const s=this.calculateDistanceByHaversine(t[t.length-1],t[0],n);o.push(s),r+=s}return{segments:o,total:r}}};class v{static toStandardFormat(n){try{const e=typeof n=="string"?parseFloat(n):n;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(n){try{const e=typeof n=="string"?parseFloat(n):n;if(isNaN(e))throw new Error("输入不是有效的数字");if(e>9999999999999e-2||e<-9999999999999e-2)throw new Error("输入数字超出范围");const o=e<0,r=Math.abs(e),s=Math.floor(r),c=Math.round((r-s)*100),u=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],i=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],f=["角","分"];let a="",d=s;if(d===0)a=u[0];else{let g=0;for(;d>0;){const p=d%10;p!==0?a=u[p]+i[g]+a:a.charAt(0)!==u[0]&&(a=u[p]+a),d=Math.floor(d/10),g++}a=a.replace(/零+/g,"零"),a=a.replace(/零+$/,"")}let h="";if(c>0){const g=Math.floor(c/10),p=c%10;g>0&&(h+=u[g]+f[0]),p>0&&(h+=u[p]+f[1])}else h="整";let y=(o?"负":"")+a+"圆"+h;return y==="零圆整"&&(y="零圆"),y}catch(e){return console.error("转换失败:",e),"格式错误"}}}const R={...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)}},L={isEmptyObject(t){return t?Object.keys(t).length===0&&t.constructor===Object:!0},copy(t,n){for(const e in t)n[e]=t[e]},deepCopy(t,n){for(const e in t){const o=t[e];o instanceof Object?(n[e]={},this.deepCopy(o,n[e])):o instanceof Array?(n[e]=[],this.deepCopy(o,n[e])):n[e]=t[e]}}},T={desensitize(t){return t?t.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||t.slice(0,3)+"****"+t.slice(7):""}},j={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(t,n){return Math.floor(Math.random()*(n-t+1))+t},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},x={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]*)$/},k={getLocal(t){return localStorage.getItem(t)},setLocal(t,n){localStorage.setItem(t,n)},removeLocal(t){localStorage.removeItem(t)},getSession(t){return sessionStorage.getItem(t)},setSession(t,n){sessionStorage.setItem(t,n)},removeSession(t){sessionStorage.removeItem(t)}},I={isExist(t,n){if(!t||!n)return!1;const e=t.split(",");return console.log("判断某元素是否在字符串中",e.indexOf(n)===-1),e.indexOf(n)!==-1},includes(t,n){return!t||!n?!1:t.includes(n)},isJSON(t){try{return JSON.parse(t),!0}catch{return!1}},indexsOfAppear(t,n){let e=-1;const o=[];do e=t.indexOf(n,e+1),e!==-1&&o.push(e);while(e!==-1);return o},getMaxTimesAndVal(t){const n=[0,""],e={};for(let s=0;s<t.length;s++){const c=t.charAt(s);e[c]?e[c]++:e[c]=1}let o=1;for(const s in e)o<e[s]&&(o=e[s]);const r=[];for(const s in e)o==e[s]&&r.push(s);return n[0]=o,n[1]=r.join(),n}},H=t=>{const e=new RegExp("[?&]"+t+"=([^&#]*)","i").exec(window.location.href);return e?decodeURIComponent(e[1]):null};function P(t){return new URLSearchParams(window.location.search).get(t)}const N={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:H,getQueryParam:P},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},$={toList(t,n=2){console.log(t,n);const e={};for(let r=0;r<n;r++)e[r]=[];t.forEach((r,s)=>e[s%n].push(r));const o=[];for(const r in e)o.push(...e[r]);return o},jsLayout(t,n,e){const o=t.offsetWidth,r=n[0].offsetWidth,s=parseInt((o/r).toString()),c=(o-r*s)/(s-1),u=[];for(let i=0,f=n.length;i<f;i++){const a=n[i];if(i<s)a.style.left=(r+c)*i+"px",u[i]=a.offsetHeight;else{const{index:d,value:h}=w.getMinValueAndIndex(u);a.style.left=(r+c)*d+"px",a.style.top=h+e+"px",u[d]=a.offsetHeight+e+h}}}};l.Base64Utils=A,l.MoneyFormatter=v,l.arrayUtils=w,l.booleanUtils=S,l.cookieUtils=U,l.dateUtils=C,l.documentUtils=B,l.downloadUtils=E,l.letterUtils=_,l.mapUtils=O,l.numberUtils=R,l.objectUtils=L,l.phoneUtils=T,l.randomUtils=j,l.regexpUtils=x,l.storageUtils=k,l.stringUtils=I,l.urlUtils=N,l.waterfallUtils=$,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(h,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(h=typeof globalThis<"u"?globalThis:h||self,m(h.yhkitUtils={}))})(this,function(h){"use strict";const b=Object.assign({unique(t){return t?Array.from(new Set(t)):[]},isExist(t,n){return!t||!n?!1:t.indexOf(n)!==-1},countOfAppear(t,n){let e=0;for(const o of t)o===n&&e++;return e},indexsOfAppear(t,n){let e=-1;const o=[];do e=t.indexOf(n,e+1),e!==-1&&o.push(e);while(e!==-1);return o},sort(t,n="asc"){return t?t.sort((e,o)=>n==="asc"?e>o?1:-1:e<o?1:-1):[]},shuffle(t){if(!t)return[];for(let n=t.length-1;n>0;n--){const e=Math.floor(Math.random()*(n+1));[t[n],t[e]]=[t[e],t[n]]}return t},getMaxValue(t){return t?Math.max(...t):0},getMinValue(t){return t?Math.min(...t):0},getMinValueAndIndex(t){if(t.length===0)return{value:0,index:0};const n={value:t[0],index:0};for(let e=1,o=t.length;e<o;e++){const r=t[e];n.value>r&&(n.value=r,n.index=e)}return n},getMaxValueAndIndex(t){return t.length===0?{value:0,index:0}:t.reduce((n,e,o)=>e<n.value?{value:e,index:o}:n,{value:t[0],index:0})}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:t=>{if(!t||!t.length)return{};const n={};return t.forEach(e=>{const o=Object.assign({label:e.label,text:e.label},e);n[e?.value]=o}),n}},Symbol.toStringTag,{value:"Module"}))});class A{static BASE64_CHARS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";static toBlob(n,e="",o=512){const s=(n.split(",")[1]||n).replace(/-/g,"+").replace(/_/g,"/"),c="=".repeat((4-s.length%4)%4),l=s+c;try{const i=atob(l),d=[];for(let a=0;a<i.length;a+=o){const u=i.slice(a,a+o),f=new Array(u.length);for(let g=0;g<u.length;g++)f[g]=u.charCodeAt(g);const y=new Uint8Array(f);d.push(y)}return new Blob(d,{type:e})}catch(i){return console.error("Failed to convert base64 to blob:",i),null}}static toFile(n,e="file.txt",o="text/plain"){const s=n.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),c="=".repeat((4-s.length%4)%4),l=s+c,i=atob(l),d=[];for(let u=0;u<i.length;u+=512){const f=i.slice(u,u+512),y=new Array(f.length);for(let g=0;g<f.length;g++)y[g]=f.charCodeAt(g);d.push(new Uint8Array(y))}const a=new Blob(d,{type:o});return new File([a],e,{type:o})}static encode(n){if(!n)return"";const e=this._stringToUtf8Bytes(n);return this._bytesToBase64(e)}static decode(n){if(!n)return"";n=n.replace(/\s/g,"");const e=this._base64ToBytes(n);return this._utf8BytesToString(e)}static _stringToUtf8Bytes(n){const e=[];for(let o=0;o<n.length;o++){let r=n.charCodeAt(o);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6),e.push(128|r&63);else if(r<55296||r>=57344)e.push(224|r>>12),e.push(128|r>>6&63),e.push(128|r&63);else{o++;const s=r,c=n.charCodeAt(o);if(isNaN(c))throw new Error("代理对不完整");r=65536+((s&1023)<<10)+(c&1023),e.push(240|r>>18),e.push(128|r>>12&63),e.push(128|r>>6&63),e.push(128|r&63)}}return e}static _utf8BytesToString(n){let e="",o=0;for(;o<n.length;){const r=n[o++];if(r<128)e+=String.fromCharCode(r);else if(r>=192&&r<224){const s=n[o++]&63;e+=String.fromCharCode((r&31)<<6|s)}else if(r>=224&&r<240){const s=n[o++]&63,c=n[o++]&63;e+=String.fromCharCode((r&15)<<12|s<<6|c)}else if(r>=240&&r<248){const s=n[o++]&63,c=n[o++]&63,l=n[o++]&63,i=(r&7)<<18|s<<12|c<<6|l,d=Math.floor((i-65536)/1024)+55296,a=(i-65536)%1024+56320;e+=String.fromCharCode(d,a)}else e+="�"}return e}static _bytesToBase64(n){let e="",o=0;for(;o<n.length;){const r=n[o++],s=o<n.length,c=s?n[o++]:0,l=o<n.length,i=l?n[o++]:0,d=r>>2,a=(r&3)<<4|c>>4,u=(c&15)<<2|i>>6,f=i&63;s?l?e+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(u)+this.BASE64_CHARS.charAt(f):e+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(u)+"=":e+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+"=="}return e}static _base64ToBytes(n){const e=n.length;let o=0;e>=2&&(n[e-1]==="="&&o++,n[e-2]==="="&&o++);const r=Math.floor(e*3/4)-o,s=new Array(r),c=new Array(256).fill(-1);for(let d=0;d<this.BASE64_CHARS.length;d++)c[this.BASE64_CHARS.charCodeAt(d)]=d;let l=0,i=0;for(;i<e;){const d=c[n.charCodeAt(i++)],a=c[n.charCodeAt(i++)],u=i<e?c[n.charCodeAt(i++)]:-1,f=i<e?c[n.charCodeAt(i++)]:-1;if(d===-1||a===-1)throw new Error("无效的 Base64 字符");const y=d<<2|a>>4;if(s[l++]=y,u!==-1){const g=(a&15)<<4|u>>2;if(s[l++]=g,f!==-1){const p=(u&3)<<6|f;s[l++]=p}}}return s}}const w={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 n=t.getBoundingClientRect();return n.top>=0&&n.left>=0&&n.bottom<=window.innerHeight&&n.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 n=document.cookie.match(new RegExp("(^| )"+t+"=([^;]+)"));return n?decodeURIComponent(n[2]):null},setCookie(t,n,e=7){const o=new Date;o.setTime(o.getTime()+e*24*60*60*1e3),document.cookie=`${t}=${encodeURIComponent(n)};expires=${o.toUTCString()};path=/`},deleteCookie(t){this.setCookie(t,"",-1)}},M={getTimeString(t,n=!1){return n?new Date().toLocaleString(t,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(t,n){const e=new Date(t).getTime(),o=new Date(n).getTime();return e>o?Math.abs(Math.floor((e-o)/(24*3600*1e3))):Math.abs(Math.floor((o-e)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)},getWhichDays(t,n,e){let o=e;for(let r=1;r<n;r++)switch(r){case 1:case 3:case 5:case 7:case 8:case 10:case 12:o+=31;break;case 2:w.isLeapYear(t)?o+=29:o+=28;break;default:o+=30;break}return o}},U={getOffsetTop(t){if(!t)throw new Error("Element is not provided");if(t instanceof SVGElement){const e=t.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop;return e.top+o}let n=0;for(;t;)n+=t.offsetTop,t=t.offsetParent;return n},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 n=t.pageX||t.clientX+this.getScrollValue().scrollLeft,e=t.pageY||t.clientY+this.getScrollValue().scrollTop;return{pageX:n,pageY:e}},addEventListener(t,n,e){t.addEventListener?t.addEventListener(n,e):t.attachEvent?t.attachEvent("on"+n,e):t["on"+n]=e},getViewportWidth(){return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth},getViewportHeight(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}},C={saveAsBlob(t,n){const e=document.createElement("a"),o=window.URL.createObjectURL(t);e.href=o,e.download=n,document.body.appendChild(e),e.click(),URL.revokeObjectURL(o),document.body.removeChild(e)}},B={sortFromA2Z(t){return t?.length?t.sort((e,o)=>{const r=e.toUpperCase(),s=o.toUpperCase();return r<s?-1:r>s?1:0}):void 0}},E={degrees2Radians(t){return t*Math.PI/180},getDistance(t,n,e,o){const r=this.degrees2Radians(t),s=this.degrees2Radians(e),c=r-s,l=this.degrees2Radians(n)-this.degrees2Radians(o);let i=2*Math.asin(Math.sqrt(Math.pow(Math.sin(c/2),2)+Math.cos(r)*Math.cos(s)*Math.pow(Math.sin(l/2),2)));return i=i*6378.137,i=Math.round(i*1e4)/1e4,i=+i.toFixed(2),console.log("经纬度计算的距离为:"+i),i},calculateDistanceByHaversine(t,n,e="km"){const o=this,r=t.longitude??t.lng,s=t.latitude??t.lat,c=n.longitude??n.lng,l=n.latitude??n.lat;if(r===void 0||s===void 0||c===void 0||l===void 0)throw new Error("无效的坐标格式,缺少经纬度信息");const i=6371,d=o.degrees2Radians(s),a=o.degrees2Radians(l),u=o.degrees2Radians(l-s),f=o.degrees2Radians(c-r),y=Math.sin(u/2)*Math.sin(u/2)+Math.cos(d)*Math.cos(a)*Math.sin(f/2)*Math.sin(f/2),g=2*Math.atan2(Math.sqrt(y),Math.sqrt(1-y)),p=i*g;switch(e){case"m":return p*1e3;case"mi":return p*.621371;case"nmi":return p*.539957;default:return p}},calculateDistancesByHaversine(t,n="km",e=!1){if(t.length<2)return{segments:[],total:0};const o=[];let r=0;for(let s=0;s<t.length-1;s++){const c=this.calculateDistanceByHaversine(t[s],t[s+1],n);o.push(c),r+=c}if(e&&t.length>2){const s=this.calculateDistanceByHaversine(t[t.length-1],t[0],n);o.push(s),r+=s}return{segments:o,total:r}}};class _{static toStandardFormat(n){try{const e=typeof n=="string"?parseFloat(n):n;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(n){try{const e=typeof n=="string"?parseFloat(n):n;if(isNaN(e))throw new Error("输入不是有效的数字");if(e>9999999999999e-2||e<-9999999999999e-2)throw new Error("输入数字超出范围");const o=e<0,r=Math.abs(e),s=Math.floor(r),c=Math.round((r-s)*100),l=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],i=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],d=["角","分"];let a="",u=s;if(u===0)a=l[0];else{let g=0;for(;u>0;){const p=u%10;p!==0?a=l[p]+i[g]+a:a.charAt(0)!==l[0]&&(a=l[p]+a),u=Math.floor(u/10),g++}a=a.replace(/零+/g,"零"),a=a.replace(/零+$/,"")}let f="";if(c>0){const g=Math.floor(c/10),p=c%10;g>0&&(f+=l[g]+d[0]),p>0&&(f+=l[p]+d[1])}else f="整";let y=(o?"负":"")+a+"圆"+f;return y==="零圆整"&&(y="零圆"),y}catch(e){return console.error("转换失败:",e),"格式错误"}}}const O={...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)}},v={isEmptyObject(t){return t?Object.keys(t).length===0&&t.constructor===Object:!0},copy(t,n){for(const e in t)n[e]=t[e]},deepCopy(t,n){for(const e in t){const o=t[e];o instanceof Object?(n[e]={},this.deepCopy(o,n[e])):o instanceof Array?(n[e]=[],this.deepCopy(o,n[e])):n[e]=t[e]}}},R={desensitize(t){return t?t.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||t.slice(0,3)+"****"+t.slice(7):""}},L={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(t,n){return Math.floor(Math.random()*(n-t+1))+t},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},T={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]*)$/},j={getLocal(t){return localStorage.getItem(t)},setLocal(t,n){localStorage.setItem(t,n)},removeLocal(t){localStorage.removeItem(t)},getSession(t){return sessionStorage.getItem(t)},setSession(t,n){sessionStorage.setItem(t,n)},removeSession(t){sessionStorage.removeItem(t)}},x={isExist(t,n){if(!t||!n)return!1;const e=t.split(",");return console.log("判断某元素是否在字符串中",e.indexOf(n)===-1),e.indexOf(n)!==-1},includes(t,n){return!t||!n?!1:t.includes(n)},isJSON(t){try{return JSON.parse(t),!0}catch{return!1}},indexsOfAppear(t,n){let e=-1;const o=[];do e=t.indexOf(n,e+1),e!==-1&&o.push(e);while(e!==-1);return o},getMaxTimesAndVal(t){const n=[0,""],e={};for(let s=0;s<t.length;s++){const c=t.charAt(s);e[c]?e[c]++:e[c]=1}let o=1;for(const s in e)o<e[s]&&(o=e[s]);const r=[];for(const s in e)o==e[s]&&r.push(s);return n[0]=o,n[1]=r.join(),n}},k=t=>{const e=new RegExp("[?&]"+t+"=([^&#]*)","i").exec(window.location.href);return e?decodeURIComponent(e[1]):null};function H(t){return new URLSearchParams(window.location.search).get(t)}const I={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:k,getQueryParam:H},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},P={toList(t,n=2){console.log(t,n);const e={};for(let r=0;r<n;r++)e[r]=[];t.forEach((r,s)=>e[s%n].push(r));const o=[];for(const r in e)o.push(...e[r]);return o},jsLayout(t,n,e){const o=t.offsetWidth,r=n[0].offsetWidth,s=parseInt((o/r).toString()),c=(o-r*s)/(s-1),l=[];for(let i=0,d=n.length;i<d;i++){const a=n[i];if(i<s)a.style.left=(r+c)*i+"px",l[i]=a.offsetHeight;else{const{index:u,value:f}=b.getMinValueAndIndex(l);a.style.left=(r+c)*u+"px",a.style.top=f+e+"px",l[u]=a.offsetHeight+e+f}}}};h.Base64Utils=A,h.MoneyFormatter=_,h.arrayUtils=b,h.booleanUtils=w,h.cookieUtils=S,h.dateUtils=M,h.documentUtils=U,h.downloadUtils=C,h.letterUtils=B,h.mapUtils=E,h.numberUtils=O,h.objectUtils=v,h.phoneUtils=R,h.randomUtils=L,h.regexpUtils=T,h.storageUtils=j,h.stringUtils=x,h.urlUtils=I,h.waterfallUtils=P,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -37,4 +37,14 @@ export declare const documentUtils: {
|
|
|
37
37
|
* @param fn 事件处理函数
|
|
38
38
|
*/
|
|
39
39
|
addEventListener(element: any, eventName: string, fn: any): void;
|
|
40
|
+
/**
|
|
41
|
+
* 获取视口宽度
|
|
42
|
+
* @returns 视口宽度
|
|
43
|
+
*/
|
|
44
|
+
getViewportWidth(): number;
|
|
45
|
+
/**
|
|
46
|
+
* 获取视口高度
|
|
47
|
+
* @returns 视口高度
|
|
48
|
+
*/
|
|
49
|
+
getViewportHeight(): number;
|
|
40
50
|
};
|
|
@@ -8,6 +8,10 @@ export declare const numberUtils: {
|
|
|
8
8
|
* @returns 是否为数字。true 是;false 否
|
|
9
9
|
*/
|
|
10
10
|
isNumber<T>(val: T): boolean;
|
|
11
|
-
toMoney: (
|
|
11
|
+
toMoney: (/**
|
|
12
|
+
* 判断是否为数字
|
|
13
|
+
* @param val 待判断的值
|
|
14
|
+
* @returns 是否为数字。true 是;false 否
|
|
15
|
+
*/ x: number) => string;
|
|
12
16
|
toLetter: (num: number) => string;
|
|
13
17
|
};
|