mazey 3.10.1 → 3.11.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/lib/index.d.ts CHANGED
@@ -1,1395 +1,1403 @@
1
- /**
2
- * @author: Mazey Chu
3
- */
4
- import { BrowserInfo, DefineListeners, ThrottleFunc, DebounceFunc, IsNumberOptions, AnyFunction, ZResResponse, ZResIsValidResOptions, RepeatUntilOptions, LoadScriptReturns, SimpleType, UnknownFnParams, UnknownFnReturn, UnknownObject, UnknownFn } from './typing';
5
- /**
6
- * EN: Computes the longest common substring of two strings.
7
- *
8
- * ZH: 计算两个字符串的最长公共子串
9
- *
10
- * Usage:
11
- *
12
- * ```
13
- * longestComSubstring('fish', 'finish');
14
- * ```
15
- *
16
- * Output:
17
- *
18
- * ```
19
- * 3
20
- * ```
21
- *
22
- * @param {string} aStr String
23
- * @param {string} bStr String
24
- * @returns {number} Length
25
- * @category Calculate and Formula
26
- */
27
- export declare function longestComSubstring(aStr: string, bStr: string): number;
28
- /**
29
- * Alias of `longestComSubstring`
30
- *
31
- * @hidden
32
- */
33
- export declare function calLongestCommonSubstring(aStr: string, bStr: string): number;
34
- /**
35
- * EN: Computes the longest common subsequence of two strings.
36
- *
37
- * ZH: 计算两个字符串的最长公共子序列
38
- *
39
- * Usage:
40
- *
41
- * ```
42
- * longestComSubsequence('fish', 'finish');
43
- * ```
44
- *
45
- * Output:
46
- *
47
- * ```
48
- * 4
49
- * ```
50
- *
51
- * @param {string} aStr 字符串
52
- * @param {string} bStr 字符串
53
- * @returns {number} 长度
54
- * @category Calculate and Formula
55
- */
56
- export declare function longestComSubsequence(aStr: string, bStr: string): number;
57
- /**
58
- * Alias of `longestComSubsequence`
59
- *
60
- * @hidden
61
- */
62
- export declare function calLongestCommonSubsequence(aStr: string, bStr: string): number;
63
- /**
64
- * Get the query param's value of the current Web URL(`location.search`).
65
- *
66
- * ```
67
- * // http://example.com/?t1=1&t2=2&t3=3&t4=4#2333
68
- * // ?t1=1&t2=2&t3=3&t4=4
69
- * getQueryParam('t3'); // 3
70
- * getQueryParam('t4'); // 4
71
- * ```
72
- *
73
- * @param {string} param Query param.
74
- * @returns {string} value
75
- * @category URL
76
- */
77
- export declare function getQueryParam(param: string): string;
78
- /**
79
- * Returns the value of the specified query parameter in the input URL.
80
- *
81
- * @example
82
- * ```
83
- * getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3'); // Returns '3'
84
- * getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4'); // Returns '4'
85
- * ```
86
- *
87
- * @param {string} url The URL string.
88
- * @param {string} param The query parameter to retrieve the value for.
89
- * @returns {string|string[]} The value of the specified query parameter, or an empty string if the parameter is not found.
90
- * @category URL
91
- */
92
- export declare function getUrlParam(url: string, param: string): string | string[];
93
- /**
94
- * Update the query param's value of the input URL.
95
- *
96
- * Usage:
97
- *
98
- * ```
99
- * updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3', 'three');
100
- * updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four');
101
- * ```
102
- *
103
- * Output:
104
- *
105
- * ```
106
- * http://example.com/?t1=1&t2=2&t3=three&t4=4
107
- * http://example.com/?t1=1&t2=2&t3=3&t4=four
108
- * ```
109
- *
110
- * @param {string} url URL string.
111
- * @param {string} param Query param.
112
- * @param {string} value Param's value.
113
- * @returns {string} URL.
114
- * @category URL
115
- */
116
- export declare function updateQueryParam(url: string, param: string, value: string): string;
117
- /**
118
- * Get the hash query param's value of the current Web URL(`location.hash`).
119
- *
120
- * Usage:
121
- *
122
- * ```
123
- * // http://example.com/?#2333?t1=1&t2=2&t3=3&t4=4
124
- * // #2333?t1=1&t2=2&t3=3&t4=4
125
- * getHashQueryParam('t3');
126
- * getHashQueryParam('t4');
127
- * ```
128
- *
129
- * Output:
130
- *
131
- * ```
132
- * 3
133
- * 4
134
- * ```
135
- *
136
- * @param {string} param Query param.
137
- * @returns {string} value
138
- * @category URL
139
- */
140
- export declare function getHashQueryParam(param: string): string;
141
- /**
142
- * Get the domain of URL, and other params.
143
- *
144
- * Usage:
145
- *
146
- * ```
147
- * getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4');
148
- * getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']);
149
- * getDomain('http://example.com:7890/test/thanks', ['hostname']);
150
- * getDomain('http://example.com:7890/test/thanks', ['host']); // With Port
151
- * getDomain('http://example.com:7890/test/thanks', ['origin']);
152
- * getDomain('http://example.com:7890/test/thanks?id=1', ['origin', 'pathname', 'search']);
153
- * ```
154
- *
155
- * Output:
156
- *
157
- * ```
158
- * example.com
159
- * example.com/test/thanks
160
- * example.com
161
- * example.com:7890
162
- * http://example.com:7890
163
- * http://example.com:7890/test/thanks?id=1
164
- * ```
165
- *
166
- * @param {string} url
167
- * @param {array} rules Object.keys(location), ['href', 'origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
168
- * @category URL
169
- */
170
- export declare function getDomain(url: string, rules?: string[]): string;
171
- /**
172
- * Transfer CamelCase to KebabCase.
173
- *
174
- * ```
175
- * convertCamelToKebab('ABC'); // a-b-c
176
- * convertCamelToKebab('aBC'); // a-b-c
177
- * ```
178
- *
179
- * @param {string} camelCase 'aBC' or 'ABC'
180
- * @returns {string} 'a-b-c'
181
- * @category Util
182
- */
183
- export declare function convertCamelToKebab(camelCase: string): string;
184
- /**
185
- * Alias of `convertCamelToKebab`
186
- *
187
- * @hidden
188
- */
189
- export declare function camelCaseToKebabCase(camelCase: string): string;
190
- /**
191
- * Transfer CamelCase to Underscore.
192
- *
193
- * ```
194
- * convertCamelToUnder('ABC'); // a_b_c
195
- * convertCamelToUnder('aBC'); // a_b_c
196
- * ```
197
- *
198
- * @param {string} camelCase 'aBC' or 'ABC'
199
- * @returns {string} 'a_b_c'
200
- * @category Util
201
- */
202
- export declare function convertCamelToUnder(camelCase: string): string;
203
- /**
204
- * Alias of `convertCamelToUnder`
205
- *
206
- * @hidden
207
- */
208
- export declare function camelCase2Underscore(camelCase: string): string;
209
- /**
210
- * Remove leading and trailing whitespace or specified characters from string.
211
- *
212
- * Note: This method is used to replace the native `String.prototype.trim()`. But it is not necessary to use it in modern browsers.
213
- *
214
- * ```
215
- * mTrim(' 1 2 3 '); // '1 2 3'
216
- * mTrim('abc '); // 'abc'
217
- * ```
218
- *
219
- * @param {string} str The string to trim.
220
- * @returns {string} Trimmed string.
221
- * @category Util
222
- * @hidden
223
- */
224
- export declare function mTrim(str: string): string;
225
- /**
226
- * Make a new line of HTML.
227
- *
228
- * ```
229
- * newLine('a\nb\nc'); // 'a<br />b<br />c'
230
- * newLine('a\n\nbc'); // 'a<br /><br />bc'
231
- * ```
232
- *
233
- * @param {string} str The string to make a new line.
234
- * @returns {string} A newline with `br`.
235
- * @category DOM
236
- */
237
- export declare function newLine(str: string): string;
238
- /**
239
- * Copy/Clone Object deeply.
240
- *
241
- * Usage:
242
- *
243
- * ```
244
- * deepCopy(['a', 'b', 'c']);
245
- * deepCopy('abc');
246
- * ```
247
- *
248
- * Output:
249
- *
250
- * ```
251
- * ['a', 'b', 'c']
252
- * 'abc'
253
- * ```
254
- *
255
- * @param {object} obj The value to clone.
256
- * @returns {object} Returns the deep cloned value.
257
- * @category Util
258
- */
259
- export declare function deepCopy<T>(obj: T): T;
260
- /**
261
- * Alias of `deepCopy`
262
- *
263
- * @hidden
264
- */
265
- export declare function deepCopyObject<T>(obj: T): T;
266
- /**
267
- * Check whether it is a valid JSON string.
268
- *
269
- * Usage:
270
- *
271
- * ```
272
- * isJSONString(`['a', 'b', 'c']`);
273
- * isJSONString(`["a", "b", "c"]`);
274
- * ```
275
- *
276
- * Output:
277
- *
278
- * ```
279
- * false
280
- * true
281
- * ```
282
- *
283
- * @param {string} str The string to check.
284
- * @returns {boolean} Return the result of checking.
285
- * @category Util
286
- */
287
- export declare function isJSONString(str: string): boolean;
288
- /**
289
- * Alias of `isJSONString`
290
- *
291
- * @hidden
292
- */
293
- export declare function isJsonString(str: string): boolean;
294
- /**
295
- * Produce a random string of number, `genRndNumString(7)` => '7658495'.
296
- *
297
- * ```
298
- * genRndNumString(4); // '9730'
299
- * genRndNumString(7); // '2262490'
300
- * ```
301
- *
302
- * @param {number} n Length
303
- * @returns {string} Return the random string.
304
- * @category Util
305
- */
306
- export declare function genRndNumString(n?: number): string;
307
- /**
308
- * Alias of `genRndNumString`
309
- *
310
- * @hidden
311
- */
312
- export declare function generateRndNum(n?: number): string;
313
- /**
314
- * 根据时间生成唯一标志的数字 genUniqueNumString() => 1538324722364123
315
- *
316
- * @param {number} n 随机数的长度
317
- * @category Util
318
- */
319
- export declare function genUniqueNumString(n?: number): string;
320
- /**
321
- * Alias of `genUniqueNumString`
322
- *
323
- * @hidden
324
- */
325
- export declare function generateUniqueNum(n?: number): string;
326
- /**
327
- * 浮点数转为百分比 0.2 => 20%
328
- *
329
- * @param {number} num 浮点数
330
- * @param {number} fixSize 保留几位浮点数
331
- * @category Util
332
- */
333
- export declare function floatToPercent(num: number, fixSize?: number): string;
334
- /**
335
- * 浮点数保留指定位
336
- *
337
- * @category Util
338
- */
339
- export declare function floatFixed(num: string, size?: number): string;
340
- /**
341
- * 阻止冒泡
342
- *
343
- * @category Event
344
- */
345
- export declare function cancelBubble(e: Event): void;
346
- /**
347
- * Modify `class`.
348
- *
349
- * ```
350
- * const dom = document.querySelector('#box');
351
- *
352
- * // Determine `class`
353
- * hasClass(dom, 'test');
354
- * // Add `class`
355
- * addClass(dom, 'test');
356
- * // Remove `class`
357
- * removeClass(dom, 'test');
358
- * ```
359
- *
360
- * @category DOM
361
- */
362
- export declare function hasClass(obj: HTMLElement, cls: string): boolean;
363
- /**
364
- * Modify `class`.
365
- *
366
- * ```
367
- * const dom = document.querySelector('#box');
368
- *
369
- * // Determine `class`
370
- * hasClass(dom, 'test');
371
- * // Add `class`
372
- * addClass(dom, 'test');
373
- * // Remove `class`
374
- * removeClass(dom, 'test');
375
- * ```
376
- *
377
- * @category DOM
378
- */
379
- export declare function addClass(obj: HTMLElement, cls: string): void;
380
- /**
381
- * Modify `class`.
382
- *
383
- * ```
384
- * const dom = document.querySelector('#box');
385
- *
386
- * // Determine `class`
387
- * hasClass(dom, 'test');
388
- * // Add `class`
389
- * addClass(dom, 'test');
390
- * // Remove `class`
391
- * removeClass(dom, 'test');
392
- * ```
393
- *
394
- * @category DOM
395
- */
396
- export declare function removeClass(obj: HTMLElement, cls: string): void;
397
- /**
398
- * EN: Throttle
399
- *
400
- * ZH: 节流
401
- *
402
- * ```
403
- * const foo = throttle(() => {
404
- * console.log('The function will be invoked at most once per every wait 1000 milliseconds.');
405
- * }, 1000, { leading: true });
406
- * ```
407
- *
408
- * Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
409
- *
410
- * @category Util
411
- */
412
- export declare function throttle<T extends (...args: UnknownFnParams) => UnknownFnReturn>(func: T, wait: number, options?: {
413
- leading?: boolean;
414
- trailing?: boolean;
415
- }): ThrottleFunc<T>;
416
- /**
417
- * EN: Debounce
418
- *
419
- * ZH: 去抖
420
- *
421
- * ```
422
- * const foo = debounce(() => {
423
- * console.log('The debounced function will only be invoked in 1000 milliseconds, the other invoking will disappear during the wait time.');
424
- * }, 1000, true);
425
- * ```
426
- *
427
- * @category Util
428
- */
429
- export declare function debounce<T extends (...args: UnknownFnParams) => UnknownFnReturn>(func: T, wait: number, immediate?: boolean): DebounceFunc<T>;
430
- /**
431
- * 获取间隔时间
432
- *
433
- * @example
434
- * ```js
435
- * console.log('getFriendlyInterval:', getFriendlyInterval(new Date('2020-03-28 00:09:27'), new Date('2023-04-18 10:54:00'), { type: 'd' })); // 1116
436
- * console.log('getFriendlyInterval:', getFriendlyInterval(1585325367000, 1681786440000, { type: 'text' })); // 1116 天 10 时 44 分 33 秒
437
- * console.log('getFriendlyInterval:', getFriendlyInterval('2020-03-28 00:09:27', '2023-04-18 10:54:00', { type: 'text' })); // 1116 天 10 时 44 分 33 秒
438
- * ```
439
- *
440
- * @param {number/Date} start 开始时间戳 1585325367122
441
- * @param {number/Date} end 结束时间戳 1585325367122
442
- * @param {string} options.type 返回类型 d: 2(天) text: 2 天 4 时...
443
- * @returns {string/number} 取决于 type
444
- * @category Util
445
- */
446
- export declare function getFriendlyInterval(start?: number | string | Date, end?: number | string | Date, options?: {
447
- type?: string;
448
- }): number | string;
449
- /**
450
- * EN: Check whether it is a right number.
451
- *
452
- * ZH: 判断是否有效数字
453
- *
454
- * ```
455
- * isNumber(123); // true
456
- * isNumber('123'); // false
457
- * // Default: NaN, Infinity is not Number
458
- * isNumber(Infinity); // false
459
- * isNumber(Infinity, { isInfinityAsNumber: true }); // true
460
- * isNumber(NaN); // false
461
- * isNumber(NaN, { isNaNAsNumber: true, isInfinityAsNumber: true }); // true
462
- * ```
463
- *
464
- * @param {*} num 被判断的值
465
- * @param {boolean} options.isNaNAsNumber 是否 NaN 算数字(默认不算)
466
- * @param {boolean} options.isInfinityAsNumber 是否 无限 算数字(默认不算)
467
- * @returns {boolean} true 是数字
468
- * @category Util
469
- */
470
- export declare function isNumber(num: unknown, options?: IsNumberOptions): boolean;
471
- /**
472
- * 执行有效函数
473
- *
474
- * @param {function} fn 等待被执行的未知是否有效的函数
475
- * @category Util
476
- */
477
- export declare function doFn(fn: AnyFunction, ...params: Parameters<AnyFunction>): ReturnType<AnyFunction> | null;
478
- /**
479
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
480
- *
481
- * ZH: 存储/获取数据到 sessionStorage/localStorage
482
- *
483
- * ```
484
- * setSessionStorage('test', '123');
485
- * getSessionStorage('test'); // 123
486
- * setLocalStorage('test', '123');
487
- * getLocalStorage('test'); // 123
488
- *
489
- * // or package in usage
490
- * const projectName = 'mazey';
491
- * function mSetLocalStorage (key, value) {
492
- * return setLocalStorage(`${projectName}_${key}`, value);
493
- * }
494
- *
495
- * function mGetLocalStorage (key) {
496
- * return getLocalStorage(`${projectName}_${key}`);
497
- * }
498
- * ```
499
- *
500
- * @param {string} key 键
501
- * @returns {void} 返回值
502
- * @category Cache Data
503
- */
504
- export declare function setSessionStorage<T>(key: string, value?: T | null): void;
505
- /**
506
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
507
- *
508
- * ZH: 存储/获取数据到 sessionStorage/localStorage
509
- *
510
- * ```
511
- * setSessionStorage('test', '123');
512
- * getSessionStorage('test'); // 123
513
- * setLocalStorage('test', '123');
514
- * getLocalStorage('test'); // 123
515
- *
516
- * // or package in usage
517
- * const projectName = 'mazey';
518
- * function mSetLocalStorage (key, value) {
519
- * return setLocalStorage(`${projectName}_${key}`, value);
520
- * }
521
- *
522
- * function mGetLocalStorage (key) {
523
- * return getLocalStorage(`${projectName}_${key}`);
524
- * }
525
- * ```
526
- *
527
- * @param {string} key 键
528
- * @returns {any} 返回值
529
- * @category Cache Data
530
- */
531
- export declare function getSessionStorage<T>(key: string): T | null;
532
- /**
533
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
534
- *
535
- * ZH: 存储/获取数据到 sessionStorage/localStorage
536
- *
537
- * ```
538
- * setSessionStorage('test', '123');
539
- * getSessionStorage('test'); // 123
540
- * setLocalStorage('test', '123');
541
- * getLocalStorage('test'); // 123
542
- *
543
- * // or package in usage
544
- * const projectName = 'mazey';
545
- * function mSetLocalStorage (key, value) {
546
- * return setLocalStorage(`${projectName}_${key}`, value);
547
- * }
548
- *
549
- * function mGetLocalStorage (key) {
550
- * return getLocalStorage(`${projectName}_${key}`);
551
- * }
552
- * ```
553
- *
554
- * @param {string} key 键
555
- * @returns {void} 返回值
556
- * @category Cache Data
557
- */
558
- export declare function setLocalStorage<T>(key: string, value?: T | null): void;
559
- /**
560
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
561
- *
562
- * ZH: 存储/获取数据到 sessionStorage/localStorage
563
- *
564
- * ```
565
- * setSessionStorage('test', '123');
566
- * getSessionStorage('test'); // 123
567
- * setLocalStorage('test', '123');
568
- * getLocalStorage('test'); // 123
569
- *
570
- * // or package in usage
571
- * const projectName = 'mazey';
572
- * function mSetLocalStorage (key, value) {
573
- * return setLocalStorage(`${projectName}_${key}`, value);
574
- * }
575
- *
576
- * function mGetLocalStorage (key) {
577
- * return getLocalStorage(`${projectName}_${key}`);
578
- * }
579
- * ```
580
- *
581
- * @param {string} key 键
582
- * @returns {any} 返回值
583
- * @category Cache Data
584
- */
585
- export declare function getLocalStorage<T>(key: string): T | null;
586
- /**
587
- * EN: Load a CSS file from the server.
588
- *
589
- * ZH: 动态加载 CSS 文件
590
- *
591
- * ```
592
- * loadCSS(
593
- * 'http://example.com/path/example.css',
594
- * {
595
- * id: 'iamid', // Optional, link ID, default none
596
- * }
597
- * )
598
- * .then(
599
- * res => {
600
- * console.log(`Load CSS Success: ${res}`);
601
- * }
602
- * )
603
- * .catch(
604
- * err => {
605
- * console.error(`Load CSS Fail: ${err.message}`)
606
- * }
607
- * );
608
- * ```
609
- *
610
- * @param {string} url -- css资源路径
611
- * @param {string} options.id -- link标签id
612
- * @returns {Promise<string>} true -- 加载成功
613
- * @category Load Resource
614
- */
615
- export declare function loadCSS(url: string, options?: {
616
- id?: string;
617
- }): Promise<unknown>;
618
- /**
619
- * EN: Load a JavaScript file from the server and execute it.
620
- *
621
- * ZH: 动态加载 JavaScript 文件
622
- *
623
- * ```
624
- * loadScript(
625
- * 'http://example.com/static/js/plugin-2.1.1.min.js',
626
- * {
627
- * id: 'iamid', // (Optional) script ID, default none
628
- * timeout: 5000, // (Optional) timeout, default `5000`
629
- * isDefer: false, // (Optional) defer, default `false`
630
- * }
631
- * )
632
- * .then(
633
- * res => {
634
- * console.log(`Load JavaScript script: ${res}`);
635
- * }
636
- * )
637
- * .catch(
638
- * err => {
639
- * console.error(`Load JavaScript script: ${err.message}`)
640
- * }
641
- * );
642
- * ```
643
- *
644
- * @param {string} url -- JavaScript 资源路径
645
- * @param {string} options.id -- DOM ID
646
- * @param {function} options.callback -- 加载后回调函数
647
- * @param {number} options.timeout -- 超时时长
648
- * @param {boolean} options.isDefer -- 是否添加 defer 标签
649
- * @returns {Promise<string>} -- true 成功
650
- * @category Load Resource
651
- */
652
- export declare function loadScript(url: string, options?: {
653
- id?: string;
654
- callback?: (...params: UnknownFnParams) => UnknownFnReturn;
655
- timeout?: number;
656
- isDefer?: boolean;
657
- }): LoadScriptReturns;
658
- /**
659
- * 获取时间戳
660
- *
661
- * @category Util
662
- */
663
- export declare function mNow(): number;
664
- /**
665
- * EN: Handle Cookie.
666
- *
667
- * ZH: 设置/获取 Cookie
668
- *
669
- * ```
670
- * setCookie('test', '123', 30, 'example.com'); // key value day domain
671
- * getCookie('test'); // 123
672
- * ```
673
- *
674
- * @category Cache Data
675
- */
676
- export declare function setCookie(name: string, value: string, days?: number, domain?: string): void;
677
- /**
678
- * EN: Handle Cookie.
679
- *
680
- * ZH: 设置/获取 Cookie
681
- *
682
- * ```
683
- * setCookie('test', '123', 30, 'example.com'); // key value day domain
684
- * getCookie('test'); // 123
685
- * ```
686
- *
687
- * @category Cache Data
688
- */
689
- export declare function getCookie(name: string): string;
690
- /**
691
- * Delete a cookie by name.
692
- *
693
- * @param name - The name of the cookie to delete.
694
- * @returns `true` if the cookie was deleted successfully, `false` otherwise.
695
- * @category Cache Data
696
- */
697
- export declare function delCookie(name: string): boolean;
698
- /**
699
- * @hidden
700
- */
701
- interface WebPerformance {
702
- [key: string]: string | number;
703
- }
704
- /**
705
- * Gets the first contentful paint (FCP) time of a web page using the Performance API.
706
- * The FCP time is the time it takes for the first piece of content to be painted on the screen.
707
- *
708
- * @returns A promise that resolves with the FCP time in milliseconds, or 0 if the 'paint' entry type is not supported.
709
- * @category Web Performance
710
- */
711
- export declare function getFCP(): Promise<number>;
712
- /**
713
- * Gets the first paint (FP) time of a web page using the Performance API.
714
- * The FP time is the time it takes for the first pixel to be painted on the screen.
715
- *
716
- * @returns A promise that resolves with the FP time in milliseconds, or 0 if the 'paint' entry type is not supported.
717
- * @category Web Performance
718
- */
719
- export declare function getFP(): Promise<number>;
720
- /**
721
- * Gets the largest contentful paint (LCP) time of a web page using the Performance API.
722
- * The LCP time is the time it takes for the largest piece of content to be painted on the screen.
723
- *
724
- * @returns A promise that resolves with the LCP time in milliseconds, or 0 if the 'largest-contentful-paint' entry type is not supported.
725
- * @category Web Performance
726
- */
727
- export declare function getLCP(): Promise<number>;
728
- /**
729
- * Gets the first input delay (FID) of a web page using the Performance API.
730
- * The FID is the time it takes for the first user input to be processed by the browser.
731
- *
732
- * @returns A promise that resolves with the FID in milliseconds, or 0 if the 'first-input' entry type is not supported.
733
- * @category Web Performance
734
- */
735
- export declare function getFID(): Promise<number>;
736
- /**
737
- * Gets the Cumulative Layout Shift (CLS) score of a web page using the Performance API.
738
- * The CLS score is a measure of how much the page layout shifts during loading.
739
- *
740
- * @returns A promise that resolves with the CLS score, or 0 if the 'layout-shift' entry type is not supported.
741
- * @category Web Performance
742
- */
743
- export declare function getCLS(): Promise<number>;
744
- /**
745
- * Gets the time to first byte (TTFB) of a web page using the Performance API.
746
- * The TTFB is the time it takes for the first byte of the response to be received by the browser.
747
- *
748
- * @returns The TTFB in milliseconds, or 0 if the navigation timing information is not available.
749
- * @category Web Performance
750
- */
751
- export declare function getTTFB(): Promise<number>;
752
- /**
753
- * EN: Get page load time(`PerformanceNavigationTiming`).
754
- *
755
- * ZH: 获取页面加载相关的各项数据
756
- *
757
- * @remarks
758
- * This function uses the [`PerformanceNavigationTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming) API to get page load time data.
759
- * The `PerformanceNavigationTiming` API provides more accurate and detailed information about page load time than the deprecated [`PerformanceTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming) API.
760
- * If you are using an older browser that does not support `PerformanceNavigationTiming`, you can still use the `PerformanceTiming` API by using the previous version of this library ([`v3.9.7`](https://www.npmjs.com/package/mazey/v/3.9.7)).
761
- *
762
- * Usage:
763
- *
764
- * ```
765
- * // `camelCase:false` (Default) Return underline(`a_b`) data.
766
- * // `camelCase:true` Return hump(`aB`) data.
767
- * getPerformance()
768
- * .then(res => {
769
- * console.log(JSON.stringify(res));
770
- * })
771
- * .catch(console.error);
772
- * ```
773
- *
774
- * Output:
775
- *
776
- * ```
777
- * {"source":"PerformanceNavigationTiming","os":"others","os_version":"","device_type":"pc","network":"4g","screen_direction":"","unload_time":0,"redirect_time":0,"dns_time":0,"tcp_time":0,"ssl_time":0,"response_time":2,"download_time":2,"first_paint_time":288,"first_contentful_paint_time":288,"dom_ready_time":0,"onload_time":0,"white_time":0,"render_time":0,"decoded_body_size":718,"encoded_body_size":718}
778
- * ```
779
- *
780
- * Results:
781
- *
782
- * | Attribute | Description | Type | Values |
783
- * | :------------ | :------------ | :------------ | :------------ |
784
- * | dns_time | DNS Lookup | number | domainLookupEnd - domainLookupStart |
785
- * | tcp_time | Connection Negotiation | number | connectEnd - connectStart |
786
- * | response_time | Requests and Responses | number | responseStart - requestStart |
787
- * | white_time | White Screen | number | responseStart - navigationStart |
788
- * | dom_ready_time | Dom Ready | number | domContentLoadedEventStart - navigationStart |
789
- * | onload_time | Onload | number | loadEventStart - navigationStart |
790
- * | render_time | EventEnd | number | loadEventEnd -navigationStart |
791
- * | unload_time | Unload | number | (Optional) unloadEventEnd - unloadEventStart |
792
- * | redirect_time | Redirect | number | (Optional) redirectEnd - redirectStart |
793
- * | ssl_time | SSL | number | (Optional) connectEnd - secureConnectionStart |
794
- * | download_time | Download | number | (Optional) responseEnd - responseStart |
795
- *
796
- * @param {boolean} camelCase -- false(默认) 以下划线形式返回数据 true 以驼峰形式返回数据
797
- * @returns {Promise<object>} 加载数据
798
- * @category Web Performance
799
- */
800
- export declare function getPerformance(camelCase?: boolean): Promise<WebPerformance | Error>;
801
- /**
802
- * EN: Hit probability (1% ~ 100%).
803
- *
804
- * ZH: 百分位概率
805
- *
806
- * Usage:
807
- *
808
- * ```
809
- * inRate(0.5); // 0.01 ~ 1 true/false
810
- * ```
811
- *
812
- * Output:
813
- *
814
- * ```
815
- * true
816
- * ```
817
- *
818
- * Example: Test the precision.
819
- *
820
- * ```
821
- * // Test
822
- * let trueCount = 0;
823
- * let falseCount = 0;
824
- * new Array(1000000).fill(0).forEach(() => {
825
- * if (inRate(0.5)) {
826
- * trueCount++;
827
- * } else {
828
- * falseCount++;
829
- * }
830
- * });
831
- * console.log(trueCount, falseCount); // 499994 500006
832
- * ```
833
- *
834
- * @param {number} rate -- 0.1 ~ 1 => 1% ~ 100%
835
- * @returns {boolean} true 命中
836
- * @category Calculate and Formula
837
- */
838
- export declare function inRate(rate: number): boolean;
839
- /**
840
- * EN: Detect the margin of Safety. Determine if it is a secure PWA environment that it can run.
841
- *
842
- * ZH: 判断是否是安全的 PWA 环境
843
- *
844
- * Usage:
845
- *
846
- * ```
847
- * isSafePWAEnv();
848
- * ```
849
- *
850
- * Output:
851
- *
852
- * ```
853
- * true
854
- * ```
855
- *
856
- * @returns {boolean} true 是
857
- * @category Browser Information
858
- */
859
- export declare function isSafePWAEnv(): boolean;
860
- /**
861
- * EN: Browser Information
862
- *
863
- * ZH: 返回浏览器信息 https://github.com/JowayYoung/juejin-code/blob/master/browser-type.js
864
- *
865
- * Usage:
866
- *
867
- * ```
868
- * getBrowserInfo();
869
- * ```
870
- *
871
- * Output:
872
- *
873
- * ```
874
- * {"engine":"webkit","engineVs":"537.36","platform":"desktop","supporter":"chrome","supporterVs":"85.0.4183.121","system":"windows","systemVs":"10"}
875
- * ```
876
- *
877
- * Results:
878
- *
879
- * | Attribute | Description | Type | Values |
880
- * | :------------ | :------------ | :------------ | :------------ |
881
- * | **system** | System | string | android, ios, windows, macos, linux |
882
- * | systemVs | System version | string | windows: 2000, xp, 2003, vista, 7, 8, 8.1, 10 <br />macos: ... |
883
- * | platform | Platform | string | desktop, mobile |
884
- * | engine | Engine | string | webkit, gecko, presto, trident |
885
- * | engineVs | Engine version | string | - |
886
- * | supporter | Supporter | string | edge, opera, chrome, safari, firefox, iexplore |
887
- * | supporterVs | Supporter version | string | - |
888
- * | shell | Shell | string | (Optional) wechat, qq_browser, qq_app, uc, 360, 2345, sougou, liebao, maxthon, bilibili |
889
- * | shellVs | Shell version | string | (Optional) 20/... |
890
- * | appleType | Apple device type | string | (Optional) ipad, iphone, ipod, iwatch |
891
- *
892
- * Example: Determine the environment of the mobile QQ.
893
- *
894
- * ```
895
- * const { system, shell } = getBrowserInfo();
896
- * const isMobileQQ = ['android', 'ios'].includes(system) && ['qq_browser', 'qq_app'].includes(shell);
897
- * ```
898
- *
899
- * @returns 浏览器信息
900
- * @category Browser Information
901
- */
902
- export declare function getBrowserInfo(): BrowserInfo;
903
- /**
904
- * 去除 HTML 标签
905
- *
906
- * @param {string} str 带html标签的字符串
907
- * @returns {string} 字符串
908
- * @category Util
909
- */
910
- export declare function clearHtml(str: string, options?: {
911
- removeNewLine?: boolean;
912
- }): string;
913
- /**
914
- * Sanitizes user input to prevent XSS attacks
915
- *
916
- * @param input - The input string to sanitize
917
- * @returns The sanitized input string
918
- * @category Util
919
- */
920
- export declare function sanitizeInput(input: string): string;
921
- /**
922
- * Reverses the sanitization done by the `sanitizeInput` function.
923
- *
924
- * @param input - The input string to unsanitize
925
- * @returns The unsanitized input string
926
- * @category Util
927
- */
928
- export declare function unsanitize(input: string): string;
929
- /**
930
- * 截取字符串,中文算 2 个字节
931
- *
932
- * @param {string} str 要截取的字符串
933
- * @param {number} len
934
- * @param {boolean} hasDot
935
- * @returns {string} 返回截取后的字符串
936
- * @category Util
937
- */
938
- export declare function truncateZHString(str: string, len: number, hasDot?: boolean): string;
939
- /**
940
- * Alias of `truncateZHString`
941
- *
942
- * @hidden
943
- */
944
- export declare function cutCHSString(str: string, len: number, hasDot?: boolean): string;
945
- /**
946
- * EN: Check whether the page is loaded successfully (Keep the compatibility if the browser's `load` event has been triggered).
947
- *
948
- * ZH: 页面加载完成
949
- *
950
- * ```
951
- * windowLoaded(30) // second
952
- * .then(res => {
953
- * console.log(`Load Success: ${res}`); // Load Success: load
954
- * })
955
- * .catch(err => {
956
- * console.log(`Load Timeout or Fail: ${err.message}`);
957
- * });
958
- * ```
959
- *
960
- * @param {number} timeout 超时时间 / 单位:秒
961
- * @returns {Promise<string>} document is loaded? 'complete' 'load' / 'timeout'
962
- * @category Load Resource
963
- */
964
- export declare function windowLoaded(timeout?: number): Promise<string | Error>;
965
- /**
966
- * EN: Add `<style>` in `<head>`.
967
- *
968
- * ZH: 添加样式标签; style: 样式标签内的字符串; id: `<style>` 标签的 `id`; 返回: 添加成功/失败
969
- *
970
- * Example 1: Add the `<style>` with `id`, and repeated invoking will update the content instead of adding a new one.
971
- *
972
- * ```
973
- * addStyle(
974
- * `
975
- * body {
976
- * background-color: #333;
977
- * }
978
- * `,
979
- * {
980
- * id: 'test',
981
- * }
982
- * );
983
- * // <style id="test">
984
- * // body {
985
- * // background-color: #333;
986
- * // }
987
- * // </style>
988
- * ```
989
- *
990
- * Example 2: Add the `<style>` without `id`, and repeated invoking will add a new one.
991
- *
992
- * ```
993
- * addStyle(
994
- * `
995
- * body {
996
- * background-color: #444;
997
- * }
998
- * `
999
- * );
1000
- * // <style>
1001
- * // body {
1002
- * // background-color: #444;
1003
- * // }
1004
- * // </style>
1005
- * ```
1006
- *
1007
- * @category DOM
1008
- */
1009
- export declare function addStyle(style: string, options?: {
1010
- id?: string;
1011
- }): boolean;
1012
- /**
1013
- * EN: Custom console printing (`console`).
1014
- *
1015
- * ZH: 生成自定义控制台打印
1016
- *
1017
- * Usage:
1018
- *
1019
- * ```
1020
- * const myConsole = genCustomConsole('MazeyLog:');
1021
- * myConsole.log('I am string.');
1022
- * myConsole.info('I am boolean.', true);
1023
- * myConsole.info('I am number.', 123, 456);
1024
- * myConsole.info('I am object.', { a: 123, b: 456});
1025
- * ```
1026
- *
1027
- * Output:
1028
- *
1029
- * ```
1030
- * MazeyLog: I am string.
1031
- * MazeyLog: I am boolean. true
1032
- * MazeyLog: I am number. 123 456
1033
- * MazeyLog: I am object. {a: 123, b: 456}
1034
- * ```
1035
- *
1036
- * @param {string} prefix 前缀
1037
- * @param {string} locales A locale string.
1038
- * @param {function} logFn The function with Log.
1039
- * @param {function} errorFn The function with Error.
1040
- * @returns {object} 新实例
1041
- * @category Debug
1042
- */
1043
- export declare function genCustomConsole(prefix?: string, options?: {
1044
- isClosed?: boolean;
1045
- showWrap?: boolean;
1046
- showDate?: boolean;
1047
- locales?: string;
1048
- logFn?: () => void;
1049
- errorFn?: () => void;
1050
- }): Console;
1051
- /**
1052
- * Verify the validity of axios response.
1053
- *
1054
- * Reference: [Handling Errors](https://axios-http.com/docs/handling_errors)
1055
- *
1056
- * @category Util
1057
- * @hidden
1058
- */
1059
- export declare function zAxiosIsValidRes(res: ZResResponse | undefined, options?: ZResIsValidResOptions): boolean;
1060
- /**
1061
- * Verify the validity of a non-empty array.
1062
- *
1063
- * @category Util
1064
- */
1065
- export declare function isNonEmptyArray<T>(arr: Array<T>): boolean;
1066
- /**
1067
- * Determine the validity of the data.
1068
- *
1069
- * Usage:
1070
- *
1071
- * ```
1072
- * const validData = {
1073
- * a: {
1074
- * b: {
1075
- * c: 413
1076
- * }
1077
- * }
1078
- * };
1079
- *
1080
- * const isValidDataResA = isValidData(validData, ['a', 'b', 'c'], 2333);
1081
- * const isValidDataResB = isValidData(validData, ['a', 'b', 'c'], 413);
1082
- * const isValidDataResC = isValidData(validData, ['d', 'd'], 413);
1083
- *
1084
- * console.log('isValidDataResA:', isValidDataResA);
1085
- * console.log('isValidDataResB:', isValidDataResB);
1086
- * console.log('isValidDataResC:', isValidDataResC);
1087
- * ```
1088
- *
1089
- * Output:
1090
- *
1091
- * ```
1092
- * isValidDataResA: false
1093
- * isValidDataResB: true
1094
- * isValidDataResC: false
1095
- * ```
1096
- *
1097
- * @param {any} data Original Data
1098
- * @param {string[]} attributes Data Attributes
1099
- * @param {any} validValue Given Value for verifying.
1100
- * @returns {boolean} Return TRUE if the data is valid.
1101
- * @category Util
1102
- */
1103
- export declare function isValidData(data: UnknownObject, attributes: string[], validValue: SimpleType): boolean;
1104
- /**
1105
- * 语义化文件大小, 把字节转换成正常文件大小.
1106
- *
1107
- * @category Util
1108
- */
1109
- export declare function getFileSize(size: number): string;
1110
- /**
1111
- * Detect webp support.
1112
- *
1113
- * Reference: [Detect WEBP Support with JavaScript](https://davidwalsh.name/detect-webp)
1114
- *
1115
- * @category Browser Information
1116
- */
1117
- export declare function isSupportWebp(): Promise<boolean>;
1118
- /**
1119
- * Generate a Hash Code from a string.
1120
- *
1121
- * Reference: [Generate a Hash from string in Javascript](https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery)
1122
- *
1123
- * @category Util
1124
- */
1125
- export declare function genHashCode(str: string): number;
1126
- /**
1127
- * Return the formatted date string in the given format.
1128
- *
1129
- * Usage:
1130
- *
1131
- * ```
1132
- * console.log('Default formatDate value:', formatDate());
1133
- * console.log('String formatDate value:', formatDate('Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)', 'yyyy-MM-dd hh:mm:ss'));
1134
- * console.log('Number formatDate value:', formatDate(1641881235000, 'yyyy-MM-dd hh:mm:ss'));
1135
- * console.log('Date formatDate value:', formatDate(new Date(2014, 1, 11), 'MM/dd/yyyy'));
1136
- * ```
1137
- *
1138
- * Output:
1139
- *
1140
- * ```
1141
- * Default formatDate value: 2023-01-11
1142
- * String formatDate value: 2022-01-11 14:12:26
1143
- * Number formatDate value: 2022-01-11 14:07:15
1144
- * Date formatDate value: 02/11/2014
1145
- * ```
1146
- *
1147
- * @param {Date|number|string} dateIns Original Date
1148
- * @param {string} format Format String
1149
- * @returns {string} Return the formatted date string.
1150
- * @category Util
1151
- */
1152
- export declare function formatDate(dateIns?: Date | number | string, format?: string): string;
1153
- /**
1154
- * Get event container.
1155
- *
1156
- * @category Event
1157
- * @hidden
1158
- */
1159
- export declare function getDefineListeners(): DefineListeners;
1160
- /**
1161
- * Add event.
1162
- *
1163
- * @param type
1164
- * @param fn
1165
- * @category Event
1166
- */
1167
- export declare function addEvent(type: string, fn: UnknownFn): void;
1168
- /**
1169
- * Invoke event.
1170
- *
1171
- * @param type
1172
- * @category Event
1173
- */
1174
- export declare function invokeEvent(type: string): void;
1175
- /**
1176
- * Remove event.
1177
- *
1178
- * @param type
1179
- * @param fn
1180
- * @category Event
1181
- */
1182
- export declare function removeEvent(type: string, fn: UnknownFn): void;
1183
- /**
1184
- * Checks if the given string is a valid URL, including **scheme URLs**.
1185
- *
1186
- * @example
1187
- * ```js
1188
- * isValidUrl('https://www.example.com'); // true
1189
- * isValidUrl('http://example.com/path/exx/ss'); // true
1190
- * isValidUrl('https://www.example.com/?q=hello&age=24#world'); // true
1191
- * isValidUrl('http://www.example.com/#world?id=9'); // true
1192
- * isValidUrl('ftp://example.com'); // true
1193
- * ```
1194
- *
1195
- * @remarks
1196
- * If you are specifically checking for HTTP/HTTPS URLs, it is recommended to use the `isValidHttpUrl` function instead.
1197
- * The `isValidUrl` function matches all scheme URLs, including FTP and other non-HTTP schemes.
1198
- *
1199
- * @param url - The URL to check.
1200
- * @returns Returns `true` if the given string is a valid URL, else `false`.
1201
- * @category URL
1202
- */
1203
- export declare function isValidUrl(url: string): boolean;
1204
- /**
1205
- * Check if the given string is a valid HTTP/HTTPS URL.
1206
- *
1207
- * @example
1208
- * ```js
1209
- * isValidHttpUrl('https://www.example.com'); // true
1210
- * isValidHttpUrl('http://example.com/path/exx/ss'); // true
1211
- * isValidHttpUrl('https://www.example.com/?q=hello&age=24#world'); // true
1212
- * isValidHttpUrl('http://www.example.com/#world?id=9'); // true
1213
- * isValidHttpUrl('ftp://example.com'); // false
1214
- * ```
1215
- *
1216
- * @param url
1217
- * @returns {boolean} Return true if the given string is a valid HTTP/HTTPS URL.
1218
- * @category URL
1219
- */
1220
- export declare function isValidHttpUrl(url: string): boolean;
1221
- /**
1222
- * Check if the given string is a mobile phone number.
1223
- *
1224
- * @example
1225
- * ```js
1226
- * console.log(isMobile('13800138000')); // true
1227
- * console.log(isMobile('1380013800')); // false
1228
- * console.log(isMobile('138001380000')); // false
1229
- * console.log(isMobile('1380013800a')); // false
1230
- * ```
1231
- *
1232
- * @param mobile
1233
- * @returns {boolean} Return true if the given string is a mobile phone number.
1234
- * @category Util
1235
- */
1236
- export declare function isValidPhoneNumber(mobile: string): boolean;
1237
- /**
1238
- * Check if the given string is a valid email.
1239
- *
1240
- * @example
1241
- * ```js
1242
- * console.log(isValidEmail('mazeyqian@gmail.com')); // true
1243
- * ```
1244
- *
1245
- * @param email
1246
- * @returns {boolean} Return true if the given string is a valid email.
1247
- * @category Util
1248
- */
1249
- export declare function isValidEmail(email: string): boolean;
1250
- /**
1251
- * Convert a given 10-hex number to a lowercase 26-hex string.
1252
- *
1253
- * @example
1254
- * ```js
1255
- * console.log(convert10To26(1)); // a
1256
- * console.log(convert10To26(26)); // z
1257
- * console.log(convert10To26(27)); // aa
1258
- * console.log(convert10To26(52)); // az
1259
- * console.log(convert10To26(53)); // ba
1260
- * ```
1261
- *
1262
- * @param {number} num
1263
- * @returns {string} Return a lowercase 26-hex string.
1264
- * @category Util
1265
- */
1266
- export declare function convert10To26(num: number): string;
1267
- /**
1268
- * EN: Get the file type of the url.
1269
- *
1270
- * ZH: 获取文件后缀名
1271
- *
1272
- * @example
1273
- * ```js
1274
- * console.log(getUrlFileType('https://example.com/a/b/c.png')); // png
1275
- * console.log(getUrlFileType('https://example.com/a/b/c.jpg')); // jpg
1276
- * console.log(getUrlFileType('https://example.com/a/b/c.jpeg')); // jpeg
1277
- * console.log(getUrlFileType('/a/b/c.jpeg')); // jpeg
1278
- * console.log(getUrlFileType('https://example.com/a/b/c.v/a')); // ''
1279
- * ```
1280
- *
1281
- * @param url
1282
- * @returns
1283
- * @category URL
1284
- */
1285
- export declare function getUrlFileType(url: string): boolean | string;
1286
- /**
1287
- * Sets the width and height of all images on the page based on their `src` attribute.
1288
- * The `src` attribute should contain `width` and/or `height` values in the format "width=100" or "height=100".
1289
- * If jQuery is available, this function uses jQuery to select the images. Otherwise, it uses pure JavaScript.
1290
- *
1291
- * @example
1292
- * ```
1293
- * // Example images with `src` attributes containing `width` and/or `height` values
1294
- * const img1 = document.createElement('img');
1295
- * img1.setAttribute('src', 'https://example.com/example.png?width=2233&height=111');
1296
- * document.body.appendChild(img1);
1297
- *
1298
- * const img2 = document.createElement('img');
1299
- * img2.setAttribute('src', 'https://example.com/example.png?width=100%&height=auto');
1300
- * document.body.appendChild(img2);
1301
- * ```
1302
- *
1303
- * @returns {boolean} - Returns `true` if images were found and their dimensions were set, otherwise `false`.
1304
- * @category DOM
1305
- */
1306
- export declare function setImgWidHeiBySrc(): boolean;
1307
- /**
1308
- * Generate the inline style string from the given parameters, First parameter is the ClassNames, Second parameter is the style array.
1309
- *
1310
- * @example
1311
- * ```js
1312
- * console.log(genStyleString('a', [ 'color:red' ])); // '.a{color:red;}'
1313
- * console.log(genStyleString('b', [ 'color:red', 'font-size:12px' ])); // '.b{color:red;font-size:12px;}'
1314
- * ```
1315
- *
1316
- * @param {string} className
1317
- * @param {Array} styleArray
1318
- * @returns {string} Return the inline style string.
1319
- * @category DOM
1320
- */
1321
- export declare function genStyleString(className: string, styleArray: Array<string>): string;
1322
- /**
1323
- * Load an image from the given URL.
1324
- *
1325
- * The target image will be loaded in the background, and the Promise status will change after the image is loaded. If the image fails to load, the Promise status will change to `reject` with the error object. If the image is loaded successfully, the Promise status will change to `resolve` with the image object. This method can be used to preload images and cache them in the browser. It can also be used to implement lazy loading of images.
1326
- *
1327
- * Note that this method will not add the image to the DOM.
1328
- *
1329
- * @example
1330
- * ```js
1331
- * loadImage('https://example.com/example.png')
1332
- * .then((img) => {
1333
- * console.log(img);
1334
- * })
1335
- * .catch((err) => {
1336
- * console.log(err);
1337
- * });
1338
- * ```
1339
- *
1340
- * @param {string} url - The URL of the image to load.
1341
- * @returns {Promise} A Promise that resolves with the loaded image or rejects with an error.
1342
- * @category Load Resource
1343
- */
1344
- export declare function loadImage(url: string): Promise<HTMLImageElement>;
1345
- /**
1346
- * Get the current version.
1347
- *
1348
- * @hidden
1349
- */
1350
- export declare function getCurrentVersion(): string;
1351
- /**
1352
- * Repeatedly fires a callback function with a certain interval until a specified condition is met.
1353
- *
1354
- * @param callback The callback function to fire.
1355
- * @param options An object containing the options for the function.
1356
- * @param options.interval The interval between each firing of the callback function, in milliseconds. Defaults to 1000.
1357
- * @param options.times The maximum number of times to fire the callback function. Defaults to 10.
1358
- * @param options.context The context to use when calling the callback function. Defaults to null.
1359
- * @param options.args An array of arguments to pass to the callback function.
1360
- * @param condition A function that takes the result of the callback function as its argument and returns a boolean value indicating whether the condition has been met. Defaults to a function that always returns true.
1361
- * @category Util
1362
- */
1363
- export declare function repeatUntilConditionMet<T extends (...args: UnknownFnParams) => UnknownFnReturn>(callback: T, options?: RepeatUntilOptions, condition?: (result: ReturnType<T>) => boolean): void;
1364
- /**
1365
- * Load a script from the given URL if it (`window['attribute']`) has not already been loaded.
1366
- *
1367
- * @example
1368
- * ```js
1369
- * loadScriptIfUndefined('jQuery', 'https://example.com/lib/jquery.min.js')
1370
- * .then(() => {
1371
- * console.log('jQuery is loaded.');
1372
- * })
1373
- * .catch(err => {
1374
- * console.log('Failed to load jQuery.', err);
1375
- * });
1376
- * ```
1377
- *
1378
- * @param {string} windowAttribute - The name of the window attribute to check (e.g. `jQuery`, `axios`, etc.).
1379
- * @param {string} url - The URL of the script to load.
1380
- * @returns {Promise} A Promise that resolves when the script has been loaded.
1381
- * @category Load Resource
1382
- */
1383
- export declare function loadScriptIfUndefined(windowAttribute: string, url: string): LoadScriptReturns;
1384
- /**
1385
- * Retrieve a query parameter from a script URL in the browser.
1386
- *
1387
- * @param param - The name of the query parameter to retrieve.
1388
- * @param matchString - An optional substring to match in the script URL.
1389
- * If not provided, defaults to matching the ".js" substring.
1390
- * @returns The decoded value of the specified query parameter, or an empty string if no matching parameter is found.
1391
- * @category URL
1392
- */
1393
- export declare function getScriptQueryParam(param: string, matchString?: string): string;
1394
- export {};
1
+ /**
2
+ * @author: Mazey Chu
3
+ */
4
+ import { BrowserInfo, DefineListeners, ThrottleFunc, DebounceFunc, IsNumberOptions, AnyFunction, ZResResponse, ZResIsValidResOptions, RepeatUntilOptions, LoadScriptReturns, SimpleType, UnknownFnParams, UnknownFnReturn, UnknownObject, UnknownFn } from './typing';
5
+ /**
6
+ * EN: Computes the longest common substring of two strings.
7
+ *
8
+ * ZH: 计算两个字符串的最长公共子串
9
+ *
10
+ * Usage:
11
+ *
12
+ * ```
13
+ * longestComSubstring('fish', 'finish');
14
+ * ```
15
+ *
16
+ * Output:
17
+ *
18
+ * ```
19
+ * 3
20
+ * ```
21
+ *
22
+ * @param {string} aStr String
23
+ * @param {string} bStr String
24
+ * @returns {number} Length
25
+ * @category Calculate and Formula
26
+ */
27
+ export declare function longestComSubstring(aStr: string, bStr: string): number;
28
+ /**
29
+ * Alias of `longestComSubstring`
30
+ *
31
+ * @hidden
32
+ */
33
+ export declare function calLongestCommonSubstring(aStr: string, bStr: string): number;
34
+ /**
35
+ * EN: Computes the longest common subsequence of two strings.
36
+ *
37
+ * ZH: 计算两个字符串的最长公共子序列
38
+ *
39
+ * Usage:
40
+ *
41
+ * ```
42
+ * longestComSubsequence('fish', 'finish');
43
+ * ```
44
+ *
45
+ * Output:
46
+ *
47
+ * ```
48
+ * 4
49
+ * ```
50
+ *
51
+ * @param {string} aStr 字符串
52
+ * @param {string} bStr 字符串
53
+ * @returns {number} 长度
54
+ * @category Calculate and Formula
55
+ */
56
+ export declare function longestComSubsequence(aStr: string, bStr: string): number;
57
+ /**
58
+ * Alias of `longestComSubsequence`
59
+ *
60
+ * @hidden
61
+ */
62
+ export declare function calLongestCommonSubsequence(aStr: string, bStr: string): number;
63
+ /**
64
+ * Get the query param's value of the current Web URL(`location.search`).
65
+ *
66
+ * ```
67
+ * // http://example.com/?t1=1&t2=2&t3=3&t4=4#2333
68
+ * // ?t1=1&t2=2&t3=3&t4=4
69
+ * getQueryParam('t3'); // 3
70
+ * getQueryParam('t4'); // 4
71
+ * ```
72
+ *
73
+ * @param {string} param Query param.
74
+ * @returns {string} value
75
+ * @category URL
76
+ */
77
+ export declare function getQueryParam(param: string): string;
78
+ /**
79
+ * Returns the value of the specified query parameter in the input URL.
80
+ *
81
+ * @example
82
+ * ```
83
+ * getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3'); // Returns '3'
84
+ * getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4'); // Returns '4'
85
+ * ```
86
+ *
87
+ * @param {string} url The URL string.
88
+ * @param {string} param The query parameter to retrieve the value for.
89
+ * @returns {string|string[]} The value of the specified query parameter, or an empty string if the parameter is not found.
90
+ * @category URL
91
+ */
92
+ export declare function getUrlParam(url: string, param: string): string | string[];
93
+ /**
94
+ * Update the query param's value of the input URL.
95
+ *
96
+ * Usage:
97
+ *
98
+ * ```
99
+ * updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3', 'three');
100
+ * updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four');
101
+ * ```
102
+ *
103
+ * Output:
104
+ *
105
+ * ```
106
+ * http://example.com/?t1=1&t2=2&t3=three&t4=4
107
+ * http://example.com/?t1=1&t2=2&t3=3&t4=four
108
+ * ```
109
+ *
110
+ * @param {string} url URL string.
111
+ * @param {string} param Query param.
112
+ * @param {string} value Param's value.
113
+ * @returns {string} URL.
114
+ * @category URL
115
+ */
116
+ export declare function updateQueryParam(url: string, param: string, value: string): string;
117
+ /**
118
+ * Get the hash query param's value of the current Web URL(`location.hash`).
119
+ *
120
+ * Usage:
121
+ *
122
+ * ```
123
+ * // http://example.com/?#2333?t1=1&t2=2&t3=3&t4=4
124
+ * // #2333?t1=1&t2=2&t3=3&t4=4
125
+ * getHashQueryParam('t3');
126
+ * getHashQueryParam('t4');
127
+ * ```
128
+ *
129
+ * Output:
130
+ *
131
+ * ```
132
+ * 3
133
+ * 4
134
+ * ```
135
+ *
136
+ * @param {string} param Query param.
137
+ * @returns {string} value
138
+ * @category URL
139
+ */
140
+ export declare function getHashQueryParam(param: string): string;
141
+ /**
142
+ * Get the domain of URL, and other params.
143
+ *
144
+ * Usage:
145
+ *
146
+ * ```
147
+ * getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4');
148
+ * getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']);
149
+ * getDomain('http://example.com:7890/test/thanks', ['hostname']);
150
+ * getDomain('http://example.com:7890/test/thanks', ['host']); // With Port
151
+ * getDomain('http://example.com:7890/test/thanks', ['origin']);
152
+ * getDomain('http://example.com:7890/test/thanks?id=1', ['origin', 'pathname', 'search']);
153
+ * ```
154
+ *
155
+ * Output:
156
+ *
157
+ * ```
158
+ * example.com
159
+ * example.com/test/thanks
160
+ * example.com
161
+ * example.com:7890
162
+ * http://example.com:7890
163
+ * http://example.com:7890/test/thanks?id=1
164
+ * ```
165
+ *
166
+ * @param {string} url
167
+ * @param {array} rules Object.keys(location), ['href', 'origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
168
+ * @category URL
169
+ */
170
+ export declare function getDomain(url: string, rules?: string[]): string;
171
+ /**
172
+ * Transfer CamelCase to KebabCase.
173
+ *
174
+ * ```
175
+ * convertCamelToKebab('ABC'); // a-b-c
176
+ * convertCamelToKebab('aBC'); // a-b-c
177
+ * ```
178
+ *
179
+ * @param {string} camelCase 'aBC' or 'ABC'
180
+ * @returns {string} 'a-b-c'
181
+ * @category Util
182
+ */
183
+ export declare function convertCamelToKebab(camelCase: string): string;
184
+ /**
185
+ * Alias of `convertCamelToKebab`
186
+ *
187
+ * @hidden
188
+ */
189
+ export declare function camelCaseToKebabCase(camelCase: string): string;
190
+ /**
191
+ * Transfer CamelCase to Underscore.
192
+ *
193
+ * ```
194
+ * convertCamelToUnder('ABC'); // a_b_c
195
+ * convertCamelToUnder('aBC'); // a_b_c
196
+ * ```
197
+ *
198
+ * @param {string} camelCase 'aBC' or 'ABC'
199
+ * @returns {string} 'a_b_c'
200
+ * @category Util
201
+ */
202
+ export declare function convertCamelToUnder(camelCase: string): string;
203
+ /**
204
+ * Alias of `convertCamelToUnder`
205
+ *
206
+ * @hidden
207
+ */
208
+ export declare function camelCase2Underscore(camelCase: string): string;
209
+ /**
210
+ * Remove leading and trailing whitespace or specified characters from string.
211
+ *
212
+ * Note: This method is used to replace the native `String.prototype.trim()`. But it is not necessary to use it in modern browsers.
213
+ *
214
+ * ```
215
+ * mTrim(' 1 2 3 '); // '1 2 3'
216
+ * mTrim('abc '); // 'abc'
217
+ * ```
218
+ *
219
+ * @param {string} str The string to trim.
220
+ * @returns {string} Trimmed string.
221
+ * @category Util
222
+ * @hidden
223
+ */
224
+ export declare function mTrim(str: string): string;
225
+ /**
226
+ * Make a new line of HTML.
227
+ *
228
+ * ```
229
+ * newLine('a\nb\nc'); // 'a<br />b<br />c'
230
+ * newLine('a\n\nbc'); // 'a<br /><br />bc'
231
+ * ```
232
+ *
233
+ * @param {string} str The string to make a new line.
234
+ * @returns {string} A newline with `br`.
235
+ * @category DOM
236
+ */
237
+ export declare function newLine(str: string): string;
238
+ /**
239
+ * Copy/Clone Object deeply.
240
+ *
241
+ * Usage:
242
+ *
243
+ * ```
244
+ * deepCopy(['a', 'b', 'c']);
245
+ * deepCopy('abc');
246
+ * ```
247
+ *
248
+ * Output:
249
+ *
250
+ * ```
251
+ * ['a', 'b', 'c']
252
+ * 'abc'
253
+ * ```
254
+ *
255
+ * @param {object} obj The value to clone.
256
+ * @returns {object} Returns the deep cloned value.
257
+ * @category Util
258
+ */
259
+ export declare function deepCopy<T>(obj: T): T;
260
+ /**
261
+ * Alias of `deepCopy`
262
+ *
263
+ * @hidden
264
+ */
265
+ export declare function deepCopyObject<T>(obj: T): T;
266
+ /**
267
+ * Check whether it is a valid JSON string.
268
+ *
269
+ * Usage:
270
+ *
271
+ * ```
272
+ * isJSONString(`['a', 'b', 'c']`);
273
+ * isJSONString(`["a", "b", "c"]`);
274
+ * ```
275
+ *
276
+ * Output:
277
+ *
278
+ * ```
279
+ * false
280
+ * true
281
+ * ```
282
+ *
283
+ * @param {string} str The string to check.
284
+ * @returns {boolean} Return the result of checking.
285
+ * @category Util
286
+ */
287
+ export declare function isJSONString(str: string): boolean;
288
+ /**
289
+ * Alias of `isJSONString`
290
+ *
291
+ * @hidden
292
+ */
293
+ export declare function isJsonString(str: string): boolean;
294
+ /**
295
+ * Produce a random string of number, `genRndNumString(7)` => '7658495'.
296
+ *
297
+ * ```
298
+ * genRndNumString(4); // '9730'
299
+ * genRndNumString(7); // '2262490'
300
+ * ```
301
+ *
302
+ * @param {number} n Length
303
+ * @returns {string} Return the random string.
304
+ * @category Util
305
+ */
306
+ export declare function genRndNumString(n?: number): string;
307
+ /**
308
+ * Alias of `genRndNumString`
309
+ *
310
+ * @hidden
311
+ */
312
+ export declare function generateRndNum(n?: number): string;
313
+ /**
314
+ * 根据时间生成唯一标志的数字 genUniqueNumString() => 1538324722364123
315
+ *
316
+ * @param {number} n 随机数的长度
317
+ * @category Util
318
+ */
319
+ export declare function genUniqueNumString(n?: number): string;
320
+ /**
321
+ * Alias of `genUniqueNumString`
322
+ *
323
+ * @hidden
324
+ */
325
+ export declare function generateUniqueNum(n?: number): string;
326
+ /**
327
+ * 浮点数转为百分比 0.2 => 20%
328
+ *
329
+ * @param {number} num 浮点数
330
+ * @param {number} fixSize 保留几位浮点数
331
+ * @category Util
332
+ */
333
+ export declare function floatToPercent(num: number, fixSize?: number): string;
334
+ /**
335
+ * 浮点数保留指定位
336
+ *
337
+ * @category Util
338
+ */
339
+ export declare function floatFixed(num: string, size?: number): string;
340
+ /**
341
+ * 阻止冒泡
342
+ *
343
+ * @category Event
344
+ */
345
+ export declare function cancelBubble(e: Event): void;
346
+ /**
347
+ * Modify `class`.
348
+ *
349
+ * ```
350
+ * const dom = document.querySelector('#box');
351
+ *
352
+ * // Determine `class`
353
+ * hasClass(dom, 'test');
354
+ * // Add `class`
355
+ * addClass(dom, 'test');
356
+ * // Remove `class`
357
+ * removeClass(dom, 'test');
358
+ * ```
359
+ *
360
+ * @category DOM
361
+ */
362
+ export declare function hasClass(obj: HTMLElement, cls: string): boolean;
363
+ /**
364
+ * Modify `class`.
365
+ *
366
+ * ```
367
+ * const dom = document.querySelector('#box');
368
+ *
369
+ * // Determine `class`
370
+ * hasClass(dom, 'test');
371
+ * // Add `class`
372
+ * addClass(dom, 'test');
373
+ * // Remove `class`
374
+ * removeClass(dom, 'test');
375
+ * ```
376
+ *
377
+ * @category DOM
378
+ */
379
+ export declare function addClass(obj: HTMLElement, cls: string): void;
380
+ /**
381
+ * Modify `class`.
382
+ *
383
+ * ```
384
+ * const dom = document.querySelector('#box');
385
+ *
386
+ * // Determine `class`
387
+ * hasClass(dom, 'test');
388
+ * // Add `class`
389
+ * addClass(dom, 'test');
390
+ * // Remove `class`
391
+ * removeClass(dom, 'test');
392
+ * ```
393
+ *
394
+ * @category DOM
395
+ */
396
+ export declare function removeClass(obj: HTMLElement, cls: string): void;
397
+ /**
398
+ * EN: Throttle
399
+ *
400
+ * ZH: 节流
401
+ *
402
+ * ```
403
+ * const foo = throttle(() => {
404
+ * console.log('The function will be invoked at most once per every wait 1000 milliseconds.');
405
+ * }, 1000, { leading: true });
406
+ * ```
407
+ *
408
+ * Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
409
+ *
410
+ * @category Util
411
+ */
412
+ export declare function throttle<T extends (...args: UnknownFnParams) => UnknownFnReturn>(func: T, wait: number, options?: {
413
+ leading?: boolean;
414
+ trailing?: boolean;
415
+ }): ThrottleFunc<T>;
416
+ /**
417
+ * EN: Debounce
418
+ *
419
+ * ZH: 去抖
420
+ *
421
+ * ```
422
+ * const foo = debounce(() => {
423
+ * console.log('The debounced function will only be invoked in 1000 milliseconds, the other invoking will disappear during the wait time.');
424
+ * }, 1000, true);
425
+ * ```
426
+ *
427
+ * @category Util
428
+ */
429
+ export declare function debounce<T extends (...args: UnknownFnParams) => UnknownFnReturn>(func: T, wait: number, immediate?: boolean): DebounceFunc<T>;
430
+ /**
431
+ * 获取间隔时间
432
+ *
433
+ * @example
434
+ * ```js
435
+ * console.log('getFriendlyInterval:', getFriendlyInterval(new Date('2020-03-28 00:09:27'), new Date('2023-04-18 10:54:00'), { type: 'd' })); // 1116
436
+ * console.log('getFriendlyInterval:', getFriendlyInterval(1585325367000, 1681786440000, { type: 'text' })); // 1116 天 10 时 44 分 33 秒
437
+ * console.log('getFriendlyInterval:', getFriendlyInterval('2020-03-28 00:09:27', '2023-04-18 10:54:00', { type: 'text' })); // 1116 天 10 时 44 分 33 秒
438
+ * ```
439
+ *
440
+ * @param {number/Date} start 开始时间戳 1585325367122
441
+ * @param {number/Date} end 结束时间戳 1585325367122
442
+ * @param {string} options.type 返回类型 d: 2(天) text: 2 天 4 时...
443
+ * @returns {string/number} 取决于 type
444
+ * @category Util
445
+ */
446
+ export declare function getFriendlyInterval(start?: number | string | Date, end?: number | string | Date, options?: {
447
+ type?: string;
448
+ }): number | string;
449
+ /**
450
+ * EN: Check whether it is a right number.
451
+ *
452
+ * ZH: 判断是否有效数字
453
+ *
454
+ * ```
455
+ * isNumber(123); // true
456
+ * isNumber('123'); // false
457
+ * // Default: NaN, Infinity is not Number
458
+ * isNumber(Infinity); // false
459
+ * isNumber(Infinity, { isInfinityAsNumber: true }); // true
460
+ * isNumber(NaN); // false
461
+ * isNumber(NaN, { isNaNAsNumber: true, isInfinityAsNumber: true }); // true
462
+ * ```
463
+ *
464
+ * @param {*} num 被判断的值
465
+ * @param {boolean} options.isNaNAsNumber 是否 NaN 算数字(默认不算)
466
+ * @param {boolean} options.isInfinityAsNumber 是否 无限 算数字(默认不算)
467
+ * @returns {boolean} true 是数字
468
+ * @category Util
469
+ */
470
+ export declare function isNumber(num: unknown, options?: IsNumberOptions): boolean;
471
+ /**
472
+ * 执行有效函数
473
+ *
474
+ * @param {function} fn 等待被执行的未知是否有效的函数
475
+ * @category Util
476
+ */
477
+ export declare function doFn(fn: AnyFunction, ...params: Parameters<AnyFunction>): ReturnType<AnyFunction> | null;
478
+ /**
479
+ * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
480
+ *
481
+ * ZH: 存储/获取数据到 sessionStorage/localStorage
482
+ *
483
+ * ```
484
+ * setSessionStorage('test', '123');
485
+ * getSessionStorage('test'); // 123
486
+ * setLocalStorage('test', '123');
487
+ * getLocalStorage('test'); // 123
488
+ *
489
+ * // or package in usage
490
+ * const projectName = 'mazey';
491
+ * function mSetLocalStorage (key, value) {
492
+ * return setLocalStorage(`${projectName}_${key}`, value);
493
+ * }
494
+ *
495
+ * function mGetLocalStorage (key) {
496
+ * return getLocalStorage(`${projectName}_${key}`);
497
+ * }
498
+ * ```
499
+ *
500
+ * @param {string} key 键
501
+ * @returns {void} 返回值
502
+ * @category Cache Data
503
+ */
504
+ export declare function setSessionStorage<T>(key: string, value?: T | null): void;
505
+ /**
506
+ * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
507
+ *
508
+ * ZH: 存储/获取数据到 sessionStorage/localStorage
509
+ *
510
+ * ```
511
+ * setSessionStorage('test', '123');
512
+ * getSessionStorage('test'); // 123
513
+ * setLocalStorage('test', '123');
514
+ * getLocalStorage('test'); // 123
515
+ *
516
+ * // or package in usage
517
+ * const projectName = 'mazey';
518
+ * function mSetLocalStorage (key, value) {
519
+ * return setLocalStorage(`${projectName}_${key}`, value);
520
+ * }
521
+ *
522
+ * function mGetLocalStorage (key) {
523
+ * return getLocalStorage(`${projectName}_${key}`);
524
+ * }
525
+ * ```
526
+ *
527
+ * @param {string} key 键
528
+ * @returns {any} 返回值
529
+ * @category Cache Data
530
+ */
531
+ export declare function getSessionStorage<T>(key: string): T | null;
532
+ /**
533
+ * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
534
+ *
535
+ * ZH: 存储/获取数据到 sessionStorage/localStorage
536
+ *
537
+ * ```
538
+ * setSessionStorage('test', '123');
539
+ * getSessionStorage('test'); // 123
540
+ * setLocalStorage('test', '123');
541
+ * getLocalStorage('test'); // 123
542
+ *
543
+ * // or package in usage
544
+ * const projectName = 'mazey';
545
+ * function mSetLocalStorage (key, value) {
546
+ * return setLocalStorage(`${projectName}_${key}`, value);
547
+ * }
548
+ *
549
+ * function mGetLocalStorage (key) {
550
+ * return getLocalStorage(`${projectName}_${key}`);
551
+ * }
552
+ * ```
553
+ *
554
+ * @param {string} key 键
555
+ * @returns {void} 返回值
556
+ * @category Cache Data
557
+ */
558
+ export declare function setLocalStorage<T>(key: string, value?: T | null): void;
559
+ /**
560
+ * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
561
+ *
562
+ * ZH: 存储/获取数据到 sessionStorage/localStorage
563
+ *
564
+ * ```
565
+ * setSessionStorage('test', '123');
566
+ * getSessionStorage('test'); // 123
567
+ * setLocalStorage('test', '123');
568
+ * getLocalStorage('test'); // 123
569
+ *
570
+ * // or package in usage
571
+ * const projectName = 'mazey';
572
+ * function mSetLocalStorage (key, value) {
573
+ * return setLocalStorage(`${projectName}_${key}`, value);
574
+ * }
575
+ *
576
+ * function mGetLocalStorage (key) {
577
+ * return getLocalStorage(`${projectName}_${key}`);
578
+ * }
579
+ * ```
580
+ *
581
+ * @param {string} key 键
582
+ * @returns {any} 返回值
583
+ * @category Cache Data
584
+ */
585
+ export declare function getLocalStorage<T>(key: string): T | null;
586
+ /**
587
+ * EN: Load a CSS file from the server.
588
+ *
589
+ * ZH: 动态加载 CSS 文件
590
+ *
591
+ * ```
592
+ * loadCSS(
593
+ * 'http://example.com/path/example.css',
594
+ * {
595
+ * id: 'iamid', // Optional, link ID, default none
596
+ * }
597
+ * )
598
+ * .then(
599
+ * res => {
600
+ * console.log(`Load CSS Success: ${res}`);
601
+ * }
602
+ * )
603
+ * .catch(
604
+ * err => {
605
+ * console.error(`Load CSS Fail: ${err.message}`)
606
+ * }
607
+ * );
608
+ * ```
609
+ *
610
+ * @param {string} url -- css资源路径
611
+ * @param {string} options.id -- link标签id
612
+ * @returns {Promise<string>} true -- 加载成功
613
+ * @category Load Resource
614
+ */
615
+ export declare function loadCSS(url: string, options?: {
616
+ id?: string;
617
+ }): Promise<unknown>;
618
+ /**
619
+ * EN: Load a JavaScript file from the server and execute it.
620
+ *
621
+ * ZH: 动态加载 JavaScript 文件
622
+ *
623
+ * ```
624
+ * loadScript(
625
+ * 'http://example.com/static/js/plugin-2.1.1.min.js',
626
+ * {
627
+ * id: 'iamid', // (Optional) script ID, default none
628
+ * timeout: 5000, // (Optional) timeout, default `5000`
629
+ * isDefer: false, // (Optional) defer, default `false`
630
+ * }
631
+ * )
632
+ * .then(
633
+ * res => {
634
+ * console.log(`Load JavaScript script: ${res}`);
635
+ * }
636
+ * )
637
+ * .catch(
638
+ * err => {
639
+ * console.error(`Load JavaScript script: ${err.message}`)
640
+ * }
641
+ * );
642
+ * ```
643
+ *
644
+ * @param {string} url -- JavaScript 资源路径
645
+ * @param {string} options.id -- DOM ID
646
+ * @param {function} options.callback -- 加载后回调函数
647
+ * @param {number} options.timeout -- 超时时长
648
+ * @param {boolean} options.isDefer -- 是否添加 defer 标签
649
+ * @returns {Promise<string>} -- true 成功
650
+ * @category Load Resource
651
+ */
652
+ export declare function loadScript(url: string, options?: {
653
+ id?: string;
654
+ callback?: (...params: UnknownFnParams) => UnknownFnReturn;
655
+ timeout?: number;
656
+ isDefer?: boolean;
657
+ }): LoadScriptReturns;
658
+ /**
659
+ * 获取时间戳
660
+ *
661
+ * @category Util
662
+ */
663
+ export declare function mNow(): number;
664
+ /**
665
+ * EN: Handle Cookie.
666
+ *
667
+ * ZH: 设置/获取 Cookie
668
+ *
669
+ * ```
670
+ * setCookie('test', '123', 30, 'example.com'); // key value day domain
671
+ * getCookie('test'); // 123
672
+ * ```
673
+ *
674
+ * @category Cache Data
675
+ */
676
+ export declare function setCookie(name: string, value: string, days?: number, domain?: string): void;
677
+ /**
678
+ * EN: Handle Cookie.
679
+ *
680
+ * ZH: 设置/获取 Cookie
681
+ *
682
+ * ```
683
+ * setCookie('test', '123', 30, 'example.com'); // key value day domain
684
+ * getCookie('test'); // 123
685
+ * ```
686
+ *
687
+ * @category Cache Data
688
+ */
689
+ export declare function getCookie(name: string): string;
690
+ /**
691
+ * Delete a cookie by name.
692
+ *
693
+ * @param name - The name of the cookie to delete.
694
+ * @returns `true` if the cookie was deleted successfully, `false` otherwise.
695
+ * @category Cache Data
696
+ */
697
+ export declare function delCookie(name: string): boolean;
698
+ /**
699
+ * @hidden
700
+ */
701
+ interface WebPerformance {
702
+ [key: string]: string | number;
703
+ }
704
+ /**
705
+ * Gets the first contentful paint (FCP) time of a web page using the Performance API.
706
+ * The FCP time is the time it takes for the first piece of content to be painted on the screen.
707
+ *
708
+ * @returns A promise that resolves with the FCP time in milliseconds, or 0 if the 'paint' entry type is not supported.
709
+ * @category Web Performance
710
+ */
711
+ export declare function getFCP(): Promise<number>;
712
+ /**
713
+ * Gets the first paint (FP) time of a web page using the Performance API.
714
+ * The FP time is the time it takes for the first pixel to be painted on the screen.
715
+ *
716
+ * @returns A promise that resolves with the FP time in milliseconds, or 0 if the 'paint' entry type is not supported.
717
+ * @category Web Performance
718
+ */
719
+ export declare function getFP(): Promise<number>;
720
+ /**
721
+ * Gets the largest contentful paint (LCP) time of a web page using the Performance API.
722
+ * The LCP time is the time it takes for the largest piece of content to be painted on the screen.
723
+ *
724
+ * @returns A promise that resolves with the LCP time in milliseconds, or 0 if the 'largest-contentful-paint' entry type is not supported.
725
+ * @category Web Performance
726
+ */
727
+ export declare function getLCP(): Promise<number>;
728
+ /**
729
+ * Gets the first input delay (FID) of a web page using the Performance API.
730
+ * The FID is the time it takes for the first user input to be processed by the browser.
731
+ *
732
+ * @returns A promise that resolves with the FID in milliseconds, or 0 if the 'first-input' entry type is not supported.
733
+ * @category Web Performance
734
+ */
735
+ export declare function getFID(): Promise<number>;
736
+ /**
737
+ * Gets the Cumulative Layout Shift (CLS) score of a web page using the Performance API.
738
+ * The CLS score is a measure of how much the page layout shifts during loading.
739
+ *
740
+ * @returns A promise that resolves with the CLS score, or 0 if the 'layout-shift' entry type is not supported.
741
+ * @category Web Performance
742
+ */
743
+ export declare function getCLS(): Promise<number>;
744
+ /**
745
+ * Gets the time to first byte (TTFB) of a web page using the Performance API.
746
+ * The TTFB is the time it takes for the first byte of the response to be received by the browser.
747
+ *
748
+ * @returns The TTFB in milliseconds, or 0 if the navigation timing information is not available.
749
+ * @category Web Performance
750
+ */
751
+ export declare function getTTFB(): Promise<number>;
752
+ /**
753
+ * EN: Get page load time(`PerformanceNavigationTiming`).
754
+ *
755
+ * ZH: 获取页面加载相关的各项数据
756
+ *
757
+ * @remarks
758
+ * This function uses the [`PerformanceNavigationTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming) API to get page load time data.
759
+ * The `PerformanceNavigationTiming` API provides more accurate and detailed information about page load time than the deprecated [`PerformanceTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming) API.
760
+ * If you are using an older browser that does not support `PerformanceNavigationTiming`, you can still use the `PerformanceTiming` API by using the previous version of this library ([`v3.9.7`](https://www.npmjs.com/package/mazey/v/3.9.7)).
761
+ *
762
+ * Usage:
763
+ *
764
+ * ```
765
+ * // `camelCase:false` (Default) Return underline(`a_b`) data.
766
+ * // `camelCase:true` Return hump(`aB`) data.
767
+ * getPerformance()
768
+ * .then(res => {
769
+ * console.log(JSON.stringify(res));
770
+ * })
771
+ * .catch(console.error);
772
+ * ```
773
+ *
774
+ * Output:
775
+ *
776
+ * ```
777
+ * {"source":"PerformanceNavigationTiming","os":"others","os_version":"","device_type":"pc","network":"4g","screen_direction":"","unload_time":0,"redirect_time":0,"dns_time":0,"tcp_time":0,"ssl_time":0,"response_time":2,"download_time":2,"first_paint_time":288,"first_contentful_paint_time":288,"dom_ready_time":0,"onload_time":0,"white_time":0,"render_time":0,"decoded_body_size":718,"encoded_body_size":718}
778
+ * ```
779
+ *
780
+ * Results:
781
+ *
782
+ * | Attribute | Description | Type | Values |
783
+ * | :------------ | :------------ | :------------ | :------------ |
784
+ * | dns_time | DNS Lookup | number | domainLookupEnd - domainLookupStart |
785
+ * | tcp_time | Connection Negotiation | number | connectEnd - connectStart |
786
+ * | response_time | Requests and Responses | number | responseStart - requestStart |
787
+ * | white_time | White Screen | number | responseStart - navigationStart |
788
+ * | dom_ready_time | Dom Ready | number | domContentLoadedEventStart - navigationStart |
789
+ * | onload_time | Onload | number | loadEventStart - navigationStart |
790
+ * | render_time | EventEnd | number | loadEventEnd -navigationStart |
791
+ * | unload_time | Unload | number | (Optional) unloadEventEnd - unloadEventStart |
792
+ * | redirect_time | Redirect | number | (Optional) redirectEnd - redirectStart |
793
+ * | ssl_time | SSL | number | (Optional) connectEnd - secureConnectionStart |
794
+ * | download_time | Download | number | (Optional) responseEnd - responseStart |
795
+ *
796
+ * @param {boolean} camelCase -- false(默认) 以下划线形式返回数据 true 以驼峰形式返回数据
797
+ * @returns {Promise<object>} 加载数据
798
+ * @category Web Performance
799
+ */
800
+ export declare function getPerformance(camelCase?: boolean): Promise<WebPerformance | Error>;
801
+ /**
802
+ * EN: Hit probability (1% ~ 100%).
803
+ *
804
+ * ZH: 百分位概率
805
+ *
806
+ * Usage:
807
+ *
808
+ * ```
809
+ * inRate(0.5); // 0.01 ~ 1 true/false
810
+ * ```
811
+ *
812
+ * Output:
813
+ *
814
+ * ```
815
+ * true
816
+ * ```
817
+ *
818
+ * Example: Test the precision.
819
+ *
820
+ * ```
821
+ * // Test
822
+ * let trueCount = 0;
823
+ * let falseCount = 0;
824
+ * new Array(1000000).fill(0).forEach(() => {
825
+ * if (inRate(0.5)) {
826
+ * trueCount++;
827
+ * } else {
828
+ * falseCount++;
829
+ * }
830
+ * });
831
+ * console.log(trueCount, falseCount); // 499994 500006
832
+ * ```
833
+ *
834
+ * @param {number} rate -- 0.1 ~ 1 => 1% ~ 100%
835
+ * @returns {boolean} true 命中
836
+ * @category Calculate and Formula
837
+ */
838
+ export declare function inRate(rate: number): boolean;
839
+ /**
840
+ * EN: Detect the margin of Safety. Determine if it is a secure PWA environment that it can run.
841
+ *
842
+ * ZH: 判断是否是安全的 PWA 环境
843
+ *
844
+ * Usage:
845
+ *
846
+ * ```
847
+ * isSafePWAEnv();
848
+ * ```
849
+ *
850
+ * Output:
851
+ *
852
+ * ```
853
+ * true
854
+ * ```
855
+ *
856
+ * @returns {boolean} true 是
857
+ * @category Browser Information
858
+ */
859
+ export declare function isSafePWAEnv(): boolean;
860
+ /**
861
+ * EN: Browser Information
862
+ *
863
+ * ZH: 返回浏览器信息 https://github.com/JowayYoung/juejin-code/blob/master/browser-type.js
864
+ *
865
+ * Usage:
866
+ *
867
+ * ```
868
+ * getBrowserInfo();
869
+ * ```
870
+ *
871
+ * Output:
872
+ *
873
+ * ```
874
+ * {"engine":"webkit","engineVs":"537.36","platform":"desktop","supporter":"chrome","supporterVs":"85.0.4183.121","system":"windows","systemVs":"10"}
875
+ * ```
876
+ *
877
+ * Results:
878
+ *
879
+ * | Attribute | Description | Type | Values |
880
+ * | :------------ | :------------ | :------------ | :------------ |
881
+ * | **system** | System | string | android, ios, windows, macos, linux |
882
+ * | systemVs | System version | string | windows: 2000, xp, 2003, vista, 7, 8, 8.1, 10 <br />macos: ... |
883
+ * | platform | Platform | string | desktop, mobile |
884
+ * | engine | Engine | string | webkit, gecko, presto, trident |
885
+ * | engineVs | Engine version | string | - |
886
+ * | supporter | Supporter | string | edge, opera, chrome, safari, firefox, iexplore |
887
+ * | supporterVs | Supporter version | string | - |
888
+ * | shell | Shell | string | (Optional) wechat, qq_browser, qq_app, uc, 360, 2345, sougou, liebao, maxthon, bilibili |
889
+ * | shellVs | Shell version | string | (Optional) 20/... |
890
+ * | appleType | Apple device type | string | (Optional) ipad, iphone, ipod, iwatch |
891
+ *
892
+ * Example: Determine the environment of the mobile QQ.
893
+ *
894
+ * ```
895
+ * const { system, shell } = getBrowserInfo();
896
+ * const isMobileQQ = ['android', 'ios'].includes(system) && ['qq_browser', 'qq_app'].includes(shell);
897
+ * ```
898
+ *
899
+ * @returns 浏览器信息
900
+ * @category Browser Information
901
+ */
902
+ export declare function getBrowserInfo(): BrowserInfo;
903
+ /**
904
+ * 去除 HTML 标签
905
+ *
906
+ * @param {string} str 带html标签的字符串
907
+ * @returns {string} 字符串
908
+ * @category Util
909
+ */
910
+ export declare function clearHtml(str: string, options?: {
911
+ removeNewLine?: boolean;
912
+ }): string;
913
+ /**
914
+ * Sanitizes user input to prevent XSS attacks
915
+ *
916
+ * @param input - The input string to sanitize
917
+ * @returns The sanitized input string
918
+ * @category Util
919
+ */
920
+ export declare function sanitizeInput(input: string): string;
921
+ /**
922
+ * Reverses the sanitization done by the `sanitizeInput` function.
923
+ *
924
+ * @param input - The input string to unsanitize
925
+ * @returns The unsanitized input string
926
+ * @category Util
927
+ */
928
+ export declare function unsanitize(input: string): string;
929
+ /**
930
+ * 截取字符串,中文算 2 个字节
931
+ *
932
+ * @param {string} str 要截取的字符串
933
+ * @param {number} len
934
+ * @param {boolean} hasDot
935
+ * @returns {string} 返回截取后的字符串
936
+ * @category Util
937
+ */
938
+ export declare function truncateZHString(str: string, len: number, hasDot?: boolean): string;
939
+ /**
940
+ * Alias of `truncateZHString`
941
+ *
942
+ * @hidden
943
+ */
944
+ export declare function cutCHSString(str: string, len: number, hasDot?: boolean): string;
945
+ /**
946
+ * EN: Check whether the page is loaded successfully (Keep the compatibility if the browser's `load` event has been triggered).
947
+ *
948
+ * ZH: 页面加载完成
949
+ *
950
+ * ```
951
+ * windowLoaded(30) // second
952
+ * .then(res => {
953
+ * console.log(`Load Success: ${res}`); // Load Success: load
954
+ * })
955
+ * .catch(err => {
956
+ * console.log(`Load Timeout or Fail: ${err.message}`);
957
+ * });
958
+ * ```
959
+ *
960
+ * @param {number} timeout 超时时间 / 单位:秒
961
+ * @returns {Promise<string>} document is loaded? 'complete' 'load' / 'timeout'
962
+ * @category Load Resource
963
+ */
964
+ export declare function windowLoaded(timeout?: number): Promise<string | Error>;
965
+ /**
966
+ * EN: Add `<style>` in `<head>`.
967
+ *
968
+ * ZH: 添加样式标签; style: 样式标签内的字符串; id: `<style>` 标签的 `id`; 返回: 添加成功/失败
969
+ *
970
+ * Example 1: Add the `<style>` with `id`, and repeated invoking will update the content instead of adding a new one.
971
+ *
972
+ * ```
973
+ * addStyle(
974
+ * `
975
+ * body {
976
+ * background-color: #333;
977
+ * }
978
+ * `,
979
+ * {
980
+ * id: 'test',
981
+ * }
982
+ * );
983
+ * // <style id="test">
984
+ * // body {
985
+ * // background-color: #333;
986
+ * // }
987
+ * // </style>
988
+ * ```
989
+ *
990
+ * Example 2: Add the `<style>` without `id`, and repeated invoking will add a new one.
991
+ *
992
+ * ```
993
+ * addStyle(
994
+ * `
995
+ * body {
996
+ * background-color: #444;
997
+ * }
998
+ * `
999
+ * );
1000
+ * // <style>
1001
+ * // body {
1002
+ * // background-color: #444;
1003
+ * // }
1004
+ * // </style>
1005
+ * ```
1006
+ *
1007
+ * @category DOM
1008
+ */
1009
+ export declare function addStyle(style: string, options?: {
1010
+ id?: string;
1011
+ }): boolean;
1012
+ /**
1013
+ * EN: Custom console printing (`console`).
1014
+ *
1015
+ * ZH: 生成自定义控制台打印
1016
+ *
1017
+ * Usage:
1018
+ *
1019
+ * ```
1020
+ * const myConsole = genCustomConsole('MazeyLog:');
1021
+ * myConsole.log('I am string.');
1022
+ * myConsole.info('I am boolean.', true);
1023
+ * myConsole.info('I am number.', 123, 456);
1024
+ * myConsole.info('I am object.', { a: 123, b: 456});
1025
+ * ```
1026
+ *
1027
+ * Output:
1028
+ *
1029
+ * ```
1030
+ * MazeyLog: I am string.
1031
+ * MazeyLog: I am boolean. true
1032
+ * MazeyLog: I am number. 123 456
1033
+ * MazeyLog: I am object. {a: 123, b: 456}
1034
+ * ```
1035
+ *
1036
+ * @param {string} prefix 前缀
1037
+ * @param {string} locales A locale string.
1038
+ * @param {function} logFn The function with Log.
1039
+ * @param {function} errorFn The function with Error.
1040
+ * @returns {object} 新实例
1041
+ * @category Debug
1042
+ */
1043
+ export declare function genCustomConsole(prefix?: string, options?: {
1044
+ isClosed?: boolean;
1045
+ showWrap?: boolean;
1046
+ showDate?: boolean;
1047
+ locales?: string;
1048
+ logFn?: () => void;
1049
+ errorFn?: () => void;
1050
+ }): Console;
1051
+ /**
1052
+ * Verify the validity of axios response.
1053
+ *
1054
+ * Reference: [Handling Errors](https://axios-http.com/docs/handling_errors)
1055
+ *
1056
+ * @category Util
1057
+ * @hidden
1058
+ */
1059
+ export declare function zAxiosIsValidRes(res: ZResResponse | undefined, options?: ZResIsValidResOptions): boolean;
1060
+ /**
1061
+ * Verify the validity of a non-empty array.
1062
+ *
1063
+ * @category Util
1064
+ */
1065
+ export declare function isNonEmptyArray<T>(arr: Array<T>): boolean;
1066
+ /**
1067
+ * Determine the validity of the data.
1068
+ *
1069
+ * Usage:
1070
+ *
1071
+ * ```
1072
+ * const validData = {
1073
+ * a: {
1074
+ * b: {
1075
+ * c: 413
1076
+ * }
1077
+ * }
1078
+ * };
1079
+ *
1080
+ * const isValidDataResA = isValidData(validData, ['a', 'b', 'c'], 2333);
1081
+ * const isValidDataResB = isValidData(validData, ['a', 'b', 'c'], 413);
1082
+ * const isValidDataResC = isValidData(validData, ['d', 'd'], 413);
1083
+ *
1084
+ * console.log('isValidDataResA:', isValidDataResA);
1085
+ * console.log('isValidDataResB:', isValidDataResB);
1086
+ * console.log('isValidDataResC:', isValidDataResC);
1087
+ * ```
1088
+ *
1089
+ * Output:
1090
+ *
1091
+ * ```
1092
+ * isValidDataResA: false
1093
+ * isValidDataResB: true
1094
+ * isValidDataResC: false
1095
+ * ```
1096
+ *
1097
+ * @param {any} data Original Data
1098
+ * @param {string[]} attributes Data Attributes
1099
+ * @param {any} validValue Given Value for verifying.
1100
+ * @returns {boolean} Return TRUE if the data is valid.
1101
+ * @category Util
1102
+ */
1103
+ export declare function isValidData(data: UnknownObject, attributes: string[], validValue: SimpleType): boolean;
1104
+ /**
1105
+ * 语义化文件大小, 把字节转换成正常文件大小.
1106
+ *
1107
+ * @category Util
1108
+ */
1109
+ export declare function getFileSize(size: number): string;
1110
+ /**
1111
+ * Detect webp support.
1112
+ *
1113
+ * Reference: [Detect WEBP Support with JavaScript](https://davidwalsh.name/detect-webp)
1114
+ *
1115
+ * @category Browser Information
1116
+ */
1117
+ export declare function isSupportWebp(): Promise<boolean>;
1118
+ /**
1119
+ * Generate a Hash Code from a string.
1120
+ *
1121
+ * Reference: [Generate a Hash from string in Javascript](https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery)
1122
+ *
1123
+ * @category Util
1124
+ */
1125
+ export declare function genHashCode(str: string): number;
1126
+ /**
1127
+ * Return the formatted date string in the given format.
1128
+ *
1129
+ * Usage:
1130
+ *
1131
+ * ```
1132
+ * console.log('Default formatDate value:', formatDate());
1133
+ * console.log('String formatDate value:', formatDate('Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)', 'yyyy-MM-dd hh:mm:ss'));
1134
+ * console.log('Number formatDate value:', formatDate(1641881235000, 'yyyy-MM-dd hh:mm:ss'));
1135
+ * console.log('Date formatDate value:', formatDate(new Date(2014, 1, 11), 'MM/dd/yyyy'));
1136
+ * ```
1137
+ *
1138
+ * Output:
1139
+ *
1140
+ * ```
1141
+ * Default formatDate value: 2023-01-11
1142
+ * String formatDate value: 2022-01-11 14:12:26
1143
+ * Number formatDate value: 2022-01-11 14:07:15
1144
+ * Date formatDate value: 02/11/2014
1145
+ * ```
1146
+ *
1147
+ * @param {Date|number|string} dateIns Original Date
1148
+ * @param {string} format Format String
1149
+ * @returns {string} Return the formatted date string.
1150
+ * @category Util
1151
+ */
1152
+ export declare function formatDate(dateIns?: Date | number | string, format?: string): string;
1153
+ /**
1154
+ * Get event container.
1155
+ *
1156
+ * @category Event
1157
+ * @hidden
1158
+ */
1159
+ export declare function getDefineListeners(): DefineListeners;
1160
+ /**
1161
+ * Add event.
1162
+ *
1163
+ * @param type
1164
+ * @param fn
1165
+ * @category Event
1166
+ */
1167
+ export declare function addEvent(type: string, fn: UnknownFn): void;
1168
+ /**
1169
+ * Invoke event.
1170
+ *
1171
+ * @param type
1172
+ * @category Event
1173
+ */
1174
+ export declare function invokeEvent(type: string): void;
1175
+ /**
1176
+ * Remove event.
1177
+ *
1178
+ * @param type
1179
+ * @param fn
1180
+ * @category Event
1181
+ */
1182
+ export declare function removeEvent(type: string, fn: UnknownFn): void;
1183
+ /**
1184
+ * Checks if the given string is a valid URL, including **scheme URLs**.
1185
+ *
1186
+ * @example
1187
+ * ```js
1188
+ * isValidUrl('https://www.example.com'); // true
1189
+ * isValidUrl('http://example.com/path/exx/ss'); // true
1190
+ * isValidUrl('https://www.example.com/?q=hello&age=24#world'); // true
1191
+ * isValidUrl('http://www.example.com/#world?id=9'); // true
1192
+ * isValidUrl('ftp://example.com'); // true
1193
+ * ```
1194
+ *
1195
+ * @remarks
1196
+ * If you are specifically checking for HTTP/HTTPS URLs, it is recommended to use the `isValidHttpUrl` function instead.
1197
+ * The `isValidUrl` function matches all scheme URLs, including FTP and other non-HTTP schemes.
1198
+ *
1199
+ * @param url - The URL to check.
1200
+ * @returns Returns `true` if the given string is a valid URL, else `false`.
1201
+ * @category URL
1202
+ */
1203
+ export declare function isValidUrl(url: string): boolean;
1204
+ /**
1205
+ * Check if the given string is a valid HTTP/HTTPS URL.
1206
+ *
1207
+ * @example
1208
+ * ```js
1209
+ * isValidHttpUrl('https://www.example.com'); // true
1210
+ * isValidHttpUrl('http://example.com/path/exx/ss'); // true
1211
+ * isValidHttpUrl('https://www.example.com/?q=hello&age=24#world'); // true
1212
+ * isValidHttpUrl('http://www.example.com/#world?id=9'); // true
1213
+ * isValidHttpUrl('ftp://example.com'); // false
1214
+ * ```
1215
+ *
1216
+ * @param url
1217
+ * @returns {boolean} Return true if the given string is a valid HTTP/HTTPS URL.
1218
+ * @category URL
1219
+ */
1220
+ export declare function isValidHttpUrl(url: string): boolean;
1221
+ /**
1222
+ * Check if the given string is a mobile phone number.
1223
+ *
1224
+ * @example
1225
+ * ```js
1226
+ * console.log(isMobile('13800138000')); // true
1227
+ * console.log(isMobile('1380013800')); // false
1228
+ * console.log(isMobile('138001380000')); // false
1229
+ * console.log(isMobile('1380013800a')); // false
1230
+ * ```
1231
+ *
1232
+ * @param mobile
1233
+ * @returns {boolean} Return true if the given string is a mobile phone number.
1234
+ * @category Util
1235
+ */
1236
+ export declare function isValidPhoneNumber(mobile: string): boolean;
1237
+ /**
1238
+ * Check if the given string is a valid email.
1239
+ *
1240
+ * @example
1241
+ * ```js
1242
+ * console.log(isValidEmail('mazeyqian@gmail.com')); // true
1243
+ * ```
1244
+ *
1245
+ * @param email
1246
+ * @returns {boolean} Return true if the given string is a valid email.
1247
+ * @category Util
1248
+ */
1249
+ export declare function isValidEmail(email: string): boolean;
1250
+ /**
1251
+ * Convert a given 10-hex number to a lowercase 26-hex string.
1252
+ *
1253
+ * @example
1254
+ * ```js
1255
+ * console.log(convert10To26(1)); // a
1256
+ * console.log(convert10To26(26)); // z
1257
+ * console.log(convert10To26(27)); // aa
1258
+ * console.log(convert10To26(52)); // az
1259
+ * console.log(convert10To26(53)); // ba
1260
+ * ```
1261
+ *
1262
+ * @param {number} num
1263
+ * @returns {string} Return a lowercase 26-hex string.
1264
+ * @category Util
1265
+ */
1266
+ export declare function convert10To26(num: number): string;
1267
+ /**
1268
+ * EN: Get the file type of the url.
1269
+ *
1270
+ * ZH: 获取文件后缀名
1271
+ *
1272
+ * @example
1273
+ * ```js
1274
+ * console.log(getUrlFileType('https://example.com/a/b/c.png')); // png
1275
+ * console.log(getUrlFileType('https://example.com/a/b/c.jpg')); // jpg
1276
+ * console.log(getUrlFileType('https://example.com/a/b/c.jpeg')); // jpeg
1277
+ * console.log(getUrlFileType('/a/b/c.jpeg')); // jpeg
1278
+ * console.log(getUrlFileType('https://example.com/a/b/c.v/a')); // ''
1279
+ * ```
1280
+ *
1281
+ * @param url
1282
+ * @returns
1283
+ * @category URL
1284
+ */
1285
+ export declare function getUrlFileType(url: string): boolean | string;
1286
+ /**
1287
+ * Sets the width and height of all images on the page based on their `src` attribute.
1288
+ * The `src` attribute should contain `width` and/or `height` values in the format "width=100" or "height=100".
1289
+ * If jQuery is available, this function uses jQuery to select the images. Otherwise, it uses pure JavaScript.
1290
+ *
1291
+ * @example
1292
+ * ```
1293
+ * // Example images with `src` attributes containing `width` and/or `height` values
1294
+ * const img1 = document.createElement('img');
1295
+ * img1.setAttribute('src', 'https://example.com/example.png?width=2233&height=111');
1296
+ * document.body.appendChild(img1);
1297
+ *
1298
+ * const img2 = document.createElement('img');
1299
+ * img2.setAttribute('src', 'https://example.com/example.png?width=100%&height=auto');
1300
+ * document.body.appendChild(img2);
1301
+ * ```
1302
+ *
1303
+ * @returns {boolean} - Returns `true` if images were found and their dimensions were set, otherwise `false`.
1304
+ * @category DOM
1305
+ */
1306
+ export declare function setImgWidHeiBySrc(): boolean;
1307
+ /**
1308
+ * Generate the inline style string from the given parameters. The first parameter is the query selector, and the second parameter is the style array.
1309
+ *
1310
+ * @example
1311
+ * ```js
1312
+ * console.log(genStyleString('.a', [ 'color:red' ])); // '.a{color:red;}'
1313
+ * console.log(genStyleString('#b', [ 'color:red', 'font-size:12px' ])); // '#b{color:red;font-size:12px;}'
1314
+ * ```
1315
+ *
1316
+ * @param {string} selector
1317
+ * @param {array} styleArray
1318
+ * @returns {string} The inline style string.
1319
+ * @category DOM
1320
+ */
1321
+ export declare function genStyleString(selector: string, styleArray: Array<string>): string;
1322
+ /**
1323
+ * Load an image from the given URL.
1324
+ *
1325
+ * The target image will be loaded in the background, and the Promise status will change after the image is loaded. If the image fails to load, the Promise status will change to `reject` with the error object. If the image is loaded successfully, the Promise status will change to `resolve` with the image object. This method can be used to preload images and cache them in the browser. It can also be used to implement lazy loading of images.
1326
+ *
1327
+ * Note that this method will not add the image to the DOM.
1328
+ *
1329
+ * @example
1330
+ * ```js
1331
+ * loadImage('https://example.com/example.png')
1332
+ * .then((img) => {
1333
+ * console.log(img);
1334
+ * })
1335
+ * .catch((err) => {
1336
+ * console.log(err);
1337
+ * });
1338
+ * ```
1339
+ *
1340
+ * @param {string} url - The URL of the image to load.
1341
+ * @returns {Promise} A Promise that resolves with the loaded image or rejects with an error.
1342
+ * @category Load Resource
1343
+ */
1344
+ export declare function loadImage(url: string): Promise<HTMLImageElement>;
1345
+ /**
1346
+ * Get the current version.
1347
+ *
1348
+ * @hidden
1349
+ */
1350
+ export declare function getCurrentVersion(): string;
1351
+ /**
1352
+ * Repeatedly fires a callback function with a certain interval until a specified condition is met.
1353
+ *
1354
+ * @param callback The callback function to fire.
1355
+ * @param options An object containing the options for the function.
1356
+ * @param options.interval The interval between each firing of the callback function, in milliseconds. Defaults to 1000.
1357
+ * @param options.times The maximum number of times to fire the callback function. Defaults to 10.
1358
+ * @param options.context The context to use when calling the callback function. Defaults to null.
1359
+ * @param options.args An array of arguments to pass to the callback function.
1360
+ * @param condition A function that takes the result of the callback function as its argument and returns a boolean value indicating whether the condition has been met. Defaults to a function that always returns true.
1361
+ * @category Util
1362
+ */
1363
+ export declare function repeatUntilConditionMet<T extends (...args: UnknownFnParams) => UnknownFnReturn>(callback: T, options?: RepeatUntilOptions, condition?: (result: ReturnType<T>) => boolean): void;
1364
+ /**
1365
+ * Load a script from the given URL if it (`window['attribute']`) has not already been loaded.
1366
+ *
1367
+ * @example
1368
+ * ```js
1369
+ * loadScriptIfUndefined('jQuery', 'https://example.com/lib/jquery.min.js')
1370
+ * .then(() => {
1371
+ * console.log('jQuery is loaded.');
1372
+ * })
1373
+ * .catch(err => {
1374
+ * console.log('Failed to load jQuery.', err);
1375
+ * });
1376
+ * ```
1377
+ *
1378
+ * @param {string} windowAttribute - The name of the window attribute to check (e.g. `jQuery`, `axios`, etc.).
1379
+ * @param {string} url - The URL of the script to load.
1380
+ * @returns {Promise} A Promise that resolves when the script has been loaded.
1381
+ * @category Load Resource
1382
+ */
1383
+ export declare function loadScriptIfUndefined(windowAttribute: string, url: string): LoadScriptReturns;
1384
+ /**
1385
+ * Retrieve a query parameter from a script URL in the browser.
1386
+ *
1387
+ * @param param - The name of the query parameter to retrieve.
1388
+ * @param matchString - An optional substring to match in the script URL.
1389
+ * If not provided, defaults to matching the ".js" substring.
1390
+ * @returns The decoded value of the specified query parameter, or an empty string if no matching parameter is found.
1391
+ * @category URL
1392
+ */
1393
+ export declare function getScriptQueryParam(param: string, matchString?: string): string;
1394
+ /**
1395
+ * Wait for a specified amount of time.
1396
+ *
1397
+ * @param time The amount of time to wait, in milliseconds.
1398
+ * @returns A Promise that resolves after the specified time has elapsed.
1399
+ * @category Util
1400
+ */
1401
+ export declare function waitTime(time: number): Promise<number>;
1402
+ export {};
1395
1403
  //# sourceMappingURL=index.d.ts.map