@yh-kit/utils 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.js CHANGED
@@ -1,127 +1,180 @@
1
- const i = (t) => {
2
- if (!t || !t.length) return {};
3
- const e = {};
4
- return t.forEach((r) => {
5
- const n = Object.assign({ label: r.label, text: r.label }, r);
6
- e[r == null ? void 0 : r.value] = n;
7
- }), e;
8
- }, u = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1
+ const p = (e) => {
2
+ if (!e || !e.length) return {};
3
+ const t = {};
4
+ return e.forEach((n) => {
5
+ const r = Object.assign({ label: n.label, text: n.label }, n);
6
+ t[n == null ? void 0 : n.value] = r;
7
+ }), t;
8
+ }, b = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
9
9
  __proto__: null,
10
- toEnumObj: i
11
- }, Symbol.toStringTag, { value: "Module" })), h = {
12
- ...u,
13
- /**
14
- * 数组去重
15
- * @param arr 数组
16
- * @returns 去重后的数组
17
- */
18
- unique: (t) => t ? Array.from(new Set(t)) : [],
19
- /**
20
- * 判断某元素是否在数组中
21
- * @param arr 数组
22
- * @param element 查询元素
23
- * @returns 是否存在。true 存在;false 不存在
24
- */
25
- isExist(t, e) {
26
- return !t || !e ? !1 : t.indexOf(e) !== -1;
27
- },
28
- /**
29
- * 统计数组中某元素出现的次数:对于大型数组,手动循环的性能略优于 filter 和 reduce。
30
- * @param arr 数组
31
- * @param target 目标元素
32
- * @returns 出现次数
33
- */
34
- countOfAppear(t, e) {
35
- let r = 0;
36
- for (const n of t)
37
- n === e && r++;
38
- return r;
10
+ toEnumObj: p
11
+ }, Symbol.toStringTag, { value: "Module" })), A = Object.assign(
12
+ {
13
+ /**
14
+ * 数组去重
15
+ * @param arr 数组
16
+ * @returns 去重后的数组
17
+ */
18
+ unique(e) {
19
+ return e ? Array.from(new Set(e)) : [];
20
+ },
21
+ /**
22
+ * 判断某元素是否在数组中
23
+ * @param arr 数组
24
+ * @param element 查询元素
25
+ * @returns 是否存在。true 存在;false 不存在
26
+ */
27
+ isExist(e, t) {
28
+ return !e || !t ? !1 : e.indexOf(t) !== -1;
29
+ },
30
+ /**
31
+ * 统计数组中某元素出现的次数:对于大型数组,手动循环的性能略优于 filter 和 reduce。
32
+ * @param arr 数组
33
+ * @param target 目标元素
34
+ * @returns 出现次数
35
+ */
36
+ countOfAppear(e, t) {
37
+ let n = 0;
38
+ for (const r of e)
39
+ r === t && n++;
40
+ return n;
41
+ },
42
+ /**
43
+ * 数组排序-默认升序
44
+ * @param arr 数组
45
+ * @param order 排序方式:asc 升序;desc 降序
46
+ * @returns 排序后的数组
47
+ */
48
+ sort(e, t = "asc") {
49
+ return e ? e.sort((n, r) => t === "asc" ? n > r ? 1 : -1 : n < r ? 1 : -1) : [];
50
+ },
51
+ /**
52
+ * 数组乱序(洗牌算法)
53
+ * 1. 从数组的最后一个元素开始,将其与随机位置的元素交换位置。
54
+ * 2. 然后,从倒数第二个元素开始,将其与随机位置的元素交换位置。
55
+ * 3. 以此类推,直到第一个元素。
56
+ * 4. 这样,数组中的元素就会被随机打乱顺序。
57
+ * 5. 注意,这个算法会改变原数组。如果不想改变原数组,可以先复制一份再进行操作。
58
+ * 6. 时间复杂度:O(n)
59
+ * @param arr 数组
60
+ * @returns
61
+ */
62
+ shuffle(e) {
63
+ if (!e)
64
+ return [];
65
+ for (let t = e.length - 1; t > 0; t--) {
66
+ const n = Math.floor(Math.random() * (t + 1));
67
+ [e[t], e[n]] = [e[n], e[t]];
68
+ }
69
+ return e;
70
+ }
39
71
  },
40
- /**
41
- * 数组排序-默认升序
42
- * @param arr 数组
43
- * @param order 排序方式:asc 升序;desc 降序
44
- * @returns 排序后的数组
45
- */
46
- sort(t, e = "asc") {
47
- return t ? t.sort((r, n) => e === "asc" ? r > n ? 1 : -1 : r < n ? 1 : -1) : [];
72
+ {
73
+ ...b
74
+ }
75
+ ), j = {
76
+ /**
77
+ * 将Base64编码的字符串转换为Blob对象。
78
+ * Blob对象用于表示二进制大型对象,可以在浏览器环境中处理大文件或二进制数据。
79
+ *
80
+ * @param base64 Base64编码的字符串。
81
+ * @param contentType 可选参数,表示生成的Blob对象的MIME类型,默认为空字符串。
82
+ * @param sliceSize 可选参数,表示分片大小,默认为512字节。用于控制每次处理的Base64字符串长度,以优化大文件的处理。
83
+ * @returns 返回转换后的Blob对象,如果转换失败,则返回null。
84
+ */
85
+ toBlob(e, t = "", n = 512) {
86
+ const o = (e.split(",")[1] || e).replace(/-/g, "+").replace(/_/g, "/"), i = "=".repeat((4 - o.length % 4) % 4), g = o + i;
87
+ try {
88
+ const l = atob(g), f = [];
89
+ for (let a = 0; a < l.length; a += n) {
90
+ const c = l.slice(a, a + n), u = new Array(c.length);
91
+ for (let s = 0; s < c.length; s++)
92
+ u[s] = c.charCodeAt(s);
93
+ const d = new Uint8Array(u);
94
+ f.push(d);
95
+ }
96
+ return new Blob(f, { type: t });
97
+ } catch (l) {
98
+ return console.error("Failed to convert base64 to blob:", l), null;
99
+ }
48
100
  },
49
101
  /**
50
- * 数组乱序(洗牌算法)
51
- * 1. 从数组的最后一个元素开始,将其与随机位置的元素交换位置。
52
- * 2. 然后,从倒数第二个元素开始,将其与随机位置的元素交换位置。
53
- * 3. 以此类推,直到第一个元素。
54
- * 4. 这样,数组中的元素就会被随机打乱顺序。
55
- * 5. 注意,这个算法会改变原数组。如果不想改变原数组,可以先复制一份再进行操作。
56
- * 6. 时间复杂度:O(n)
57
- * @param arr 数组
58
- * @returns
59
- */
60
- shuffle(t) {
61
- if (!t)
62
- return [];
63
- for (let e = t.length - 1; e > 0; e--) {
64
- const r = Math.floor(Math.random() * (e + 1));
65
- [t[e], t[r]] = [t[r], t[e]];
102
+ * 将Base64编码的字符串转换为File对象。
103
+ * 这个函数接受一个Base64编码的字符串,一个可选的文件名和一个可选的MIME类型,
104
+ * 并返回一个代表原始数据的File对象。
105
+ *
106
+ * @param base64 Base64编码的字符串。
107
+ * @param fileName 文件名,默认为"file.txt"。
108
+ * @param mimeType MIME类型,默认为"text/plain"。
109
+ * @returns 返回一个File对象,包含解码后的数据。
110
+ */
111
+ toFile(e, t = "file.txt", n = "text/plain") {
112
+ const o = e.replace(/^data:.+;base64,/, "").replace(/-/g, "+").replace(/_/g, "/"), i = "=".repeat((4 - o.length % 4) % 4), g = o + i, l = atob(g), f = [];
113
+ for (let c = 0; c < l.length; c += 512) {
114
+ const u = l.slice(c, c + 512), d = new Array(u.length);
115
+ for (let s = 0; s < u.length; s++)
116
+ d[s] = u.charCodeAt(s);
117
+ f.push(new Uint8Array(d));
66
118
  }
67
- return t;
119
+ const a = new Blob(f, { type: n });
120
+ return new File([a], t, { type: n });
68
121
  }
69
- }, y = {
122
+ }, E = {
70
123
  /**
71
124
  * 检查是否为空字符串
72
125
  * @param str 要检查的字符串
73
126
  * @returns 如果字符串为空,则返回 true,否则返回 false
74
127
  */
75
- isEmptyString(t) {
76
- return typeof t == "string" && t.trim() === "";
128
+ isEmptyString(e) {
129
+ return typeof e == "string" && e.trim() === "";
77
130
  },
78
131
  /**
79
132
  * 判断是否为数字
80
133
  * @param val 要检查的值
81
134
  * @returns 如果值是数字,则返回 true,否则返回 false
82
135
  */
83
- isNumber(t) {
84
- return typeof t == "number" && !isNaN(t);
136
+ isNumber(e) {
137
+ return typeof e == "number" && !isNaN(e);
85
138
  },
86
139
  /**
87
140
  * 判断是否为对象
88
141
  * @param val 要检查的值
89
142
  * @returns 如果值是对象,则返回 true,否则返回 false
90
143
  */
91
- isObject(t) {
92
- return t !== null && typeof t == "object" && !Array.isArray(t);
144
+ isObject(e) {
145
+ return e !== null && typeof e == "object" && !Array.isArray(e);
93
146
  },
94
147
  /**
95
148
  * 判断对象是否为空
96
149
  * @param obj 要检查的对象
97
150
  * @returns 如果对象为空,则返回 true,否则返回 false
98
151
  */
99
- isEmptyObject(t) {
100
- return t ? Object.keys(t).length === 0 && t.constructor === Object : !0;
152
+ isEmptyObject(e) {
153
+ return e ? Object.keys(e).length === 0 && e.constructor === Object : !0;
101
154
  },
102
155
  /**
103
156
  * 判断是否为布尔值
104
157
  * @param val 要检查的值
105
158
  * @returns 如果值是布尔值,则返回 true,否则返回 false
106
159
  */
107
- isBoolean(t) {
108
- return typeof t == "boolean";
160
+ isBoolean(e) {
161
+ return typeof e == "boolean";
109
162
  },
110
163
  /**
111
164
  * 判断是否为数组
112
165
  * @param val 要检查的值
113
166
  * @returns 如果值是数组,则返回 true,否则返回 false
114
167
  */
115
- isArray(t) {
116
- return Array.isArray(t);
168
+ isArray(e) {
169
+ return Array.isArray(e);
117
170
  },
118
171
  /**
119
172
  * 判断是否为函数
120
173
  * @param val 要检查的值
121
174
  * @returns
122
175
  */
123
- isFunction(t) {
124
- return typeof t == "function";
176
+ isFunction(e) {
177
+ return typeof e == "function";
125
178
  },
126
179
  /**
127
180
  * 判断是否为 Promise 对象
@@ -129,41 +182,41 @@ const i = (t) => {
129
182
  * @returns 如果对象是 Promise 对象,则返回 true,否则返回 false
130
183
  */
131
184
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
132
- isPromise(t) {
133
- return !!t && (typeof t == "object" || typeof t == "function") && typeof t.then == "function";
185
+ isPromise(e) {
186
+ return !!e && (typeof e == "object" || typeof e == "function") && typeof e.then == "function";
134
187
  },
135
188
  /**
136
189
  * 判断是否为 DOM 元素
137
190
  * @param obj 要检查的对象
138
191
  * @returns 如果对象是 DOM 元素,则返回 true,否则返回 false
139
192
  */
140
- isElement(t) {
141
- return t instanceof Element;
193
+ isElement(e) {
194
+ return e instanceof Element;
142
195
  },
143
196
  /**
144
197
  * 判断手机号格式(中国)
145
198
  * @param str 手机号字符串
146
199
  * @returns true 表示手机号格式正确,false 表示手机号格式错误
147
200
  */
148
- isPhone(t) {
149
- return /^1[3-9]\d{9}$/.test(t);
201
+ isPhone(e) {
202
+ return /^1[3-9]\d{9}$/.test(e);
150
203
  },
151
204
  /**
152
205
  * 判断邮箱格式
153
206
  * @param str 邮箱字符串
154
207
  * @returns true 表示邮箱格式正确,false 表示邮箱格式错误
155
208
  */
156
- isEmail(t) {
157
- return /^[\w.-]+@[\w.-]+\.\w+$/.test(t);
209
+ isEmail(e) {
210
+ return /^[\w.-]+@[\w.-]+\.\w+$/.test(e);
158
211
  },
159
212
  /**
160
213
  * 判断字符串是否为 JSON
161
214
  * @param str 字符串
162
215
  * @returns true 表示是 JSON,false 表示不是 JSON
163
216
  */
164
- isJSON(t) {
217
+ isJSON(e) {
165
218
  try {
166
- return JSON.parse(t), !0;
219
+ return JSON.parse(e), !0;
167
220
  } catch {
168
221
  return !1;
169
222
  }
@@ -176,17 +229,17 @@ const i = (t) => {
176
229
  * const img = new Image();
177
230
  * img.src = "URL_ADDRESS * img.src = "https://example.com/image.jpg";
178
231
  */
179
- isImageLoaded(t) {
180
- return t.complete && t.naturalWidth !== 0;
232
+ isImageLoaded(e) {
233
+ return e.complete && e.naturalWidth !== 0;
181
234
  },
182
235
  /**
183
236
  * 判断元素是否在可视区域内
184
237
  * @param el 元素对象
185
238
  * @returns true 表示元素在可视区域内,false 表示元素不在可视区域内
186
239
  */
187
- isInViewport(t) {
188
- const e = t.getBoundingClientRect();
189
- return e.top >= 0 && e.left >= 0 && e.bottom <= window.innerHeight && e.right <= window.innerWidth;
240
+ isInViewport(e) {
241
+ const t = e.getBoundingClientRect();
242
+ return t.top >= 0 && t.left >= 0 && t.bottom <= window.innerHeight && t.right <= window.innerWidth;
190
243
  },
191
244
  /**
192
245
  * 判断是否为闰年
@@ -200,8 +253,8 @@ const i = (t) => {
200
253
  * isLeapYear(2025); // false
201
254
  * isLeapYear(2024); // true
202
255
  */
203
- isLeapYear(t) {
204
- return t % 4 === 0 && t % 100 !== 0 || t % 400 === 0;
256
+ isLeapYear(e) {
257
+ return e % 4 === 0 && e % 100 !== 0 || e % 400 === 0;
205
258
  },
206
259
  /**
207
260
  * 判断是否为移动端
@@ -210,16 +263,16 @@ const i = (t) => {
210
263
  isMobile() {
211
264
  return /Mobi|Android|iPhone/i.test(navigator.userAgent);
212
265
  }
213
- }, m = {
266
+ }, _ = {
214
267
  /**
215
268
  * 通过传入的name获取cookie的值
216
269
  * @param name cookie的name
217
270
  * @returns cookie的值
218
271
  */
219
- getCookie(t) {
220
- if (!t) return;
221
- const e = document.cookie.match(new RegExp("(^| )" + t + "=([^;]+)"));
222
- return e ? decodeURIComponent(e[2]) : null;
272
+ getCookie(e) {
273
+ if (!e) return;
274
+ const t = document.cookie.match(new RegExp("(^| )" + e + "=([^;]+)"));
275
+ return t ? decodeURIComponent(t[2]) : null;
223
276
  },
224
277
  /**
225
278
  * 设置 cookie
@@ -228,27 +281,27 @@ const i = (t) => {
228
281
  * @param days cookie的过期时间,默认7天。如果为0,则表示cookie在会话结束时过期。如果为负数,则表示cookie已过期。
229
282
  * @returns void
230
283
  */
231
- setCookie(t, e, r = 7) {
232
- const n = /* @__PURE__ */ new Date();
233
- n.setTime(n.getTime() + r * 24 * 60 * 60 * 1e3), document.cookie = `${t}=${encodeURIComponent(e)};expires=${n.toUTCString()};path=/`;
284
+ setCookie(e, t, n = 7) {
285
+ const r = /* @__PURE__ */ new Date();
286
+ r.setTime(r.getTime() + n * 24 * 60 * 60 * 1e3), document.cookie = `${e}=${encodeURIComponent(t)};expires=${r.toUTCString()};path=/`;
234
287
  },
235
288
  /**
236
289
  * 删除cookie
237
290
  * @param name cookie的name
238
291
  * @returns void
239
292
  */
240
- deleteCookie(t) {
241
- this.setCookie(t, "", -1);
293
+ deleteCookie(e) {
294
+ this.setCookie(e, "", -1);
242
295
  }
243
- }, b = {
296
+ }, C = {
244
297
  /**
245
298
  * 获取当前时间字符串
246
299
  * @param locales 区域设置。如:'zh-CN','en-US',"chinese"。默认'zh-CN'。
247
300
  * @param hour12 是否使用12小时制。默认false,使用24小时制。
248
301
  * @returns 当前时间的字符串。如:'2025/5/27 16:54:45'
249
302
  */
250
- getTimeString(t, e = !1) {
251
- return e ? (/* @__PURE__ */ new Date()).toLocaleString(t, { hour12: !0 }) : (/* @__PURE__ */ new Date()).toLocaleString("chinese", { hour12: !1 });
303
+ getTimeString(e, t = !1) {
304
+ return t ? (/* @__PURE__ */ new Date()).toLocaleString(e, { hour12: !0 }) : (/* @__PURE__ */ new Date()).toLocaleString("chinese", { hour12: !1 });
252
305
  },
253
306
  /**
254
307
  * 计算两个日期相差天数
@@ -256,9 +309,9 @@ const i = (t) => {
256
309
  * @param date2 日期2
257
310
  * @returns 相差天数
258
311
  */
259
- diffDays(t, e) {
260
- const r = new Date(t).getTime(), n = new Date(e).getTime();
261
- return r > n ? Math.abs(Math.floor((r - n) / (24 * 3600 * 1e3))) : Math.abs(Math.floor((n - r) / (24 * 3600 * 1e3)));
312
+ diffDays(e, t) {
313
+ const n = new Date(e).getTime(), r = new Date(t).getTime();
314
+ return n > r ? Math.abs(Math.floor((n - r) / (24 * 3600 * 1e3))) : Math.abs(Math.floor((r - n) / (24 * 3600 * 1e3)));
262
315
  },
263
316
  /**
264
317
  * 生成唯一ID(时间戳+随机数)
@@ -267,61 +320,98 @@ const i = (t) => {
267
320
  uniqueId() {
268
321
  return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
269
322
  }
270
- }, S = {
323
+ }, M = {
324
+ /**
325
+ * 将blob对象转化成文件并导出到本地
326
+ * @param blob blob对象
327
+ * @param filename 文件名
328
+ */
329
+ saveAsBlob(e, t) {
330
+ const n = document.createElement("a"), r = window.URL.createObjectURL(e);
331
+ n.href = r, n.download = t, document.body.appendChild(n), n.click(), URL.revokeObjectURL(r), document.body.removeChild(n);
332
+ }
333
+ }, x = {
334
+ /**
335
+ * 获取元素相对于文档顶部的偏移量(距离)
336
+ * 处理了SVG元素的特殊情况。
337
+ * @param el 元素
338
+ * @returns 偏移量(距离值)
339
+ */
340
+ getOffsetTop(e) {
341
+ if (!e)
342
+ throw new Error("Element is not provided");
343
+ if (e instanceof SVGElement) {
344
+ const n = e.getBoundingClientRect(), r = window.pageYOffset || document.documentElement.scrollTop;
345
+ return n.top + r;
346
+ }
347
+ let t = 0;
348
+ for (; e; )
349
+ t += e.offsetTop, e = e.offsetParent;
350
+ return t;
351
+ }
352
+ }, B = {
271
353
  /**
272
354
  * 将选中的字母数组从A-Z排序:用于试题选择答案的排序实例
273
355
  * @param arr 字母数组
274
356
  * @returns
275
357
  */
276
- sortFromA2Z: (t) => t != null && t.length ? t.sort((r, n) => {
277
- const o = r.toUpperCase(), s = n.toUpperCase();
278
- return o < s ? -1 : o > s ? 1 : 0;
279
- }) : void 0
280
- }, c = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], l = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
358
+ sortFromA2Z(e) {
359
+ return e != null && e.length ? e.sort((n, r) => {
360
+ const o = n.toUpperCase(), i = r.toUpperCase();
361
+ return o < i ? -1 : o > i ? 1 : 0;
362
+ }) : void 0;
363
+ }
364
+ }, h = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
281
365
  __proto__: null,
282
- toLetter: c
283
- }, Symbol.toStringTag, { value: "Module" })), a = (t) => t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), f = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
366
+ toLetter: h
367
+ }, Symbol.toStringTag, { value: "Module" })), m = (e) => e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), w = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
284
368
  __proto__: null,
285
- toMoney: a
286
- }, Symbol.toStringTag, { value: "Module" })), O = {
287
- ...l,
288
- ...f,
369
+ toMoney: m
370
+ }, Symbol.toStringTag, { value: "Module" })), L = {
371
+ ...y,
372
+ ...w,
289
373
  /**
290
374
  * 判断是否为数字
291
375
  * @param val 待判断的值
292
376
  * @returns 是否为数字。true 是;false 否
293
377
  */
294
- isNumber(t) {
295
- return typeof t == "number" && !isNaN(t);
378
+ isNumber(e) {
379
+ return typeof e == "number" && !isNaN(e);
296
380
  }
297
- }, w = {
381
+ }, I = {
298
382
  /**
299
383
  * 判断对象是否为空
300
384
  * @param obj 对象
301
385
  * @returns 是否为空。true 为空;false 不为空
302
386
  */
303
- isEmptyObject: (t) => t ? Object.keys(t).length === 0 && t.constructor === Object : !0
304
- }, U = {
387
+ isEmptyObject(e) {
388
+ return e ? Object.keys(e).length === 0 && e.constructor === Object : !0;
389
+ }
390
+ }, T = {
305
391
  /**
306
392
  * 脱敏
307
393
  * @param phone 电话号码/手机号码
308
394
  * @returns 脱敏后的电话号码/手机号码
309
395
  */
310
- desensitize: (t) => t ? t.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2") || t.slice(0, 3) + "****" + t.slice(7) : ""
311
- }, M = {
396
+ desensitize(e) {
397
+ return e ? e.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2") || e.slice(0, 3) + "****" + e.slice(7) : "";
398
+ }
399
+ }, k = {
312
400
  /**
313
401
  * 生成随机颜色
314
402
  * @returns 随机颜色值
315
403
  */
316
- color: () => `#${Math.random().toString(16).slice(2, 8)}`,
404
+ color: function() {
405
+ return `#${Math.random().toString(16).slice(2, 8)}`;
406
+ },
317
407
  /**
318
408
  * 生成指定范围的随机整数
319
409
  * @param min 最小值
320
410
  * @param max 最大值
321
411
  * @returns 随机数
322
412
  */
323
- int(t, e) {
324
- return Math.floor(Math.random() * (e - t + 1)) + t;
413
+ int(e, t) {
414
+ return Math.floor(Math.random() * (t - e + 1)) + e;
325
415
  },
326
416
  /**
327
417
  * 生成唯一ID(时间戳+随机数)
@@ -330,65 +420,65 @@ const i = (t) => {
330
420
  uniqueId() {
331
421
  return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
332
422
  }
333
- }, _ = {
423
+ }, v = {
334
424
  /**
335
425
  * 通过key值获取 localStorage 中存储的某个值
336
426
  * @param key 获取的key
337
427
  * @returns 获取的值
338
428
  */
339
- getLocal(t) {
340
- return localStorage.getItem(t);
429
+ getLocal(e) {
430
+ return localStorage.getItem(e);
341
431
  },
342
432
  /**
343
433
  * 设置localStorage中的某个值
344
434
  * @param key 设置的key
345
435
  * @param value 设置的value
346
436
  */
347
- setLocal(t, e) {
348
- localStorage.setItem(t, e);
437
+ setLocal(e, t) {
438
+ localStorage.setItem(e, t);
349
439
  },
350
440
  /**
351
441
  * 删除localStorage中的某个值
352
442
  * @param key 删除的key
353
443
  */
354
- removeLocal(t) {
355
- localStorage.removeItem(t);
444
+ removeLocal(e) {
445
+ localStorage.removeItem(e);
356
446
  },
357
447
  /**
358
448
  * 通过key值获取 sessionStorage 中存储的某个值
359
449
  * @param key 获取的key
360
450
  * @returns 获取的值
361
451
  */
362
- getSession(t) {
363
- return sessionStorage.getItem(t);
452
+ getSession(e) {
453
+ return sessionStorage.getItem(e);
364
454
  },
365
455
  /**
366
456
  * 设置sessionStorage中的某个值
367
457
  * @param key 设置的key
368
458
  * @param value 设置的value
369
459
  */
370
- setSession(t, e) {
371
- sessionStorage.setItem(t, e);
460
+ setSession(e, t) {
461
+ sessionStorage.setItem(e, t);
372
462
  },
373
463
  /**
374
464
  * 删除sessionStorage中的某个值
375
465
  * @param key 删除的key
376
466
  */
377
- removeSession(t) {
378
- sessionStorage.removeItem(t);
467
+ removeSession(e) {
468
+ sessionStorage.removeItem(e);
379
469
  }
380
- }, j = {
470
+ }, R = {
381
471
  /**
382
472
  * 判断某元素是否在字符串中-比includes()方法更兼容,includes为ES6新增方法,IE不支持。小程序也不支持
383
473
  * @param str 字符串
384
474
  * @param element 查询元素
385
475
  * @returns 是否存在。true 存在;false 不存在
386
476
  */
387
- isExist(t, e) {
388
- if (!t || !e)
477
+ isExist(e, t) {
478
+ if (!e || !t)
389
479
  return !1;
390
- const r = t.split(",");
391
- return console.log("判断某元素是否在字符串中", r.indexOf(e) === -1), r.indexOf(e) !== -1;
480
+ const n = e.split(",");
481
+ return console.log("判断某元素是否在字符串中", n.indexOf(t) === -1), n.indexOf(t) !== -1;
392
482
  },
393
483
  /**
394
484
  * 判断某元素是否在字符串中-比isExist()方法更高效。
@@ -396,72 +486,82 @@ const i = (t) => {
396
486
  * @param element 查询元素
397
487
  * @returns 是否存在。true 存在;false 不存在
398
488
  */
399
- includes(t, e) {
400
- return !t || !e ? !1 : t.includes(e);
489
+ includes(e, t) {
490
+ return !e || !t ? !1 : e.includes(t);
401
491
  },
402
492
  /**
403
493
  * 判断字符串是否为 JSON
404
494
  * @param str 字符串
405
495
  * @returns
406
496
  */
407
- isJSON(t) {
497
+ isJSON(e) {
408
498
  try {
409
- return JSON.parse(t), !0;
499
+ return JSON.parse(e), !0;
410
500
  } catch {
411
501
  return !1;
412
502
  }
413
503
  }
414
- }, g = (t) => {
415
- const r = new RegExp("[?&]" + t + "=([^&#]*)", "i").exec(window.location.href);
416
- return r ? decodeURIComponent(r[1]) : null;
504
+ }, S = (e) => {
505
+ const n = new RegExp("[?&]" + e + "=([^&#]*)", "i").exec(window.location.href);
506
+ return n ? decodeURIComponent(n[1]) : null;
417
507
  };
418
- function d(t) {
419
- return new URLSearchParams(window.location.search).get(t);
508
+ function O(e) {
509
+ return new URLSearchParams(window.location.search).get(e);
420
510
  }
421
- const p = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
511
+ const U = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
422
512
  __proto__: null,
423
- getQueryInfoByName: g,
424
- getQueryParam: d
425
- }, Symbol.toStringTag, { value: "Module" })), E = {
426
- ...p,
513
+ getQueryInfoByName: S,
514
+ getQueryParam: O
515
+ }, Symbol.toStringTag, { value: "Module" })), N = {
516
+ ...U,
427
517
  /**
428
518
  * 获取当前域名
429
519
  * @returns 当前url链接的host信息
430
520
  */
431
521
  getHost() {
432
522
  return window.location.host;
523
+ },
524
+ /**
525
+ * 获取当前页面路径
526
+ * @returns 当前url链接的pathname信息
527
+ */
528
+ getPath() {
529
+ return window.location.pathname;
433
530
  }
434
- }, I = {
531
+ }, P = {
435
532
  /**
436
533
  * 处理瀑布流数据,使其适合瀑布流布局展示
437
534
  * @param list 瀑布流数据-数组
438
535
  * @param columnsNum 需要展示的列数
439
536
  * @returns 适合瀑布流布局的数组
440
537
  */
441
- toList: (t, e = 2) => {
442
- console.log(t, e);
443
- const r = {};
444
- for (let o = 0; o < e; o++)
445
- r[o] = [];
446
- t.forEach((o, s) => r[s % e].push(o));
447
- const n = [];
448
- for (const o in r)
449
- n.push(...r[o]);
450
- return n;
538
+ toList(e, t = 2) {
539
+ console.log(e, t);
540
+ const n = {};
541
+ for (let o = 0; o < t; o++)
542
+ n[o] = [];
543
+ e.forEach((o, i) => n[i % t].push(o));
544
+ const r = [];
545
+ for (const o in n)
546
+ r.push(...n[o]);
547
+ return r;
451
548
  }
452
549
  };
453
550
  export {
454
- h as arrayUtils,
455
- y as booleanUtils,
456
- m as cookieUtils,
457
- b as dateUtils,
458
- S as letterUtils,
459
- O as numberUtils,
460
- w as objectUtils,
461
- U as phoneUtils,
462
- M as randomUtils,
463
- _ as storageUtils,
464
- j as stringUtils,
465
- E as urlUtils,
466
- I as waterfallUtils
551
+ A as arrayUtils,
552
+ j as base64Utils,
553
+ E as booleanUtils,
554
+ _ as cookieUtils,
555
+ C as dateUtils,
556
+ M as downloadUtils,
557
+ x as elementUtils,
558
+ B as letterUtils,
559
+ L as numberUtils,
560
+ I as objectUtils,
561
+ T as phoneUtils,
562
+ k as randomUtils,
563
+ v as storageUtils,
564
+ R as stringUtils,
565
+ N as urlUtils,
566
+ P as waterfallUtils
467
567
  };
@@ -1 +1 @@
1
- (function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.yhkitUtils={}))})(this,function(o){"use strict";const l={...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:t=>{if(!t||!t.length)return{};const e={};return t.forEach(r=>{const n=Object.assign({label:r.label,text:r.label},r);e[r==null?void 0:r.value]=n}),e}},Symbol.toStringTag,{value:"Module"})),unique:t=>t?Array.from(new Set(t)):[],isExist(t,e){return!t||!e?!1:t.indexOf(e)!==-1},countOfAppear(t,e){let r=0;for(const n of t)n===e&&r++;return r},sort(t,e="asc"){return t?t.sort((r,n)=>e==="asc"?r>n?1:-1:r<n?1:-1):[]},shuffle(t){if(!t)return[];for(let e=t.length-1;e>0;e--){const r=Math.floor(Math.random()*(e+1));[t[e],t[r]]=[t[r],t[e]]}return t}},c={isEmptyString(t){return typeof t=="string"&&t.trim()===""},isNumber(t){return typeof t=="number"&&!isNaN(t)},isObject(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)},isEmptyObject(t){return t?Object.keys(t).length===0&&t.constructor===Object:!0},isBoolean(t){return typeof t=="boolean"},isArray(t){return Array.isArray(t)},isFunction(t){return typeof t=="function"},isPromise(t){return!!t&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function"},isElement(t){return t instanceof Element},isPhone(t){return/^1[3-9]\d{9}$/.test(t)},isEmail(t){return/^[\w.-]+@[\w.-]+\.\w+$/.test(t)},isJSON(t){try{return JSON.parse(t),!0}catch{return!1}},isImageLoaded(t){return t.complete&&t.naturalWidth!==0},isInViewport(t){const e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=window.innerHeight&&e.right<=window.innerWidth},isLeapYear(t){return t%4===0&&t%100!==0||t%400===0},isMobile(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}},a={getCookie(t){if(!t)return;const e=document.cookie.match(new RegExp("(^| )"+t+"=([^;]+)"));return e?decodeURIComponent(e[2]):null},setCookie(t,e,r=7){const n=new Date;n.setTime(n.getTime()+r*24*60*60*1e3),document.cookie=`${t}=${encodeURIComponent(e)};expires=${n.toUTCString()};path=/`},deleteCookie(t){this.setCookie(t,"",-1)}},f={getTimeString(t,e=!1){return e?new Date().toLocaleString(t,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(t,e){const r=new Date(t).getTime(),n=new Date(e).getTime();return r>n?Math.abs(Math.floor((r-n)/(24*3600*1e3))):Math.abs(Math.floor((n-r)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},d={sortFromA2Z:t=>t!=null&&t.length?t.sort((r,n)=>{const i=r.toUpperCase(),u=n.toUpperCase();return i<u?-1:i>u?1:0}):void 0},g={...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)}},y={isEmptyObject:t=>t?Object.keys(t).length===0&&t.constructor===Object:!0},m={desensitize:t=>t?t.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||t.slice(0,3)+"****"+t.slice(7):""},b={color:()=>`#${Math.random().toString(16).slice(2,8)}`,int(t,e){return Math.floor(Math.random()*(e-t+1))+t},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},h={getLocal(t){return localStorage.getItem(t)},setLocal(t,e){localStorage.setItem(t,e)},removeLocal(t){localStorage.removeItem(t)},getSession(t){return sessionStorage.getItem(t)},setSession(t,e){sessionStorage.setItem(t,e)},removeSession(t){sessionStorage.removeItem(t)}},p={isExist(t,e){if(!t||!e)return!1;const r=t.split(",");return console.log("判断某元素是否在字符串中",r.indexOf(e)===-1),r.indexOf(e)!==-1},includes(t,e){return!t||!e?!1:t.includes(e)},isJSON(t){try{return JSON.parse(t),!0}catch{return!1}}},S=t=>{const r=new RegExp("[?&]"+t+"=([^&#]*)","i").exec(window.location.href);return r?decodeURIComponent(r[1]):null};function U(t){return new URLSearchParams(window.location.search).get(t)}const O={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:S,getQueryParam:U},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host}},w={toList:(t,e=2)=>{console.log(t,e);const r={};for(let i=0;i<e;i++)r[i]=[];t.forEach((i,u)=>r[u%e].push(i));const n=[];for(const i in r)n.push(...r[i]);return n}};o.arrayUtils=l,o.booleanUtils=c,o.cookieUtils=a,o.dateUtils=f,o.letterUtils=d,o.numberUtils=g,o.objectUtils=y,o.phoneUtils=m,o.randomUtils=b,o.storageUtils=h,o.stringUtils=p,o.urlUtils=O,o.waterfallUtils=w,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(r,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(r=typeof globalThis<"u"?globalThis:r||self,g(r.yhkitUtils={}))})(this,function(r){"use strict";const h=Object.assign({unique(e){return e?Array.from(new Set(e)):[]},isExist(e,t){return!e||!t?!1:e.indexOf(t)!==-1},countOfAppear(e,t){let n=0;for(const o of e)o===t&&n++;return n},sort(e,t="asc"){return e?e.sort((n,o)=>t==="asc"?n>o?1:-1:n<o?1:-1):[]},shuffle(e){if(!e)return[];for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:e=>{if(!e||!e.length)return{};const t={};return e.forEach(n=>{const o=Object.assign({label:n.label,text:n.label},n);t[n==null?void 0:n.value]=o}),t}},Symbol.toStringTag,{value:"Module"}))}),p={toBlob(e,t="",n=512){const s=(e.split(",")[1]||e).replace(/-/g,"+").replace(/_/g,"/"),l="=".repeat((4-s.length%4)%4),y=s+l;try{const a=atob(y),d=[];for(let u=0;u<a.length;u+=n){const c=a.slice(u,u+n),f=new Array(c.length);for(let i=0;i<c.length;i++)f[i]=c.charCodeAt(i);const b=new Uint8Array(f);d.push(b)}return new Blob(d,{type:t})}catch(a){return console.error("Failed to convert base64 to blob:",a),null}},toFile(e,t="file.txt",n="text/plain"){const s=e.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),l="=".repeat((4-s.length%4)%4),y=s+l,a=atob(y),d=[];for(let c=0;c<a.length;c+=512){const f=a.slice(c,c+512),b=new Array(f.length);for(let i=0;i<f.length;i++)b[i]=f.charCodeAt(i);d.push(new Uint8Array(b))}const u=new Blob(d,{type:n});return new File([u],t,{type:n})}},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 t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=window.innerHeight&&t.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 t=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return t?decodeURIComponent(t[2]):null},setCookie(e,t,n=7){const o=new Date;o.setTime(o.getTime()+n*24*60*60*1e3),document.cookie=`${e}=${encodeURIComponent(t)};expires=${o.toUTCString()};path=/`},deleteCookie(e){this.setCookie(e,"",-1)}},w={getTimeString(e,t=!1){return t?new Date().toLocaleString(e,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(e,t){const n=new Date(e).getTime(),o=new Date(t).getTime();return n>o?Math.abs(Math.floor((n-o)/(24*3600*1e3))):Math.abs(Math.floor((o-n)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},S={saveAsBlob(e,t){const n=document.createElement("a"),o=window.URL.createObjectURL(e);n.href=o,n.download=t,document.body.appendChild(n),n.click(),URL.revokeObjectURL(o),document.body.removeChild(n)}},O={getOffsetTop(e){if(!e)throw new Error("Element is not provided");if(e instanceof SVGElement){const n=e.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop;return n.top+o}let t=0;for(;e;)t+=e.offsetTop,e=e.offsetParent;return t}},j={sortFromA2Z(e){return e!=null&&e.length?e.sort((n,o)=>{const s=n.toUpperCase(),l=o.toUpperCase();return s<l?-1:s>l?1:0}):void 0}},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)}},E={isEmptyObject(e){return e?Object.keys(e).length===0&&e.constructor===Object:!0}},M={desensitize(e){return e?e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||e.slice(0,3)+"****"+e.slice(7):""}},_={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(e,t){return Math.floor(Math.random()*(t-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,t){localStorage.setItem(e,t)},removeLocal(e){localStorage.removeItem(e)},getSession(e){return sessionStorage.getItem(e)},setSession(e,t){sessionStorage.setItem(e,t)},removeSession(e){sessionStorage.removeItem(e)}},T={isExist(e,t){if(!e||!t)return!1;const n=e.split(",");return console.log("判断某元素是否在字符串中",n.indexOf(t)===-1),n.indexOf(t)!==-1},includes(e,t){return!e||!t?!1:e.includes(t)},isJSON(e){try{return JSON.parse(e),!0}catch{return!1}}},L=e=>{const n=new RegExp("[?&]"+e+"=([^&#]*)","i").exec(window.location.href);return n?decodeURIComponent(n[1]):null};function B(e){return new URLSearchParams(window.location.search).get(e)}const k={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:L,getQueryParam:B},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},I={toList(e,t=2){console.log(e,t);const n={};for(let s=0;s<t;s++)n[s]=[];e.forEach((s,l)=>n[l%t].push(s));const o=[];for(const s in n)o.push(...n[s]);return o}};r.arrayUtils=h,r.base64Utils=p,r.booleanUtils=m,r.cookieUtils=U,r.dateUtils=w,r.downloadUtils=S,r.elementUtils=O,r.letterUtils=j,r.numberUtils=A,r.objectUtils=E,r.phoneUtils=M,r.randomUtils=_,r.storageUtils=C,r.stringUtils=T,r.urlUtils=k,r.waterfallUtils=I,Object.defineProperty(r,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.3.0",
4
+ "version": "1.4.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -35,4 +35,4 @@
35
35
  "access": "public",
36
36
  "registry": "https://registry.npmjs.org/"
37
37
  }
38
- }
38
+ }
@@ -7,7 +7,7 @@ export declare const arrayUtils: {
7
7
  * @param arr 数组
8
8
  * @returns 去重后的数组
9
9
  */
10
- unique: <T>(arr: T[]) => T[];
10
+ unique<T>(arr: T[]): T[];
11
11
  /**
12
12
  * 判断某元素是否在数组中
13
13
  * @param arr 数组
@@ -41,5 +41,6 @@ export declare const arrayUtils: {
41
41
  * @returns
42
42
  */
43
43
  shuffle<T>(arr: T[]): T[];
44
- toEnumObj: (arr: import("../../../typings/src").IOptionItem[]) => import("../../../typings/src").TValueEnum;
44
+ } & {
45
+ toEnumObj: (arr: import("@yh-kit/types").IOptionItem[]) => import("@yh-kit/types").TValueEnum;
45
46
  };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Base64 相关操作工具函数
3
+ */
4
+ export declare const base64Utils: {
5
+ /**
6
+ * 将Base64编码的字符串转换为Blob对象。
7
+ * Blob对象用于表示二进制大型对象,可以在浏览器环境中处理大文件或二进制数据。
8
+ *
9
+ * @param base64 Base64编码的字符串。
10
+ * @param contentType 可选参数,表示生成的Blob对象的MIME类型,默认为空字符串。
11
+ * @param sliceSize 可选参数,表示分片大小,默认为512字节。用于控制每次处理的Base64字符串长度,以优化大文件的处理。
12
+ * @returns 返回转换后的Blob对象,如果转换失败,则返回null。
13
+ */
14
+ toBlob(base64: string, contentType?: string, sliceSize?: number): Blob | null;
15
+ /**
16
+ * 将Base64编码的字符串转换为File对象。
17
+ * 这个函数接受一个Base64编码的字符串,一个可选的文件名和一个可选的MIME类型,
18
+ * 并返回一个代表原始数据的File对象。
19
+ *
20
+ * @param base64 Base64编码的字符串。
21
+ * @param fileName 文件名,默认为"file.txt"。
22
+ * @param mimeType MIME类型,默认为"text/plain"。
23
+ * @returns 返回一个File对象,包含解码后的数据。
24
+ */
25
+ toFile(base64: string, fileName?: string, mimeType?: string): File;
26
+ };
@@ -1,3 +1,6 @@
1
+ /**
2
+ * 布尔值相关工具函数
3
+ */
1
4
  export declare const booleanUtils: {
2
5
  /**
3
6
  * 检查是否为空字符串
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 下载相关工具函数
3
+ */
4
+ export declare const downloadUtils: {
5
+ /**
6
+ * 将blob对象转化成文件并导出到本地
7
+ * @param blob blob对象
8
+ * @param filename 文件名
9
+ */
10
+ saveAsBlob(blob: Blob | MediaSource, filename: string): void;
11
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 元素相关工具函数
3
+ */
4
+ export declare const elementUtils: {
5
+ /**
6
+ * 获取元素相对于文档顶部的偏移量(距离)
7
+ * 处理了SVG元素的特殊情况。
8
+ * @param el 元素
9
+ * @returns 偏移量(距离值)
10
+ */
11
+ getOffsetTop(el: HTMLElement): number;
12
+ };
@@ -1,7 +1,10 @@
1
1
  export * from "./array";
2
+ export * from "./base64";
2
3
  export * from "./boolean";
3
4
  export * from "./cookie";
4
5
  export * from "./date";
6
+ export * from "./download";
7
+ export * from "./element";
5
8
  export * from "./letter";
6
9
  export * from "./number";
7
10
  export * from "./object";
@@ -7,5 +7,5 @@ export declare const letterUtils: {
7
7
  * @param arr 字母数组
8
8
  * @returns
9
9
  */
10
- sortFromA2Z: (arr: string[]) => string[] | undefined;
10
+ sortFromA2Z(arr: string[]): string[] | undefined;
11
11
  };
@@ -7,5 +7,5 @@ export declare const objectUtils: {
7
7
  * @param obj 对象
8
8
  * @returns 是否为空。true 为空;false 不为空
9
9
  */
10
- isEmptyObject: (obj: object) => boolean;
10
+ isEmptyObject(obj: object): boolean;
11
11
  };
@@ -7,5 +7,5 @@ export declare const phoneUtils: {
7
7
  * @param phone 电话号码/手机号码
8
8
  * @returns 脱敏后的电话号码/手机号码
9
9
  */
10
- desensitize: (phone: string) => string;
10
+ desensitize(phone: string): string;
11
11
  };
@@ -7,6 +7,11 @@ export declare const urlUtils: {
7
7
  * @returns 当前url链接的host信息
8
8
  */
9
9
  getHost(): string;
10
+ /**
11
+ * 获取当前页面路径
12
+ * @returns 当前url链接的pathname信息
13
+ */
14
+ getPath(): string;
10
15
  getQueryParam(name: string): string | null;
11
16
  getQueryInfoByName: (name: string) => string | null;
12
17
  };
@@ -8,5 +8,5 @@ export declare const waterfallUtils: {
8
8
  * @param columnsNum 需要展示的列数
9
9
  * @returns 适合瀑布流布局的数组
10
10
  */
11
- toList: <T>(list: T[], columnsNum?: number) => any[];
11
+ toList<T>(list: T[], columnsNum?: number): any[];
12
12
  };