mazey 4.0.7 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -2,2044 +2,14 @@
2
2
  * @author Cheng
3
3
  */
4
4
  /// <reference types="global" />
5
- import { BrowserInfo, DefineListeners, ThrottleFunc, DebounceFunc, IsNumberOptions, AnyFunction, ZResResponse, ZResIsValidResOptions, RepeatUntilOptions, LoadScriptReturns, SimpleType, UnknownFnParams, UnknownFnReturn, UnknownObject, UnknownFn } from './typing';
6
- /**
7
- * EN: Computes the longest common substring of two strings.
8
- *
9
- * ZH: 计算两个字符串的最长公共子串
10
- *
11
- * Usage:
12
- *
13
- * ```javascript
14
- * const ret = longestComSubstring('fish', 'finish');
15
- * console.log(ret);
16
- * ```
17
- *
18
- * Output:
19
- *
20
- * ```text
21
- * 3
22
- * ```
23
- *
24
- * @param {string} aStr String
25
- * @param {string} bStr String
26
- * @returns {number} Length
27
- * @category Calculate and Formula
28
- */
29
- export declare function longestComSubstring(aStr: string, bStr: string): number;
30
- /**
31
- * Alias of `longestComSubstring`
32
- *
33
- * @hidden
34
- */
35
- export declare function calLongestCommonSubstring(aStr: string, bStr: string): number;
36
- /**
37
- * EN: Computes the longest common subsequence of two strings.
38
- *
39
- * ZH: 计算两个字符串的最长公共子序列
40
- *
41
- * Usage:
42
- *
43
- * ```javascript
44
- * const ret = longestComSubsequence('fish', 'finish');
45
- * console.log(ret);
46
- * ```
47
- *
48
- * Output:
49
- *
50
- * ```text
51
- * 4
52
- * ```
53
- *
54
- * @param {string} aStr 字符串
55
- * @param {string} bStr 字符串
56
- * @returns {number} 长度
57
- * @category Calculate and Formula
58
- */
59
- export declare function longestComSubsequence(aStr: string, bStr: string): number;
60
- /**
61
- * Alias of `longestComSubsequence`
62
- *
63
- * @hidden
64
- */
65
- export declare function calLongestCommonSubsequence(aStr: string, bStr: string): number;
66
- /**
67
- * Get the query param's value of the current Web URL(`location.search`).
68
- *
69
- * Usage:
70
- *
71
- * ```javascript
72
- * // http://example.com/?t1=1&t2=2&t3=3&t4=4#2333
73
- * // ?t1=1&t2=2&t3=3&t4=4
74
- * const p1 = getQueryParam('t3');
75
- * const p2 = getQueryParam('t4');
76
- * console.log(p1, p2);
77
- * ```
78
- *
79
- * Output:
80
- *
81
- * ```text
82
- * 3 4
83
- * ```
84
- *
85
- * @param {string} param Query param.
86
- * @returns {string} value
87
- * @category URL
88
- */
89
- export declare function getQueryParam(param: string): string;
90
- /**
91
- * Returns the value of the specified query parameter in the input URL.
92
- *
93
- * Usage:
94
- *
95
- * ```javascript
96
- * const p1 = getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3');
97
- * const p2 = getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4');
98
- * console.log(p1, p2);
99
- * ```
100
- *
101
- * Output:
102
- *
103
- * ```text
104
- * 3 4
105
- * ```
106
- *
107
- * @param {string} url The URL string.
108
- * @param {string} param The query parameter to retrieve the value for.
109
- * @param {object} options The options object.
110
- * @param {boolean} options.returnArray Whether to return an array of values for the specified query parameter. Default is false.
111
- * @returns {string|string[]} The value of the specified query parameter, or an empty string if the parameter is not found.
112
- * @category URL
113
- */
114
- export declare function getUrlParam(url: string, param: string, options?: {
115
- returnArray?: boolean;
116
- }): string | string[] | null;
117
- /**
118
- * Update the query param's value of the input URL.
119
- *
120
- * Usage:
121
- *
122
- * ```javascript
123
- * const ret1 = updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3', 'three');
124
- * const ret2 = updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four');
125
- * console.log(ret1);
126
- * console.log(ret2);
127
- * ```
128
- *
129
- * Output:
130
- *
131
- * ```text
132
- * http://example.com/?t1=1&t2=2&t3=three&t4=4
133
- * http://example.com/?t1=1&t2=2&t3=3&t4=four
134
- * ```
135
- *
136
- * @param {string} url URL string.
137
- * @param {string} param Query param.
138
- * @param {string} value Param's value.
139
- * @returns {string} URL.
140
- * @category URL
141
- */
142
- export declare function updateQueryParam(url: string, param: string, value: string): string;
143
- /**
144
- * Get the hash query param's value of the current Web URL(`location.hash`).
145
- *
146
- * Usage:
147
- *
148
- * ```javascript
149
- * // http://example.com/?#2333?t1=1&t2=2&t3=3&t4=4
150
- * // #2333?t1=1&t2=2&t3=3&t4=4
151
- * const p1 = getHashQueryParam('t3');
152
- * const p2 = getHashQueryParam('t4');
153
- * console.log(p1, p2);
154
- * ```
155
- *
156
- * Output:
157
- *
158
- * ```text
159
- * 3 4
160
- * ```
161
- *
162
- * @param {string} param Query param.
163
- * @returns {string} value
164
- * @category URL
165
- */
166
- export declare function getHashQueryParam(param: string): string;
167
- /**
168
- * Get the domain of URL, and other params.
169
- *
170
- * Usage:
171
- *
172
- * ```javascript
173
- * const ret1 = getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4');
174
- * const ret2 = getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']);
175
- * const ret3 = getDomain('http://example.com:7890/test/thanks', ['hostname']);
176
- * const ret4 = getDomain('http://example.com:7890/test/thanks', ['host']); // With Port
177
- * const ret5 = getDomain('http://example.com:7890/test/thanks', ['origin']);
178
- * const ret6 = getDomain('http://example.com:7890/test/thanks?id=1', ['origin', 'pathname', 'search']);
179
- * console.log(ret1);
180
- * console.log(ret2);
181
- * console.log(ret3);
182
- * console.log(ret4);
183
- * console.log(ret5);
184
- * console.log(ret6);
185
- * ```
186
- *
187
- * Output:
188
- *
189
- * ```text
190
- * example.com
191
- * example.com/test/thanks
192
- * example.com
193
- * example.com:7890
194
- * http://example.com:7890
195
- * http://example.com:7890/test/thanks?id=1
196
- * ```
197
- *
198
- * @param {string} url
199
- * @param {array} rules Object.keys(location), ['href', 'origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
200
- * @category URL
201
- */
202
- export declare function getDomain(url: string, rules?: string[]): string;
203
- /**
204
- * Transfer CamelCase to KebabCase.
205
- *
206
- * Usage:
207
- *
208
- * ```javascript
209
- * const ret1 = convertCamelToKebab('ABC');
210
- * const ret2 = convertCamelToKebab('aBC');
211
- * console.log(ret1);
212
- * console.log(ret2);
213
- * ```
214
- *
215
- * Output:
216
- *
217
- * ```text
218
- * a-b-c
219
- * a-b-c
220
- * ```
221
- *
222
- * @param {string} camelCase 'aBC' or 'ABC'
223
- * @returns {string} 'a-b-c'
224
- * @category Util
225
- */
226
- export declare function convertCamelToKebab(camelCase: string): string;
227
- /**
228
- * Alias of `convertCamelToKebab`
229
- *
230
- * @hidden
231
- */
232
- export declare function camelCaseToKebabCase(camelCase: string): string;
233
- /**
234
- * Transfer CamelCase to Underscore.
235
- *
236
- * Usage:
237
- *
238
- * ```javascript
239
- * const ret1 = convertCamelToUnder('ABC');
240
- * const ret2 = convertCamelToUnder('aBC');
241
- * console.log(ret1);
242
- * console.log(ret2);
243
- * ```
244
- *
245
- * Output:
246
- *
247
- * ```text
248
- * a_b_c
249
- * a_b_c
250
- * ```
251
- *
252
- * @param {string} camelCase 'aBC' or 'ABC'
253
- * @returns {string} 'a_b_c'
254
- * @category Util
255
- */
256
- export declare function convertCamelToUnder(camelCase: string): string;
257
- /**
258
- * Alias of `convertCamelToUnder`
259
- *
260
- * @hidden
261
- */
262
- export declare function camelCase2Underscore(camelCase: string): string;
263
- /**
264
- * Remove leading and trailing whitespace or specified characters from string.
265
- *
266
- * Note: This method is used to replace the native `String.prototype.trim()`. But it is not necessary to use it in modern browsers.
267
- *
268
- * Usage:
269
- *
270
- * ```javascript
271
- * const ret1 = mTrim(' 1 2 3 ');
272
- * const ret2 = mTrim('abc ');
273
- * console.log(ret1);
274
- * console.log(ret2);
275
- * ```
276
- *
277
- * Output:
278
- *
279
- * ```text
280
- * 1 2 3
281
- * abc
282
- * ```
283
- *
284
- * @param {string} str The string to trim.
285
- * @returns {string} Trimmed string.
286
- * @category Util
287
- * @hidden
288
- */
289
- export declare function mTrim(str: string): string;
290
- /**
291
- * Make a new line of HTML.
292
- *
293
- * Usage:
294
- *
295
- * ```javascript
296
- * const ret1 = newLine('a\nb\nc');
297
- * const ret2 = newLine('a\n\nbc');
298
- * console.log(ret1);
299
- * console.log(ret2);
300
- * ```
301
- *
302
- * Output:
303
- *
304
- * ```text
305
- * a<br />b<br />c
306
- * a<br /><br />bc
307
- * ```
308
- *
309
- * @param {string} str The string to make a new line.
310
- * @returns {string} A newline with `br`.
311
- * @category DOM
312
- */
313
- export declare function newLine(str: string): string;
314
- /**
315
- * Copy/Clone Object deeply.
316
- *
317
- * Usage:
318
- *
319
- * ```javascript
320
- * const ret1 = deepCopy(['a', 'b', 'c']);
321
- * const ret2 = deepCopy('abc');
322
- * console.log(ret1);
323
- * console.log(ret2);
324
- * ```
325
- *
326
- * Output:
327
- *
328
- * ```text
329
- * ['a', 'b', 'c']
330
- * abc
331
- * ```
332
- *
333
- * @param {object} obj The value to clone.
334
- * @returns {object} Returns the deep cloned value.
335
- * @category Util
336
- */
337
- export declare function deepCopy<T>(obj: T): T;
338
- /**
339
- * Alias of `deepCopy`
340
- *
341
- * @hidden
342
- */
343
- export declare function deepCopyObject<T>(obj: T): T;
344
- /**
345
- * Check whether it is a valid JSON string.
346
- *
347
- * Usage:
348
- *
349
- * ```javascript
350
- * const ret1 = isJSONString(`['a', 'b', 'c']`);
351
- * const ret2 = isJSONString(`["a", "b", "c"]`);
352
- * console.log(ret1);
353
- * console.log(ret2);
354
- * ```
355
- *
356
- * Output:
357
- *
358
- * ```text
359
- * false
360
- * true
361
- * ```
362
- *
363
- * @param {string} str The string to check.
364
- * @returns {boolean} Return the result of checking.
365
- * @category Util
366
- */
367
- export declare function isJSONString(str: string): boolean;
368
- /**
369
- * Alias of `isJSONString`
370
- *
371
- * @hidden
372
- */
373
- export declare function isJsonString(str: string): boolean;
374
- /**
375
- * Produce a random string of number, `genRndNumString(7)` => '7658495'.
376
- *
377
- * Usage:
378
- *
379
- * ```javascript
380
- * const ret1 = genRndNumString(4);
381
- * const ret2 = genRndNumString(7);
382
- * console.log(ret1);
383
- * console.log(ret2);
384
- * ```
385
- *
386
- * Output:
387
- *
388
- * ```text
389
- * 9730
390
- * 2262490
391
- * ```
392
- *
393
- * @param {number} n Length
394
- * @returns {string} Return the random string.
395
- * @category Util
396
- */
397
- export declare function genRndNumString(n?: number): string;
398
- /**
399
- * Alias of `genRndNumString`
400
- *
401
- * @hidden
402
- */
403
- export declare function generateRndNum(n?: number): string;
404
- /**
405
- * 根据时间生成唯一标志的数字 `genUniqueNumString()` => `1538324722364123`
406
- *
407
- * Usage:
408
- *
409
- * ```javascript
410
- * const ret1 = genUniqueNumString();
411
- * const ret2 = genUniqueNumString(3);
412
- * console.log(ret1);
413
- * console.log(ret2);
414
- * ```
415
- *
416
- * Output:
417
- *
418
- * ```text
419
- * 1538324722364123
420
- * 1538324722364123
421
- * ```
422
- *
423
- * @param {number} n 随机数的长度
424
- * @category Util
425
- */
426
- export declare function genUniqueNumString(n?: number): string;
427
- /**
428
- * Alias of `genUniqueNumString`
429
- *
430
- * @hidden
431
- */
432
- export declare function generateUniqueNum(n?: number): string;
433
- /**
434
- * 浮点数转为百分比 0.2 => 20%
435
- *
436
- * Usage:
437
- *
438
- * ```javascript
439
- * const ret1 = floatToPercent(0.2);
440
- * const ret2 = floatToPercent(0.2, 2);
441
- * console.log(ret1);
442
- * console.log(ret2);
443
- * ```
444
- *
445
- * Output:
446
- *
447
- * ```text
448
- * 20%
449
- * 20.00%
450
- * ```
451
- *
452
- * @param {number} num 浮点数
453
- * @param {number} fixSize 保留几位浮点数
454
- * @category Util
455
- */
456
- export declare function floatToPercent(num: number, fixSize?: number): string;
457
- /**
458
- * 浮点数保留指定位
459
- *
460
- * Usage:
461
- *
462
- * ```javascript
463
- * const ret1 = floatFixed(0.2);
464
- * const ret2 = floatFixed(0.2, 2);
465
- * console.log(ret1);
466
- * console.log(ret2);
467
- * ```
468
- *
469
- * Output:
470
- *
471
- * ```text
472
- * 0
473
- * 0.20
474
- * ```
475
- *
476
- * @category Util
477
- */
478
- export declare function floatFixed(num: string, size?: number): string;
479
- /**
480
- * 阻止冒泡
481
- *
482
- * Usage:
483
- *
484
- * ```javascript
485
- * const ret1 = cancelBubble(e);
486
- * ```
487
- *
488
- * @category Event
489
- */
490
- export declare function cancelBubble(e: Event): void;
491
- /**
492
- * Modify `class`.
493
- *
494
- * Usage:
495
- *
496
- * ```javascript
497
- * const dom = document.querySelector('#box');
498
- *
499
- * // Determine `class`
500
- * hasClass(dom, 'test');
501
- * // Add `class`
502
- * addClass(dom, 'test');
503
- * // Remove `class`
504
- * removeClass(dom, 'test');
505
- * ```
506
- *
507
- * @category DOM
508
- */
509
- export declare function hasClass(obj: HTMLElement, cls: string): boolean;
510
- /**
511
- * Modify `class`.
512
- *
513
- * Usage:
514
- *
515
- * ```javascript
516
- * const dom = document.querySelector('#box');
517
- *
518
- * // Determine `class`
519
- * hasClass(dom, 'test');
520
- * // Add `class`
521
- * addClass(dom, 'test');
522
- * // Remove `class`
523
- * removeClass(dom, 'test');
524
- * ```
525
- *
526
- * @category DOM
527
- */
528
- export declare function addClass(obj: HTMLElement, cls: string): void;
529
- /**
530
- * Modify `class`.
531
- *
532
- * Usage:
533
- *
534
- * ```javascript
535
- * const dom = document.querySelector('#box');
536
- *
537
- * // Determine `class`
538
- * hasClass(dom, 'test');
539
- * // Add `class`
540
- * addClass(dom, 'test');
541
- * // Remove `class`
542
- * removeClass(dom, 'test');
543
- * ```
544
- *
545
- * @category DOM
546
- */
547
- export declare function removeClass(obj: HTMLElement, cls: string): void;
548
- /**
549
- * EN: Throttle
550
- *
551
- * ZH: 节流
552
- *
553
- * Usage:
554
- *
555
- * ```javascript
556
- * const foo = throttle(() => {
557
- * console.log('The function will be invoked at most once per every wait 1000 milliseconds.');
558
- * }, 1000, { leading: true });
559
- * ```
560
- *
561
- * Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
562
- *
563
- * @category Util
564
- */
565
- export declare function throttle<T extends (...args: UnknownFnParams) => UnknownFnReturn>(func: T, wait: number, options?: {
566
- leading?: boolean;
567
- trailing?: boolean;
568
- }): ThrottleFunc<T>;
569
- /**
570
- * EN: Debounce
571
- *
572
- * ZH: 去抖
573
- *
574
- * Usage:
575
- *
576
- * ```javascript
577
- * const foo = debounce(() => {
578
- * console.log('The debounced function will only be invoked in 1000 milliseconds, the other invoking will disappear during the wait time.');
579
- * }, 1000, true);
580
- * ```
581
- *
582
- * @category Util
583
- */
584
- export declare function debounce<T extends (...args: UnknownFnParams) => UnknownFnReturn>(func: T, wait: number, immediate?: boolean): DebounceFunc<T>;
585
- /**
586
- * 获取间隔时间
587
- *
588
- * Usage:
589
- *
590
- * ```javascript
591
- * const ret1 = getFriendlyInterval(new Date('2020-03-28 00:09:27'), new Date('2023-04-18 10:54:00'), { type: 'd' });
592
- * const ret2 = getFriendlyInterval(1585325367000, 1681786440000, { type: 'text' });
593
- * const ret3 = getFriendlyInterval('2020-03-28 00:09:27', '2023-04-18 10:54:00', { type: 'text' });
594
- * console.log(ret1);
595
- * console.log(ret2);
596
- * console.log(ret3);
597
- * ```
598
- *
599
- * Output:
600
- *
601
- * ```text
602
- * 1116
603
- * 1116 天 10 时 44 分 33 秒
604
- * 1116 天 10 时 44 分 33 秒
605
- * ```
606
- *
607
- * @param {number/Date} start 开始时间戳 1585325367122
608
- * @param {number/Date} end 结束时间戳 1585325367122
609
- * @param {string} options.type 返回类型 d: 2(天) text: 2 天 4 时...
610
- * @returns {string/number} 取决于 type
611
- * @category Util
612
- */
613
- export declare function getFriendlyInterval(start?: number | string | Date, end?: number | string | Date, options?: {
614
- type?: string;
615
- }): number | string;
616
- /**
617
- * EN: Check whether it is a right number.
618
- *
619
- * ZH: 判断是否有效数字
620
- *
621
- * Usage:
622
- *
623
- * ```javascript
624
- * const ret1 = isNumber(123);
625
- * const ret2 = isNumber('123');
626
- * // Default: NaN, Infinity is not Number
627
- * const ret3 = isNumber(Infinity);
628
- * const ret4 = isNumber(Infinity, { isInfinityAsNumber: true });
629
- * const ret5 = isNumber(NaN);
630
- * const ret6 = isNumber(NaN, { isNaNAsNumber: true, isInfinityAsNumber: true });
631
- * console.log(ret1, ret2, ret3, ret4, ret5, ret6);
632
- * ```
633
- *
634
- * Output:
635
- *
636
- * ```text
637
- * true false false true false true
638
- * ```
639
- *
640
- * @param {*} num 被判断的值
641
- * @param {boolean} options.isNaNAsNumber 是否 NaN 算数字(默认不算)
642
- * @param {boolean} options.isInfinityAsNumber 是否 无限 算数字(默认不算)
643
- * @returns {boolean} true 是数字
644
- * @category Util
645
- */
646
- export declare function isNumber(num: unknown, options?: IsNumberOptions): boolean;
647
- /**
648
- * 执行有效函数
649
- *
650
- * Usage:
651
- *
652
- * ```javascript
653
- * const ret = doFn(() => {
654
- * console.log('doFn');
655
- * });
656
- * ```
657
- *
658
- * @param {function} fn 等待被执行的未知是否有效的函数
659
- * @category Util
660
- */
661
- export declare function doFn(fn: AnyFunction, ...params: Parameters<AnyFunction>): ReturnType<AnyFunction> | null;
662
- /**
663
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
664
- *
665
- * ZH: 存储/获取数据到 sessionStorage/localStorage
666
- *
667
- * Usage:
668
- *
669
- * ```javascript
670
- * setSessionStorage('test', '123');
671
- * const ret1 = getSessionStorage('test');
672
- * setLocalStorage('test', '123');
673
- * const ret2 = getLocalStorage('test');
674
- * console.log(ret1, ret2);
675
- *
676
- * // or package in usage
677
- * const projectName = 'mazey';
678
- * function mSetLocalStorage (key, value) {
679
- * return setLocalStorage(`${projectName}_${key}`, value);
680
- * }
681
- *
682
- * function mGetLocalStorage (key) {
683
- * return getLocalStorage(`${projectName}_${key}`);
684
- * }
685
- * ```
686
- *
687
- * Output:
688
- *
689
- * ```text
690
- * 123 123
691
- * ```
692
- *
693
- * @param {string} key 键
694
- * @returns {void} 返回值
695
- * @category Cache Data
696
- */
697
- export declare function setSessionStorage<T>(key: string, value?: T | null): void;
698
- /**
699
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
700
- *
701
- * ZH: 存储/获取数据到 sessionStorage/localStorage
702
- *
703
- * Usage:
704
- *
705
- * ```javascript
706
- * setSessionStorage('test', '123');
707
- * const ret1 = getSessionStorage('test');
708
- * setLocalStorage('test', '123');
709
- * const ret2 = getLocalStorage('test');
710
- * console.log(ret1, ret2);
711
- *
712
- * // or package in usage
713
- * const projectName = 'mazey';
714
- * function mSetLocalStorage (key, value) {
715
- * return setLocalStorage(`${projectName}_${key}`, value);
716
- * }
717
- *
718
- * function mGetLocalStorage (key) {
719
- * return getLocalStorage(`${projectName}_${key}`);
720
- * }
721
- * ```
722
- *
723
- * Output:
724
- *
725
- * ```text
726
- * 123 123
727
- * ```
728
- *
729
- * @param {string} key 键
730
- * @returns {any} 返回值
731
- * @category Cache Data
732
- */
733
- export declare function getSessionStorage<T>(key: string): T | null;
734
- /**
735
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
736
- *
737
- * ZH: 存储/获取数据到 sessionStorage/localStorage
738
- *
739
- * Usage:
740
- *
741
- * ```javascript
742
- * setSessionStorage('test', '123');
743
- * const ret1 = getSessionStorage('test');
744
- * setLocalStorage('test', '123');
745
- * const ret2 = getLocalStorage('test');
746
- * console.log(ret1, ret2);
747
- *
748
- * // or package in usage
749
- * const projectName = 'mazey';
750
- * function mSetLocalStorage (key, value) {
751
- * return setLocalStorage(`${projectName}_${key}`, value);
752
- * }
753
- *
754
- * function mGetLocalStorage (key) {
755
- * return getLocalStorage(`${projectName}_${key}`);
756
- * }
757
- * ```
758
- *
759
- * Output:
760
- *
761
- * ```text
762
- * 123 123
763
- * ```
764
- *
765
- * @param {string} key 键
766
- * @returns {void} 返回值
767
- * @category Cache Data
768
- */
769
- export declare function setLocalStorage<T>(key: string, value?: T | null): void;
770
- /**
771
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
772
- *
773
- * ZH: 存储/获取数据到 sessionStorage/localStorage
774
- *
775
- * Usage:
776
- *
777
- * ```javascript
778
- * setSessionStorage('test', '123');
779
- * const ret1 = getSessionStorage('test');
780
- * setLocalStorage('test', '123');
781
- * const ret2 = getLocalStorage('test');
782
- * console.log(ret1, ret2);
783
- *
784
- * // or package in usage
785
- * const projectName = 'mazey';
786
- * function mSetLocalStorage (key, value) {
787
- * return setLocalStorage(`${projectName}_${key}`, value);
788
- * }
789
- *
790
- * function mGetLocalStorage (key) {
791
- * return getLocalStorage(`${projectName}_${key}`);
792
- * }
793
- * ```
794
- *
795
- * Output:
796
- *
797
- * ```text
798
- * 123 123
799
- * ```
800
- *
801
- * @param {string} key 键
802
- * @returns {void} 返回值
803
- * @category Cache Data
804
- */
805
- export declare function getLocalStorage<T>(key: string): T | null;
806
- /**
807
- * EN: Load a CSS file from the server.
808
- *
809
- * ZH: 动态加载 CSS 文件
810
- *
811
- * Usage:
812
- *
813
- * ```javascript
814
- * loadCSS(
815
- * 'http://example.com/path/example.css',
816
- * {
817
- * id: 'iamid', // Optional, link ID, default none
818
- * }
819
- * )
820
- * .then(
821
- * res => {
822
- * console.log(`Load CSS Success: ${res}`);
823
- * }
824
- * )
825
- * .catch(
826
- * err => {
827
- * console.error(`Load CSS Fail: ${err.message}`)
828
- * }
829
- * );
830
- * ```
831
- *
832
- * Output:
833
- *
834
- * ```text
835
- * Load CSS Success: loaded
836
- * ```
837
- *
838
- * @param {string} url -- css资源路径
839
- * @param {string} options.id -- link标签id
840
- * @returns {Promise<string>} true -- 加载成功
841
- * @category Load Resource
842
- */
843
- export declare function loadCSS(url: string, options?: {
844
- id?: string;
845
- }): Promise<unknown>;
846
- /**
847
- * EN: Load a JavaScript file from the server and execute it.
848
- *
849
- * ZH: 动态加载 JavaScript 文件
850
- *
851
- * Usage:
852
- *
853
- * ```javascript
854
- * loadScript(
855
- * 'http://example.com/static/js/plugin-2.1.1.min.js',
856
- * {
857
- * id: 'iamid', // (Optional) script ID, default none
858
- * timeout: 5000, // (Optional) timeout, default `5000`
859
- * isDefer: false, // (Optional) defer, default `false`
860
- * }
861
- * )
862
- * .then(
863
- * res => {
864
- * console.log(`Load JavaScript script: ${res}`);
865
- * }
866
- * )
867
- * .catch(
868
- * err => {
869
- * console.error(`Load JavaScript script: ${err.message}`)
870
- * }
871
- * );
872
- * ```
873
- *
874
- * Output:
875
- *
876
- * ```text
877
- * Load JavaScript script: loaded
878
- * ```
879
- *
880
- * @param {string} url -- JavaScript 资源路径
881
- * @param {string} options.id -- DOM ID
882
- * @param {function} options.callback -- 加载后回调函数
883
- * @param {number} options.timeout -- 超时时长
884
- * @param {boolean} options.isDefer -- 是否添加 defer 标签
885
- * @returns {Promise<string>} -- true 成功
886
- * @category Load Resource
887
- */
888
- export declare function loadScript(url: string, options?: {
889
- id?: string;
890
- callback?: (...params: UnknownFnParams) => UnknownFnReturn;
891
- timeout?: number;
892
- isDefer?: boolean;
893
- }): LoadScriptReturns;
894
- /**
895
- * 获取时间戳
896
- *
897
- * Usage:
898
- *
899
- * ```javascript
900
- * const ret = mNow();
901
- * console.log(ret);
902
- * ```
903
- *
904
- * Output:
905
- *
906
- * ```text
907
- * 1585325367122
908
- * ```
909
- *
910
- * @category Util
911
- */
912
- export declare function mNow(): number;
913
- /**
914
- * EN: Handle Cookie.
915
- *
916
- * ZH: 设置/获取 Cookie
917
- *
918
- * Usage:
919
- *
920
- * ```javascript
921
- * setCookie('test', '123', 30, 'example.com'); // key value day domain
922
- * const ret = getCookie('test');
923
- * console.log(ret);
924
- * ```
925
- *
926
- * Output:
927
- *
928
- * ```text
929
- * 123
930
- * ```
931
- *
932
- * @category Cache Data
933
- */
934
- export declare function setCookie(name: string, value: string, days?: number, domain?: string): void;
935
- /**
936
- * EN: Handle Cookie.
937
- *
938
- * ZH: 设置/获取 Cookie
939
- *
940
- * Usage:
941
- *
942
- * ```javascript
943
- * setCookie('test', '123', 30, 'example.com'); // key value day domain
944
- * const ret = getCookie('test');
945
- * console.log(ret);
946
- * ```
947
- *
948
- * Output:
949
- *
950
- * ```text
951
- * 123
952
- * ```
953
- *
954
- * @category Cache Data
955
- */
956
- export declare function getCookie(name: string): string;
957
- /**
958
- * Delete a cookie by name.
959
- *
960
- * Usage:
961
- *
962
- * ```javascript
963
- * const ret = delCookie('test');
964
- * console.log(ret);
965
- * ```
966
- *
967
- * Output:
968
- *
969
- * ```text
970
- * true
971
- * ```
972
- *
973
- * @param name - The name of the cookie to delete.
974
- * @returns `true` if the cookie was deleted successfully, `false` otherwise.
975
- * @category Cache Data
976
- */
977
- export declare function delCookie(name: string): boolean;
978
- /**
979
- * @hidden
980
- */
981
- interface WebPerformance {
982
- [key: string]: string | number;
983
- }
984
- /**
985
- * Gets the first contentful paint (FCP) time of a web page using the Performance API.
986
- * The FCP time is the time it takes for the first piece of content to be painted on the screen.
987
- *
988
- * Usage:
989
- *
990
- * ```javascript
991
- * getFCP().then(
992
- * res => {
993
- * console.log(`FCP: ${res}`);
994
- * }
995
- * );
996
- * ```
997
- *
998
- * Output:
999
- *
1000
- * ```text
1001
- * FCP: 123
1002
- * ```
1003
- *
1004
- * @returns A promise that resolves with the FCP time in milliseconds, or 0 if the 'paint' entry type is not supported.
1005
- * @category Web Performance
1006
- */
1007
- export declare function getFCP(): Promise<number>;
1008
- /**
1009
- * Gets the first paint (FP) time of a web page using the Performance API.
1010
- * The FP time is the time it takes for the first pixel to be painted on the screen.
1011
- *
1012
- * Usage:
1013
- *
1014
- * ```javascript
1015
- * getFP().then(
1016
- * res => {
1017
- * console.log(`FP: ${res}`);
1018
- * }
1019
- * );
1020
- * ```
1021
- *
1022
- * Output:
1023
- *
1024
- * ```text
1025
- * FP: 123
1026
- * ```
1027
- *
1028
- * @returns A promise that resolves with the FP time in milliseconds, or 0 if the 'paint' entry type is not supported.
1029
- * @category Web Performance
1030
- */
1031
- export declare function getFP(): Promise<number>;
1032
- /**
1033
- * Gets the largest contentful paint (LCP) time of a web page using the Performance API.
1034
- * The LCP time is the time it takes for the largest piece of content to be painted on the screen.
1035
- *
1036
- * Usage:
1037
- *
1038
- * ```javascript
1039
- * getLCP().then(
1040
- * res => {
1041
- * console.log(`LCP: ${res}`);
1042
- * }
1043
- * );
1044
- * ```
1045
- *
1046
- * Output:
1047
- *
1048
- * ```text
1049
- * LCP: 123
1050
- * ```
1051
- *
1052
- * @returns A promise that resolves with the LCP time in milliseconds, or 0 if the 'largest-contentful-paint' entry type is not supported.
1053
- * @category Web Performance
1054
- */
1055
- export declare function getLCP(): Promise<number>;
1056
- /**
1057
- * Gets the first input delay (FID) of a web page using the Performance API.
1058
- * The FID is the time it takes for the first user input to be processed by the browser.
1059
- *
1060
- * Usage:
1061
- *
1062
- * ```javascript
1063
- * getFID().then(
1064
- * res => {
1065
- * console.log(`FID: ${res}`);
1066
- * }
1067
- * );
1068
- * ```
1069
- *
1070
- * Output:
1071
- *
1072
- * ```text
1073
- * FID: 123
1074
- * ```
1075
- *
1076
- * @returns A promise that resolves with the FID in milliseconds, or 0 if the 'first-input' entry type is not supported.
1077
- * @category Web Performance
1078
- */
1079
- export declare function getFID(): Promise<number>;
1080
- /**
1081
- * Gets the Cumulative Layout Shift (CLS) score of a web page using the Performance API.
1082
- * The CLS score is a measure of how much the page layout shifts during loading.
1083
- *
1084
- * Usage:
1085
- *
1086
- * ```javascript
1087
- * getCLS().then(
1088
- * res => {
1089
- * console.log(`CLS: ${res}`);
1090
- * }
1091
- * );
1092
- * ```
1093
- *
1094
- * Output:
1095
- *
1096
- * ```text
1097
- * CLS: 123
1098
- * ```
1099
- *
1100
- * @returns A promise that resolves with the CLS score, or 0 if the 'layout-shift' entry type is not supported.
1101
- * @category Web Performance
1102
- */
1103
- export declare function getCLS(): Promise<number>;
1104
- /**
1105
- * Gets the time to first byte (TTFB) of a web page using the Performance API.
1106
- * The TTFB is the time it takes for the first byte of the response to be received by the browser.
1107
- *
1108
- * Usage:
1109
- *
1110
- * ```javascript
1111
- * getTTFB().then(
1112
- * res => {
1113
- * console.log(`TTFB: ${res}`);
1114
- * }
1115
- * );
1116
- * ```
1117
- *
1118
- * Output:
1119
- *
1120
- * ```text
1121
- * TTFB: 123
1122
- * ```
1123
- *
1124
- * @returns The TTFB in milliseconds, or 0 if the navigation timing information is not available.
1125
- * @category Web Performance
1126
- */
1127
- export declare function getTTFB(): Promise<number>;
1128
- /**
1129
- * EN: Get page load time(`PerformanceNavigationTiming`).
1130
- *
1131
- * ZH: 获取页面加载相关的各项数据
1132
- *
1133
- * @remarks
1134
- * This function uses the [`PerformanceNavigationTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming) API to get page load time data.
1135
- * 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.
1136
- * 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://github.com/mazeyqian/mazey/releases/tag/v3.9.7)).
1137
- *
1138
- * Usage:
1139
- *
1140
- * ```javascript
1141
- * // `camelCase:false` (Default) Return underline(`a_b`) data.
1142
- * // `camelCase:true` Return hump(`aB`) data.
1143
- * getPerformance()
1144
- * .then(res => {
1145
- * console.log(JSON.stringify(res));
1146
- * })
1147
- * .catch(console.error);
1148
- * ```
1149
- *
1150
- * Output:
1151
- *
1152
- * ```text
1153
- * {"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}
1154
- * ```
1155
- *
1156
- * Results:
1157
- *
1158
- * | Attribute | Description | Type | Values |
1159
- * | :------------ | :------------ | :------------ | :------------ |
1160
- * | dns_time | DNS Lookup | number | domainLookupEnd - domainLookupStart |
1161
- * | tcp_time | Connection Negotiation | number | connectEnd - connectStart |
1162
- * | response_time | Requests and Responses | number | responseStart - requestStart |
1163
- * | white_time | White Screen | number | responseStart - navigationStart |
1164
- * | dom_ready_time | Dom Ready | number | domContentLoadedEventStart - navigationStart |
1165
- * | onload_time | Onload | number | loadEventStart - navigationStart |
1166
- * | render_time | EventEnd | number | loadEventEnd -navigationStart |
1167
- * | unload_time | Unload | number | (Optional) unloadEventEnd - unloadEventStart |
1168
- * | redirect_time | Redirect | number | (Optional) redirectEnd - redirectStart |
1169
- * | ssl_time | SSL | number | (Optional) connectEnd - secureConnectionStart |
1170
- * | download_time | Download | number | (Optional) responseEnd - responseStart |
1171
- *
1172
- * @param {boolean} camelCase -- false(默认) 以下划线形式返回数据 true 以驼峰形式返回数据
1173
- * @returns {Promise<object>} 加载数据
1174
- * @category Web Performance
1175
- */
1176
- export declare function getPerformance(camelCase?: boolean): Promise<WebPerformance | Error>;
1177
- /**
1178
- * EN: Hit probability (1% ~ 100%).
1179
- *
1180
- * ZH: 百分位概率
1181
- *
1182
- * Usage:
1183
- *
1184
- * ```javascript
1185
- * const ret = inRate(0.5); // 0.01 ~ 1 true/false
1186
- * console.log(ret);
1187
- * ```
1188
- *
1189
- * Output:
1190
- *
1191
- * ```text
1192
- * true
1193
- * ```
1194
- *
1195
- * Example: Test the precision.
1196
- *
1197
- * ```javascript
1198
- * // Test
1199
- * let trueCount = 0;
1200
- * let falseCount = 0;
1201
- * new Array(1000000).fill(0).forEach(() => {
1202
- * if (inRate(0.5)) {
1203
- * trueCount++;
1204
- * } else {
1205
- * falseCount++;
1206
- * }
1207
- * });
1208
- * console.log(trueCount, falseCount); // 499994 500006
1209
- * ```
1210
- *
1211
- * @param {number} rate -- 0.1 ~ 1 => 1% ~ 100%
1212
- * @returns {boolean} true 命中
1213
- * @category Calculate and Formula
1214
- */
1215
- export declare function inRate(rate: number): boolean;
1216
- /**
1217
- * EN: Detect the margin of Safety. Determine if it is a secure PWA environment that it can run.
1218
- *
1219
- * ZH: 判断是否是安全的 PWA 环境
1220
- *
1221
- * Usage:
1222
- *
1223
- * ```javascript
1224
- * const ret = isSafePWAEnv();
1225
- * console.log(ret);
1226
- * ```
1227
- *
1228
- * Output:
1229
- *
1230
- * ```text
1231
- * true
1232
- * ```
1233
- *
1234
- * @returns {boolean} true 是
1235
- * @category Browser Information
1236
- */
1237
- export declare function isSafePWAEnv(): boolean;
1238
- /**
1239
- * EN: Browser Information
1240
- *
1241
- * ZH: 返回浏览器信息 https://github.com/JowayYoung/juejin-code/blob/master/browser-type.js
1242
- *
1243
- * Usage:
1244
- *
1245
- * ```javascript
1246
- * const ret = getBrowserInfo();
1247
- * console.log(ret);
1248
- * ```
1249
- *
1250
- * Output:
1251
- *
1252
- * ```text
1253
- * {"engine":"webkit","engineVs":"537.36","platform":"desktop","supporter":"chrome","supporterVs":"85.0.4183.121","system":"windows","systemVs":"10"}
1254
- * ```
1255
- *
1256
- * Results:
1257
- *
1258
- * | Attribute | Description | Type | Values |
1259
- * | :------------ | :------------ | :------------ | :------------ |
1260
- * | **system** | System | string | android, ios, windows, macos, linux |
1261
- * | systemVs | System version | string | Windows: 2000, xp, 2003, vista, 7, 8, 8.1, 10 macOS: ... |
1262
- * | platform | Platform | string | desktop, mobile |
1263
- * | engine | Engine | string | webkit, gecko, presto, trident |
1264
- * | engineVs | Engine version | string | - |
1265
- * | supporter | Supporter | string | edge, opera, chrome, safari, firefox, iexplore |
1266
- * | supporterVs | Supporter version | string | - |
1267
- * | shell | Shell | string | (Optional) wechat, qq_browser, qq_app, uc, 360, 2345, sougou, liebao, maxthon, bilibili |
1268
- * | shellVs | Shell version | string | (Optional) 20/... |
1269
- * | appleType | Apple device type | string | (Optional) ipad, iphone, ipod, iwatch |
1270
- *
1271
- * Example: Determine the environment of the mobile QQ.
1272
- *
1273
- * ```javascript
1274
- * const { system, shell } = getBrowserInfo();
1275
- * const isMobileQQ = ['android', 'ios'].includes(system) && ['qq_browser', 'qq_app'].includes(shell);
1276
- * ```
1277
- *
1278
- * @returns 浏览器信息
1279
- * @category Browser Information
1280
- */
1281
- export declare function getBrowserInfo(): BrowserInfo;
1282
- /**
1283
- * 去除 HTML 标签
1284
- *
1285
- * Usage:
1286
- *
1287
- * ```javascript
1288
- * const ret = clearHtml('<div>hello world</div>');
1289
- * console.log(ret);
1290
- * ```
1291
- *
1292
- * Output:
1293
- *
1294
- * ```text
1295
- * hello world
1296
- * ```
1297
- *
1298
- * @param {string} str 带html标签的字符串
1299
- * @returns {string} 字符串
1300
- * @category Util
1301
- */
1302
- export declare function clearHtml(str: string, options?: {
1303
- removeNewLine?: boolean;
1304
- }): string;
1305
- /**
1306
- * Sanitizes user input to prevent XSS attacks.
1307
- *
1308
- * Usage:
1309
- *
1310
- * ```javascript
1311
- * const ret = sanitizeInput('<div>hello world</div>');
1312
- * console.log(ret);
1313
- * ```
1314
- *
1315
- * Output:
1316
- *
1317
- * ```text
1318
- * &lt;div&gt;hello world&lt;/div&gt;
1319
- * ```
1320
- *
1321
- * @param input - The input string to sanitize
1322
- * @returns The sanitized input string
1323
- * @category Util
1324
- */
1325
- export declare function sanitizeInput(input: string): string;
1326
- /**
1327
- * Reverses the sanitization done by the `sanitizeInput` function.
1328
- *
1329
- * Usage:
1330
- *
1331
- * ```javascript
1332
- * const ret = unsanitize('&lt;div&gt;hello world&lt;/div&gt;');
1333
- * console.log(ret);
1334
- * ```
1335
- *
1336
- * Output:
1337
- *
1338
- * ```text
1339
- * <div>hello world</div>
1340
- * ```
1341
- *
1342
- * @param input - The input string to unsanitize
1343
- * @returns The unsanitized input string
1344
- * @category Util
1345
- */
1346
- export declare function unsanitize(input: string): string;
1347
- /**
1348
- * 截取字符串,中文算 2 个字节
1349
- *
1350
- * Usage:
1351
- *
1352
- * ```javascript
1353
- * const ret = truncateZHString('hello world', 5);
1354
- * console.log(ret);
1355
- * ```
1356
- *
1357
- * Output:
1358
- *
1359
- * ```text
1360
- * hello
1361
- * ```
1362
- *
1363
- * @param {string} str 要截取的字符串
1364
- * @param {number} len
1365
- * @param {boolean} hasDot
1366
- * @returns {string} 返回截取后的字符串
1367
- * @category Util
1368
- */
1369
- export declare function truncateZHString(str: string, len: number, hasDot?: boolean): string;
1370
- /**
1371
- * Alias of `truncateZHString`
1372
- *
1373
- * @hidden
1374
- */
1375
- export declare function cutCHSString(str: string, len: number, hasDot?: boolean): string;
1376
- /**
1377
- * EN: Check whether the page is loaded successfully (Keep the compatibility if the browser's `load` event has been triggered).
1378
- *
1379
- * ZH: 页面加载完成
1380
- *
1381
- * Usage:
1382
- *
1383
- * ```javascript
1384
- * windowLoaded(30) // second
1385
- * .then(res => {
1386
- * console.log(`Load Success: ${res}`);
1387
- * })
1388
- * .catch(err => {
1389
- * console.log(`Load Timeout or Fail: ${err.message}`);
1390
- * });
1391
- * ```
1392
- *
1393
- * Output:
1394
- *
1395
- * ```text
1396
- * Load Success: load
1397
- * ```
1398
- *
1399
- * @param {number} timeout 超时时间 / 单位:秒
1400
- * @returns {Promise<string>} document is loaded? 'complete' 'load' / 'timeout'
1401
- * @category Load Resource
1402
- */
1403
- export declare function windowLoaded(timeout?: number): Promise<string | Error>;
1404
- /**
1405
- * EN: Add `<style>` in `<head>`.
1406
- *
1407
- * ZH: 添加样式标签; style: 样式标签内的字符串; id: `<style>` 标签的 `id`; 返回: 添加成功/失败
1408
- *
1409
- * Example 1: Add the `<style>` with `id`, and repeated invoking will update the content instead of adding a new one.
1410
- *
1411
- * ```javascript
1412
- * addStyle(
1413
- * `
1414
- * body {
1415
- * background-color: #333;
1416
- * }
1417
- * `,
1418
- * {
1419
- * id: 'test',
1420
- * }
1421
- * );
1422
- * // <style id="test">
1423
- * // body {
1424
- * // background-color: #333;
1425
- * // }
1426
- * // </style>
1427
- * ```
1428
- *
1429
- * Example 2: Add the `<style>` without `id`, and repeated invoking will add a new one.
1430
- *
1431
- * ```javascript
1432
- * addStyle(
1433
- * `
1434
- * body {
1435
- * background-color: #444;
1436
- * }
1437
- * `
1438
- * );
1439
- * // <style>
1440
- * // body {
1441
- * // background-color: #444;
1442
- * // }
1443
- * // </style>
1444
- * ```
1445
- *
1446
- * @category DOM
1447
- */
1448
- export declare function addStyle(style: string, options?: {
1449
- id?: string;
1450
- }): boolean;
1451
- /**
1452
- * EN: Custom console printing (`console`).
1453
- *
1454
- * ZH: 生成自定义控制台打印
1455
- *
1456
- * Usage:
1457
- *
1458
- * ```javascript
1459
- * const myConsole = genCustomConsole('MazeyLog:');
1460
- * myConsole.log('I am string.');
1461
- * myConsole.info('I am boolean.', true);
1462
- * myConsole.info('I am number.', 123, 456);
1463
- * myConsole.info('I am object.', { a: 123, b: 456});
1464
- * ```
1465
- *
1466
- * Output:
1467
- *
1468
- * ```text
1469
- * MazeyLog: I am string.
1470
- * MazeyLog: I am boolean. true
1471
- * MazeyLog: I am number. 123 456
1472
- * MazeyLog: I am object. {a: 123, b: 456}
1473
- * ```
1474
- *
1475
- * @param {string} prefix 前缀
1476
- * @param {string} locales A locale string.
1477
- * @param {function} logFn The function with Log.
1478
- * @param {function} errorFn The function with Error.
1479
- * @returns {object} 新实例
1480
- * @category Debug
1481
- */
1482
- export declare function genCustomConsole(prefix?: string, options?: {
1483
- isClosed?: boolean;
1484
- showWrap?: boolean;
1485
- showDate?: boolean;
1486
- locales?: string;
1487
- logFn?: () => void;
1488
- errorFn?: () => void;
1489
- }): Console;
1490
- /**
1491
- * Verify the validity of axios response.
1492
- *
1493
- * Reference: [Handling Errors](https://axios-http.com/docs/handling_errors)
1494
- *
1495
- * @category Util
1496
- * @hidden
1497
- */
1498
- export declare function zAxiosIsValidRes(res: ZResResponse | undefined, options?: ZResIsValidResOptions): boolean;
1499
- /**
1500
- * Verify the validity of a non-empty array.
1501
- *
1502
- * Usage:
1503
- *
1504
- * ```javascript
1505
- * const ret = isNonEmptyArray([1, 2, 3]);
1506
- * console.log(ret);
1507
- * ```
1508
- *
1509
- * Output:
1510
- *
1511
- * ```text
1512
- * true
1513
- * ```
1514
- *
1515
- * @category Util
1516
- */
1517
- export declare function isNonEmptyArray<T>(arr: Array<T>): boolean;
1518
- /**
1519
- * Determine the validity of the data.
1520
- *
1521
- * Usage:
1522
- *
1523
- * ```javascript
1524
- * const validData = {
1525
- * a: {
1526
- * b: {
1527
- * c: 413
1528
- * }
1529
- * }
1530
- * };
1531
- * const isValidDataResA = isValidData(validData, ['a', 'b', 'c'], 2333);
1532
- * const isValidDataResB = isValidData(validData, ['a', 'b', 'c'], 413);
1533
- * const isValidDataResC = isValidData(validData, ['d', 'd'], 413);
1534
- * console.log('isValidDataResA:', isValidDataResA);
1535
- * console.log('isValidDataResB:', isValidDataResB);
1536
- * console.log('isValidDataResC:', isValidDataResC);
1537
- * ```
1538
- *
1539
- * Output:
1540
- *
1541
- * ```text
1542
- * isValidDataResA: false
1543
- * isValidDataResB: true
1544
- * isValidDataResC: false
1545
- * ```
1546
- *
1547
- * @param {any} data Original Data
1548
- * @param {string[]} attributes Data Attributes
1549
- * @param {any} validValue Given Value for verifying.
1550
- * @returns {boolean} Return TRUE if the data is valid.
1551
- * @category Util
1552
- */
1553
- export declare function isValidData(data: UnknownObject, attributes: string[], validValue: SimpleType): boolean;
1554
- /**
1555
- * 语义化文件大小,把字节转换成正常文件大小。
1556
- *
1557
- * Usage:
1558
- *
1559
- * ```javascript
1560
- * const ret = getFileSize(1024);
1561
- * console.log(ret);
1562
- * ```
1563
- *
1564
- * Output:
1565
- *
1566
- * ```text
1567
- * 1 KB
1568
- * ```
1569
- *
1570
- * @category Util
1571
- */
1572
- export declare function getFileSize(size: number): string;
1573
- /**
1574
- * Detect webp support.
1575
- *
1576
- * Usage:
1577
- *
1578
- * ```javascript
1579
- * isSupportWebp().then(res => {
1580
- * console.log('isSupportWebp:', res);
1581
- * });
1582
- * ```
1583
- *
1584
- * Output:
1585
- *
1586
- * ```text
1587
- * isSupportWebp: true
1588
- * ```
1589
- *
1590
- * Reference: [Detect WEBP Support with JavaScript](https://davidwalsh.name/detect-webp)
1591
- *
1592
- * @category Browser Information
1593
- */
1594
- export declare function isSupportWebp(): Promise<boolean>;
1595
- /**
1596
- * Generate a Hash Code from a string.
1597
- *
1598
- * Usage:
1599
- *
1600
- * ```javascript
1601
- * const ret = genHashCode('hello world');
1602
- * console.log(ret);
1603
- * ```
1604
- *
1605
- * Output:
1606
- *
1607
- * ```text
1608
- * 1794106052
1609
- * ```
1610
- *
1611
- * Reference: [Generate a Hash from string in Javascript](https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery)
1612
- *
1613
- * @category Util
1614
- */
1615
- export declare function genHashCode(str: string): number;
1616
- /**
1617
- * Return the formatted date string in the given format.
1618
- *
1619
- * Usage:
1620
- *
1621
- * ```javascript
1622
- * const ret1 = formatDate();
1623
- * const ret2 = formatDate('Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)', 'yyyy-MM-dd hh:mm:ss');
1624
- * const ret3 = formatDate(1641881235000, 'yyyy-MM-dd hh:mm:ss');
1625
- * const ret4 = formatDate(new Date(2014, 1, 11), 'MM/dd/yyyy');
1626
- * console.log('Default formatDate value:', ret1);
1627
- * console.log('String formatDate value:', ret2);
1628
- * console.log('Number formatDate value:', ret3);
1629
- * console.log('Date formatDate value:', ret4);
1630
- * ```
1631
- *
1632
- * Output:
1633
- *
1634
- * ```text
1635
- * Default formatDate value: 2023-01-11
1636
- * String formatDate value: 2022-01-11 14:12:26
1637
- * Number formatDate value: 2022-01-11 14:07:15
1638
- * Date formatDate value: 02/11/2014
1639
- * ```
1640
- *
1641
- * @param {Date|number|string} dateIns Original Date
1642
- * @param {string} format Format String
1643
- * @returns {string} Return the formatted date string.
1644
- * @category Util
1645
- */
1646
- export declare function formatDate(dateIns?: Date | number | string, format?: string): string;
1647
- /**
1648
- * Get event container.
1649
- *
1650
- * Usage:
1651
- *
1652
- * ```javascript
1653
- * const ret = getEventContainer();
1654
- * ```
1655
- *
1656
- * @category Event
1657
- * @hidden
1658
- */
1659
- export declare function getDefineListeners(): DefineListeners;
1660
- /**
1661
- * Add event.
1662
- *
1663
- * Usage:
1664
- *
1665
- * ```javascript
1666
- * addEvent('test', (e) => {
1667
- * console.log('test event:', e);
1668
- * });
1669
- * ```
1670
- *
1671
- * @param type
1672
- * @param fn
1673
- * @category Event
1674
- */
1675
- export declare function addEvent(type: string, fn: UnknownFn): void;
1676
- /**
1677
- * Invoke event.
1678
- *
1679
- * Usage:
1680
- *
1681
- * ```javascript
1682
- * invokeEvent('test');
1683
- * ```
1684
- *
1685
- * @param type
1686
- * @category Event
1687
- */
1688
- export declare function invokeEvent(type: string): void;
1689
- /**
1690
- * Remove event.
1691
- *
1692
- * Usage:
1693
- *
1694
- * ```javascript
1695
- * removeEvent('test');
1696
- * ```
1697
- *
1698
- * @param type
1699
- * @param fn
1700
- * @category Event
1701
- */
1702
- export declare function removeEvent(type: string, fn: UnknownFn): void;
1703
- /**
1704
- * Checks if the given string is a valid URL, including **scheme URLs**.
1705
- *
1706
- * Usage:
1707
- *
1708
- * ```javascript
1709
- * const ret1 = isValidUrl('https://www.example.com');
1710
- * const ret2 = isValidUrl('http://example.com/path/exx/ss');
1711
- * const ret3 = isValidUrl('https://www.example.com/?q=hello&age=24#world');
1712
- * const ret4 = isValidUrl('http://www.example.com/#world?id=9');
1713
- * const ret5 = isValidUrl('ftp://example.com');
1714
- * console.log(ret1, ret2, ret3, ret4, ret5);
1715
- * ```
1716
- *
1717
- * Output:
1718
- *
1719
- * ```text
1720
- * true true true true true
1721
- * ```
1722
- *
1723
- * @remarks
1724
- * If you are specifically checking for HTTP/HTTPS URLs, it is recommended to use the `isValidHttpUrl` function instead.
1725
- * The `isValidUrl` function matches all scheme URLs, including FTP and other non-HTTP schemes.
1726
- *
1727
- * @param url - The URL to check.
1728
- * @returns Returns `true` if the given string is a valid URL, else `false`.
1729
- * @category URL
1730
- */
1731
- export declare function isValidUrl(url: string): boolean;
1732
- /**
1733
- * Check if the given string is a valid HTTP/HTTPS URL.
1734
- *
1735
- * Usage:
1736
- *
1737
- * ```javascript
1738
- * const ret1 = isValidHttpUrl('https://www.example.com');
1739
- * const ret2 = isValidHttpUrl('http://example.com/path/exx/ss');
1740
- * const ret3 = isValidHttpUrl('https://www.example.com/?q=hello&age=24#world');
1741
- * const ret4 = isValidHttpUrl('http://www.example.com/#world?id=9');
1742
- * const ret5 = isValidHttpUrl('//example.com/a/b/c?q=1', { strict: false });
1743
- * const ret6 = isValidHttpUrl('ftp://example.com');
1744
- * console.log(ret1, ret2, ret3, ret4, ret5, ret6);
1745
- * ```
1746
- *
1747
- * Output:
1748
- *
1749
- * ```text
1750
- * true true true true true false
1751
- * ```
1752
- *
1753
- * @param url
1754
- * @param options.strict - If `true`, the function only matches standard HTTP/HTTPS URLs. Default is `true`. If `false`, the function also matches protocol-relative URLs, such as `//example.com`.
1755
- * @returns {boolean} Return true if the given string is a valid HTTP/HTTPS URL.
1756
- * @category URL
1757
- */
1758
- export declare function isValidHttpUrl(url: string, options?: {
1759
- strict: boolean;
1760
- }): boolean;
1761
- /**
1762
- * Check if the given string is a mobile phone number.
1763
- *
1764
- * Usage:
1765
- *
1766
- * ```javascript
1767
- * const ret1 = isMobile('13800138000');
1768
- * const ret2 = isMobile('1380013800');
1769
- * const ret3 = isMobile('138001380000');
1770
- * const ret4 = isMobile('1380013800a');
1771
- * console.log(ret1, ret2, ret3, ret4);
1772
- * ```
1773
- *
1774
- * Output:
1775
- *
1776
- * ```text
1777
- * true false false false
1778
- * ```
1779
- *
1780
- * @param mobile
1781
- * @returns {boolean} Return true if the given string is a mobile phone number.
1782
- * @category Util
1783
- */
1784
- export declare function isValidPhoneNumber(mobile: string): boolean;
1785
- /**
1786
- * Check if the given string is a valid email.
1787
- *
1788
- * Usage:
1789
- *
1790
- * ```javascript
1791
- * const ret = isValidEmail('mazeyqian@gmail.com');
1792
- * console.log(ret);
1793
- * ```
1794
- *
1795
- * Output:
1796
- *
1797
- * ```text
1798
- * true
1799
- * ```
1800
- *
1801
- * @param email
1802
- * @returns {boolean} Return true if the given string is a valid email.
1803
- * @category Util
1804
- */
1805
- export declare function isValidEmail(email: string): boolean;
1806
- /**
1807
- * Convert a given 10-hex number to a lowercase 26-hex string.
1808
- *
1809
- * Usage:
1810
- *
1811
- * ```javascript
1812
- * const ret1 = convert10To26(1);
1813
- * const ret2 = convert10To26(26);
1814
- * const ret3 = convert10To26(27);
1815
- * const ret4 = convert10To26(52);
1816
- * const ret5 = convert10To26(53);
1817
- * console.log(ret1, ret2, ret3, ret4, ret5);
1818
- * ```
1819
- *
1820
- * Output:
1821
- *
1822
- * ```text
1823
- * a z aa az ba
1824
- * ```
1825
- *
1826
- * @param {number} num
1827
- * @returns {string} Return a lowercase 26-hex string.
1828
- * @category Util
1829
- */
1830
- export declare function convert10To26(num: number): string;
1831
- /**
1832
- * EN: Get the file type of the url.
1833
- *
1834
- * ZH: 获取文件后缀名
1835
- *
1836
- * Usage:
1837
- *
1838
- * ```javascript
1839
- * const ret1 = getUrlFileType('https://example.com/a/b/c.png');
1840
- * const ret2 = getUrlFileType('https://example.com/a/b/c.jpg');
1841
- * const ret3 = getUrlFileType('https://example.com/a/b/c.jpeg');
1842
- * const ret4 = getUrlFileType('/a/b/c.jpeg');
1843
- * const ret5 = getUrlFileType('https://example.com/a/b/c.v/a');
1844
- * console.log(ret1, ret2, ret3, ret4, ret5);
1845
- * ```
1846
- *
1847
- * Output:
1848
- *
1849
- * ```text
1850
- * png jpg jpeg jpeg ''
1851
- * ```
1852
- *
1853
- * @param url
1854
- * @returns
1855
- * @category URL
1856
- */
1857
- export declare function getUrlFileType(url: string): boolean | string;
1858
- /**
1859
- * Sets the width and height of all images on the page based on their `src` attribute.
1860
- * The `src` attribute should contain `width` and/or `height` values in the format "width=100" or "height=100".
1861
- * If jQuery is available, this function uses jQuery to select the images. Otherwise, it uses pure JavaScript.
1862
- *
1863
- * Usage:
1864
- *
1865
- * ```javascript
1866
- * // Example images with `src` attributes containing `width` and/or `height` values
1867
- * const img1 = document.createElement('img');
1868
- * img1.setAttribute('src', 'https://example.com/example.png?width=2233&height=111');
1869
- * document.body.appendChild(img1);
1870
- *
1871
- * const img2 = document.createElement('img');
1872
- * img2.setAttribute('src', 'https://example.com/example.png?width=100%&height=auto');
1873
- * document.body.appendChild(img2);
1874
- * ```
1875
- *
1876
- * @returns {boolean} - Returns `true` if images were found and their dimensions were set, otherwise `false`.
1877
- * @category DOM
1878
- */
1879
- export declare function setImgWidHeiBySrc(): boolean;
1880
- /**
1881
- * Generate the inline style string from the given parameters. The first parameter is the query selector, and the second parameter is the style array.
1882
- *
1883
- * Usage:
1884
- *
1885
- * ```javascript
1886
- * const ret1 = genStyleString('.a', [ 'color:red' ]);
1887
- * const ret2 = genStyleString('#b', [ 'color:red', 'font-size:12px' ]);
1888
- * console.log(ret1);
1889
- * console.log(ret2);
1890
- * ```
1891
- *
1892
- * Output:
1893
- *
1894
- * ```text
1895
- * .a{color:red;}
1896
- * #b{color:red;font-size:12px;}
1897
- * ```
1898
- *
1899
- * @param {string} selector
1900
- * @param {array} styleArray
1901
- * @returns {string} The inline style string.
1902
- * @category DOM
1903
- */
1904
- export declare function genStyleString(selector: string, styleArray: Array<string>): string;
1905
- /**
1906
- * Load an image from the given URL.
1907
- *
1908
- * 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.
1909
- *
1910
- * Note that this method will not add the image to the DOM.
1911
- *
1912
- * Usage:
1913
- *
1914
- * ```javascript
1915
- * loadImage('https://example.com/example.png')
1916
- * .then((img) => {
1917
- * console.log(img);
1918
- * })
1919
- * .catch((err) => {
1920
- * console.log(err);
1921
- * });
1922
- * ```
1923
- *
1924
- * @param {string} url - The URL of the image to load.
1925
- * @returns {Promise} A Promise that resolves with the loaded image or rejects with an error.
1926
- * @category Load Resource
1927
- */
1928
- export declare function loadImage(url: string): Promise<HTMLImageElement>;
1929
- /**
1930
- * Get the current version.
1931
- *
1932
- * @hidden
1933
- */
1934
- export declare function getCurrentVersion(): string;
1935
- /**
1936
- * Repeatedly fires a callback function with a certain interval until a specified condition is met.
1937
- *
1938
- * Usage:
1939
- *
1940
- * ```javascript
1941
- * repeatUntilConditionMet(
1942
- * () => {
1943
- * console.log('repeatUntilConditionMet');
1944
- * return true;
1945
- * }, {
1946
- * interval: 1000,
1947
- * times: 10,
1948
- * context: null,
1949
- * args: [],
1950
- * }, (result) => {
1951
- * return result === true;
1952
- * }
1953
- * );
1954
- * ```
1955
- *
1956
- * @param callback The callback function to fire.
1957
- * @param options An object containing the options for the function.
1958
- * @param options.interval The interval between each firing of the callback function, in milliseconds. Defaults to 1000.
1959
- * @param options.times The maximum number of times to fire the callback function. Defaults to 10.
1960
- * @param options.context The context to use when calling the callback function. Defaults to null.
1961
- * @param options.args An array of arguments to pass to the callback function.
1962
- * @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.
1963
- * @category Util
1964
- */
1965
- export declare function repeatUntilConditionMet<T extends (...args: UnknownFnParams) => UnknownFnReturn>(callback: T, options?: RepeatUntilOptions, condition?: (result: ReturnType<T>) => boolean): void;
1966
- /**
1967
- * Load a script from the given URL if it (`window['attribute']`) has not already been loaded.
1968
- *
1969
- * Usage:
1970
- *
1971
- * ```javascript
1972
- * loadScriptIfUndefined('xyz', 'https://example.com/lib/jquery.min.js')
1973
- * .then(() => {
1974
- * console.log('xyz is loaded.');
1975
- * })
1976
- * .catch(err => {
1977
- * console.log('Failed to load xyz.', err);
1978
- * });
1979
- * ```
1980
- *
1981
- * Output:
1982
- *
1983
- * ```text
1984
- * xyz is loaded.
1985
- * ```
1986
- *
1987
- * @param {string} windowAttribute - The name of the window attribute to check (e.g. `jQuery`, `axios`, etc.).
1988
- * @param {string} url - The URL of the script to load.
1989
- * @returns {Promise} A Promise that resolves when the script has been loaded.
1990
- * @category Load Resource
1991
- */
1992
- export declare function loadScriptIfUndefined(windowAttribute: string, url: string): LoadScriptReturns;
1993
- /**
1994
- * Retrieve a query parameter from a script URL in the browser.
1995
- *
1996
- * Usage:
1997
- *
1998
- * ```javascript
1999
- * const ret = getScriptQueryParam('test', 'https://example.com/example.js');
2000
- * console.log(ret);
2001
- * ```
2002
- *
2003
- * Output:
2004
- *
2005
- * ```text
2006
- * hello
2007
- * ```
2008
- *
2009
- * @param param - The name of the query parameter to retrieve.
2010
- * @param matchString - An optional substring to match in the script URL.
2011
- * If not provided, defaults to matching the ".js" substring.
2012
- * @returns The decoded value of the specified query parameter, or an empty string if no matching parameter is found.
2013
- * @category URL
2014
- */
2015
- export declare function getScriptQueryParam(param: string, matchString?: string): string;
2016
- /**
2017
- * Wait for a specified amount of time.
2018
- *
2019
- * Usage:
2020
- *
2021
- * ```javascript
2022
- * waitTime(1000).then((time) => {
2023
- * console.log('waitTime:', time);
2024
- * });
2025
- * ```
2026
- *
2027
- * Output:
2028
- *
2029
- * ```text
2030
- * waitTime: 1000
2031
- * ```
2032
- *
2033
- * @param time The amount of time to wait, in milliseconds.
2034
- * @returns A Promise that resolves after the specified time has elapsed.
2035
- * @category Util
2036
- */
2037
- export declare function waitTime(time: number): Promise<number>;
2038
- /**
2039
- * Alias of `waitTime`.
2040
- *
2041
- * @hidden
2042
- */
2043
- export declare function sleep(time: number): Promise<number>;
2044
- export {};
5
+ export * from "./calc";
6
+ export * from "./util";
7
+ export * from "./url";
8
+ export * from "./dom";
9
+ export * from "./event";
10
+ export * from "./store";
11
+ export * from "./load";
12
+ export * from "./perf";
13
+ export * from "./browser";
14
+ export * from "./debug";
2045
15
  //# sourceMappingURL=index.d.ts.map