mazey 4.11.0 → 4.11.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 ADDED
@@ -0,0 +1,2979 @@
1
+ /**
2
+ * EN: Computes the longest common substring of two strings.
3
+ *
4
+ * ZH: 计算两个字符串的最长公共子串。
5
+ *
6
+ * Usage:
7
+ *
8
+ * ```javascript
9
+ * import { longestComSubstring } from "mazey";
10
+ *
11
+ * const ret = longestComSubstring("fish", "finish");
12
+ * console.log(ret);
13
+ * ```
14
+ *
15
+ * Output:
16
+ *
17
+ * ```text
18
+ * 3
19
+ * ```
20
+ *
21
+ * @param {string} aStr String
22
+ * @param {string} bStr String
23
+ * @returns {number} Length
24
+ * @category Calculate and Formula
25
+ */
26
+ declare function longestComSubstring(aStr: string, bStr: string): number;
27
+ /**
28
+ * Alias of `longestComSubstring`.
29
+ *
30
+ * @hidden
31
+ */
32
+ declare function calLongestCommonSubstring(aStr: string, bStr: string): number;
33
+ /**
34
+ * EN: Computes the longest common subsequence of two strings.
35
+ *
36
+ * ZH: 计算两个字符串的最长公共子序列。
37
+ *
38
+ * Usage:
39
+ *
40
+ * ```javascript
41
+ * import { longestComSubsequence } from "mazey";
42
+ *
43
+ * const ret = longestComSubsequence("fish", "finish");
44
+ * console.log(ret);
45
+ * ```
46
+ *
47
+ * Output:
48
+ *
49
+ * ```text
50
+ * 4
51
+ * ```
52
+ *
53
+ * @param {string} aStr 字符串
54
+ * @param {string} bStr 字符串
55
+ * @returns {number} 长度
56
+ * @category Calculate and Formula
57
+ */
58
+ declare function longestComSubsequence(aStr: string, bStr: string): number;
59
+ /**
60
+ * Alias of `longestComSubsequence`.
61
+ *
62
+ * @hidden
63
+ */
64
+ declare function calLongestCommonSubsequence(aStr: string, bStr: string): number;
65
+ /**
66
+ * EN: Hit probability (1% ~ 100%).
67
+ *
68
+ * ZH: 百分位概率。
69
+ *
70
+ * Usage:
71
+ *
72
+ * ```javascript
73
+ * import { isHit } from "mazey";
74
+ *
75
+ * const ret = isHit(0.5); // 0.01 ~ 1 true/false
76
+ * console.log(ret);
77
+ * ```
78
+ *
79
+ * Output:
80
+ *
81
+ * ```text
82
+ * true
83
+ * ```
84
+ *
85
+ * Example: Test the precision.
86
+ *
87
+ * ```javascript
88
+ * let trueCount = 0;
89
+ * let falseCount = 0;
90
+ * new Array(1000000).fill(0).forEach(() => {
91
+ * if (isHit(0.5)) {
92
+ * trueCount++;
93
+ * } else {
94
+ * falseCount++;
95
+ * }
96
+ * });
97
+ * console.log(trueCount, falseCount);
98
+ * ```
99
+ *
100
+ * Output:
101
+ *
102
+ * ```text
103
+ * 499994 500006
104
+ * ```
105
+ *
106
+ * @param {number} rate 0.1 ~ 1 => 1% ~ 100%
107
+ * @returns {boolean} true 命中
108
+ * @category Calculate and Formula
109
+ */
110
+ declare function isHit(rate: number): boolean;
111
+ /**
112
+ * Alias of `isHit`.
113
+ *
114
+ * @hidden
115
+ */
116
+ declare function inRate(rate: number): boolean;
117
+
118
+ /**
119
+ * @author Cheng
120
+ */
121
+
122
+ interface BrowserInfo {
123
+ engine: string; // webkit gecko presto trident
124
+ engineVs: string;
125
+ platform: string; // desktop mobile
126
+ supporter: string; // chrome safari firefox opera iexplore edge
127
+ supporterVs: string;
128
+ system: string; // windows macos linux android ios
129
+ systemVs: string;
130
+ shell: string; // wechat qq uc 360 2345 sougou liebao maxthon
131
+ shellVs: string;
132
+ appleType: string;
133
+ colorScheme: string;
134
+ }
135
+
136
+ interface DefineListeners {
137
+ [key: string]: any;
138
+ }
139
+
140
+ type SingleValueUrlParams = {
141
+ [key: string]: string;
142
+ };
143
+
144
+ type ThrottleFunc<T extends (...args: any[]) => any> = (...args: Parameters<T>) => ReturnType<T> | null;
145
+
146
+ type DebounceFunc<T extends (...args: any[]) => any> = (...args: Parameters<T>) => ReturnType<T>;
147
+
148
+ interface IsNumberOptions {
149
+ isNaNAsNumber?: boolean;
150
+ isInfinityAsNumber?: boolean;
151
+ isUnFiniteAsNumber?: boolean;
152
+ }
153
+
154
+ interface ZResResponse {
155
+ status: number;
156
+ data: {
157
+ code: number;
158
+ };
159
+ }
160
+
161
+ interface ZResIsValidResOptions {
162
+ validStatusRange?: [number, number];
163
+ validCode?: number[];
164
+ }
165
+
166
+ interface RepeatUntilOptions {
167
+ interval?: number;
168
+ times?: number;
169
+ context?: any;
170
+ args?: Array<any>;
171
+ }
172
+
173
+ type LoadScriptReturns = Promise<boolean | string | Error | void>;
174
+
175
+ type SimpleType = string | number | boolean | null | undefined;
176
+
177
+ type MazeyObject = any;
178
+ type MazeyFnParams = any[];
179
+ type MazeyFnReturn = any;
180
+ type MazeyFunction = (...args: any[]) => any;
181
+ type MazeyFn = (...args: MazeyFnParams) => MazeyFnReturn;
182
+
183
+ interface WebPerformance {
184
+ [key: string]: string | number;
185
+ }
186
+
187
+ type MazeyElement = HTMLElement | null;
188
+
189
+ type MazeyDate = Date | string | number;
190
+
191
+ type URLChangeTrigger = "load" | "popstate" | "hashchange" | "pushState" | "replaceState";
192
+
193
+ interface URLChangeInfo {
194
+ url: string;
195
+ oldUrl: string;
196
+ trigger: URLChangeTrigger;
197
+ }
198
+
199
+ interface OnURLChangeOptions {
200
+ fireOnInit?: boolean;
201
+ }
202
+
203
+ /**
204
+ * Copy/Clone Object deeply.
205
+ *
206
+ * Usage:
207
+ *
208
+ * ```javascript
209
+ * import { deepCopy } from "mazey";
210
+ *
211
+ * const ret1 = deepCopy(["a", "b", "c"]);
212
+ * const ret2 = deepCopy("abc");
213
+ * console.log(ret1);
214
+ * console.log(ret2);
215
+ * ```
216
+ *
217
+ * Output:
218
+ *
219
+ * ```text
220
+ * ["a", "b", "c"]
221
+ * abc
222
+ * ```
223
+ *
224
+ * @param {object} obj The value to clone.
225
+ * @returns {object} Returns the deep cloned value.
226
+ * @category Util
227
+ */
228
+ declare function deepCopy<T>(obj: T): T;
229
+ /**
230
+ * Alias of `deepCopy`.
231
+ *
232
+ * @hidden
233
+ */
234
+ declare function deepCopyObject<T>(obj: T): T;
235
+ /**
236
+ * Convert CamelCase to KebabCase.
237
+ *
238
+ * Usage:
239
+ *
240
+ * ```javascript
241
+ * import { convertCamelToKebab } from "mazey";
242
+ *
243
+ * const ret1 = convertCamelToKebab("ABC");
244
+ * const ret2 = convertCamelToKebab("aBC");
245
+ * console.log(ret1);
246
+ * console.log(ret2);
247
+ * ```
248
+ *
249
+ * Output:
250
+ *
251
+ * ```text
252
+ * a-b-c
253
+ * a-b-c
254
+ * ```
255
+ *
256
+ * @param {string} camelCase "aBC" or "ABC"
257
+ * @returns {string} "a-b-c"
258
+ * @category Util
259
+ */
260
+ declare function convertCamelToKebab(camelCase: string): string;
261
+ /**
262
+ * Convert KebabCase to CamelCase.
263
+ *
264
+ * Usage:
265
+ *
266
+ * ```javascript
267
+ * import { convertKebabToCamel } from "mazey";
268
+ *
269
+ * const ret1 = convertKebabToCamel("a-b-c");
270
+ * const ret2 = convertKebabToCamel("a-bb-cc");
271
+ * console.log(ret1, ret2);
272
+ * ```
273
+ *
274
+ * Output:
275
+ *
276
+ * ```text
277
+ * aBC aBbCc
278
+ * ```
279
+ *
280
+ * @param {string} kebabCase "a-bb-cc"
281
+ * @returns {string} "aBbCc"
282
+ * @category Util
283
+ */
284
+ declare function convertKebabToCamel(kebabCase: string): string;
285
+ /**
286
+ * Alias of `convertCamelToKebab`.
287
+ *
288
+ * @hidden
289
+ */
290
+ declare function camelCaseToKebabCase(camelCase: string): string;
291
+ /**
292
+ * Convert CamelCase to Underscore.
293
+ *
294
+ * Usage:
295
+ *
296
+ * ```javascript
297
+ * import { convertCamelToUnder } from "mazey";
298
+ *
299
+ * const ret1 = convertCamelToUnder("ABC");
300
+ * const ret2 = convertCamelToUnder("aBC");
301
+ * console.log(ret1);
302
+ * console.log(ret2);
303
+ * ```
304
+ *
305
+ * Output:
306
+ *
307
+ * ```text
308
+ * a_b_c
309
+ * a_b_c
310
+ * ```
311
+ *
312
+ * @param {string} camelCase "aBC" or "ABC"
313
+ * @returns {string} "a_b_c"
314
+ * @category Util
315
+ */
316
+ declare function convertCamelToUnder(camelCase: string): string;
317
+ /**
318
+ * Convert Underscore to CamelCase.
319
+ *
320
+ * Usage:
321
+ *
322
+ * ```javascript
323
+ * import { convertUnderToCamel } from "mazey";
324
+ *
325
+ * const ret1 = convertUnderToCamel("a_b_c");
326
+ * const ret2 = convertUnderToCamel("a_bb_cc");
327
+ * console.log(ret1, ret2);
328
+ * ```
329
+ *
330
+ * Output:
331
+ *
332
+ * ```text
333
+ * aBC aBbCc
334
+ * ```
335
+ *
336
+ * @param {string} underCase "a_bb_cc"
337
+ * @returns {string} "aBbCc"
338
+ * @category Util
339
+ */
340
+ declare function convertUnderToCamel(underCase: string): string;
341
+ /**
342
+ * Alias of `convertCamelToUnder`.
343
+ *
344
+ * @hidden
345
+ */
346
+ declare function camelCase2Underscore(camelCase: string): string;
347
+ /**
348
+ * Remove leading and trailing whitespace or specified characters from string.
349
+ *
350
+ * Note: This method is used to replace the native `String.prototype.trim()`. But it is not necessary to use it in modern browsers.
351
+ *
352
+ * Usage:
353
+ *
354
+ * ```javascript
355
+ * import { mTrim } from "mazey";
356
+ *
357
+ * const ret1 = mTrim(" 1 2 3 ");
358
+ * const ret2 = mTrim("abc ");
359
+ * console.log(ret1);
360
+ * console.log(ret2);
361
+ * ```
362
+ *
363
+ * Output:
364
+ *
365
+ * ```text
366
+ * 1 2 3
367
+ * abc
368
+ * ```
369
+ *
370
+ * @param {string} str The string to trim.
371
+ * @returns {string} Trimmed string.
372
+ * @category Util
373
+ * @hidden
374
+ */
375
+ declare function mTrim(str: string): string;
376
+ /**
377
+ * Check whether it is a valid JSON string.
378
+ *
379
+ * Usage:
380
+ *
381
+ * ```javascript
382
+ * import { isJSONString } from "mazey";
383
+ *
384
+ * const ret1 = isJSONString(`['a', 'b', 'c']`);
385
+ * const ret2 = isJSONString(`["a", "b", "c"]`);
386
+ * console.log(ret1);
387
+ * console.log(ret2);
388
+ * ```
389
+ *
390
+ * Output:
391
+ *
392
+ * ```text
393
+ * false
394
+ * true
395
+ * ```
396
+ *
397
+ * @param {string} str The string to check.
398
+ * @returns {boolean} Return the result of checking.
399
+ * @category Util
400
+ */
401
+ declare function isJSONString(str: string): boolean;
402
+ /**
403
+ * Alias of `isJSONString`.
404
+ *
405
+ * @hidden
406
+ */
407
+ declare function isJsonString(str: string): boolean;
408
+ /**
409
+ * Generate a random string of number, `genRndNumString(7)` => "7658495".
410
+ *
411
+ * Usage:
412
+ *
413
+ * ```javascript
414
+ * import { genRndNumString } from "mazey";
415
+ *
416
+ * const ret1 = genRndNumString(4);
417
+ * const ret2 = genRndNumString(7);
418
+ * console.log(ret1);
419
+ * console.log(ret2);
420
+ * ```
421
+ *
422
+ * Output:
423
+ *
424
+ * ```text
425
+ * 9730
426
+ * 2262490
427
+ * ```
428
+ *
429
+ * @param {number} n Length
430
+ * @returns {string} Return the random string.
431
+ * @category Util
432
+ */
433
+ declare function genRndNumString(n?: number): string;
434
+ /**
435
+ * Alias of `genRndNumString`.
436
+ *
437
+ * @hidden
438
+ */
439
+ declare function generateRndNum(n?: number): string;
440
+ /**
441
+ * EN: Generate a unique identifier number based on time: `genUniqueNumString()` => `1538324722364123`
442
+ *
443
+ * ZH: 根据时间生成唯一标志的数字:`genUniqueNumString()` => `1538324722364123`。
444
+ *
445
+ * Usage:
446
+ *
447
+ * ```javascript
448
+ * import { genUniqueNumString } from "mazey";
449
+ *
450
+ * const ret1 = genUniqueNumString();
451
+ * const ret2 = genUniqueNumString(3);
452
+ * console.log(ret1);
453
+ * console.log(ret2);
454
+ * ```
455
+ *
456
+ * Output:
457
+ *
458
+ * ```text
459
+ * 1538324722364123
460
+ * 1538324722364123
461
+ * ```
462
+ *
463
+ * @param {number} n 随机数的长度
464
+ * @category Util
465
+ */
466
+ declare function genUniqueNumString(n?: number): string;
467
+ /**
468
+ * Alias of `genUniqueNumString`.
469
+ *
470
+ * @hidden
471
+ */
472
+ declare function generateUniqueNum(n?: number): string;
473
+ /**
474
+ * EN: Get timestamp.
475
+ *
476
+ * ZH: 获取时间戳。
477
+ *
478
+ * Usage:
479
+ *
480
+ * ```javascript
481
+ * import { mNow } from "mazey";
482
+ *
483
+ * const ret = mNow();
484
+ * console.log(ret);
485
+ * ```
486
+ *
487
+ * Output:
488
+ *
489
+ * ```text
490
+ * 1585325367122
491
+ * ```
492
+ *
493
+ * @category Util
494
+ */
495
+ declare function mNow(): number;
496
+ /**
497
+ * EN: Floating point number to percentage 0.2 => 20%
498
+ *
499
+ * ZH: 浮点数转为百分比 0.2 => 20%。
500
+ *
501
+ * Usage:
502
+ *
503
+ * ```javascript
504
+ * import { floatToPercent } from "mazey";
505
+ *
506
+ * const ret1 = floatToPercent(0.2);
507
+ * const ret2 = floatToPercent(0.2, 2);
508
+ * console.log(ret1);
509
+ * console.log(ret2);
510
+ * ```
511
+ *
512
+ * Output:
513
+ *
514
+ * ```text
515
+ * 20%
516
+ * 20.00%
517
+ * ```
518
+ *
519
+ * @param {number} num 浮点数
520
+ * @param {number} fixSize 保留几位浮点数
521
+ * @category Util
522
+ */
523
+ declare function floatToPercent(num: number, fixSize?: number): string;
524
+ /**
525
+ * EN: Keep the specified number of decimal places for floating-point numbers.
526
+ *
527
+ * ZH: 浮点数保留指定位。
528
+ *
529
+ * Usage:
530
+ *
531
+ * ```javascript
532
+ * import { floatFixed } from "mazey";
533
+ *
534
+ * const ret1 = floatFixed(0.2);
535
+ * const ret2 = floatFixed(0.2, 2);
536
+ * console.log(ret1);
537
+ * console.log(ret2);
538
+ * ```
539
+ *
540
+ * Output:
541
+ *
542
+ * ```text
543
+ * 0
544
+ * 0.20
545
+ * ```
546
+ *
547
+ * @category Util
548
+ */
549
+ declare function floatFixed(num: string, size?: number): string;
550
+ /**
551
+ * EN: Throttle, used to limit the frequency of function execution over time.
552
+ *
553
+ * ZH: 节流,用于限制函数在一段时间内的执行频率。
554
+ *
555
+ * Usage:
556
+ *
557
+ * ```javascript
558
+ * import { throttle } from "mazey";
559
+ *
560
+ * const foo = throttle(() => {
561
+ * console.log("The function will be invoked at most once per every wait 1000 milliseconds.");
562
+ * }, 1000, { leading: true });
563
+ * ```
564
+ *
565
+ * Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
566
+ *
567
+ * @category Util
568
+ */
569
+ declare function throttle<T extends (...args: MazeyFnParams) => MazeyFnReturn>(func: T, wait: number, options?: {
570
+ leading?: boolean;
571
+ trailing?: boolean;
572
+ }): ThrottleFunc<T>;
573
+ /**
574
+ * EN: Debounce, used to delay the execution of a function until a specified time has passed since the last invocation.
575
+ *
576
+ * ZH: 防抖,用于在最后一次调用后的指定时间内延迟函数的执行。
577
+ *
578
+ * Usage:
579
+ *
580
+ * ```javascript
581
+ * import { debounce } from "mazey";
582
+ *
583
+ * const foo = debounce(() => {
584
+ * console.log("The debounced function will only be invoked in 1000 milliseconds, the other invoking will disappear during the wait time.");
585
+ * }, 1000, true);
586
+ * ```
587
+ *
588
+ * @category Util
589
+ */
590
+ declare function debounce<T extends (...args: MazeyFnParams) => MazeyFnReturn>(func: T, wait: number, immediate?: boolean): DebounceFunc<T>;
591
+ /**
592
+ * EN: Get interval time.
593
+ *
594
+ * ZH: 获取间隔时间。
595
+ *
596
+ * Usage:
597
+ *
598
+ * ```javascript
599
+ * import { getFriendlyInterval } from "mazey";
600
+ *
601
+ * const ret1 = getFriendlyInterval(new Date("2020-03-28 00:09:27"), new Date("2023-04-18 10:54:00"), { type: "d" });
602
+ * const ret2 = getFriendlyInterval(1585325367000, 1681786440000, { type: "text" });
603
+ * const ret3 = getFriendlyInterval("2020-03-28 00:09:27", "2023-04-18 10:54:00", { type: "text" });
604
+ * console.log(ret1);
605
+ * console.log(ret2);
606
+ * console.log(ret3);
607
+ * ```
608
+ *
609
+ * Output:
610
+ *
611
+ * ```text
612
+ * 1116
613
+ * 1116 天 10 时 44 分 33 秒
614
+ * 1116 天 10 时 44 分 33 秒
615
+ * ```
616
+ *
617
+ * @param {number/Date} start 开始时间戳 1585325367122
618
+ * @param {number/Date} end 结束时间戳 1585325367122
619
+ * @param {string} options.type 返回类型 d: 2(天) text: 2 天 4 时...
620
+ * @returns {string/number} 取决于 type
621
+ * @category Util
622
+ */
623
+ declare function getFriendlyInterval(start?: number | string | Date, end?: number | string | Date, options?: {
624
+ type?: string;
625
+ }): number | string;
626
+ /**
627
+ * EN: Check whether it is a right number.
628
+ *
629
+ * ZH: 判断是否有效数字。
630
+ *
631
+ * Usage:
632
+ *
633
+ * ```javascript
634
+ * import { isNumber } from "mazey";
635
+ *
636
+ * const ret1 = isNumber(123);
637
+ * const ret2 = isNumber("123");
638
+ * // Default: NaN, Infinity is not Number
639
+ * const ret3 = isNumber(Infinity);
640
+ * const ret4 = isNumber(Infinity, { isInfinityAsNumber: true });
641
+ * const ret5 = isNumber(NaN);
642
+ * const ret6 = isNumber(NaN, { isNaNAsNumber: true, isInfinityAsNumber: true });
643
+ * console.log(ret1, ret2, ret3, ret4, ret5, ret6);
644
+ * ```
645
+ *
646
+ * Output:
647
+ *
648
+ * ```text
649
+ * true false false true false true
650
+ * ```
651
+ *
652
+ * @param {*} num 被判断的值
653
+ * @param {boolean} options.isNaNAsNumber 是否 NaN 算数字(默认不算)
654
+ * @param {boolean} options.isInfinityAsNumber 是否 无限 算数字(默认不算)
655
+ * @returns {boolean} true 是数字
656
+ * @category Util
657
+ */
658
+ declare function isNumber(num: unknown, options?: IsNumberOptions): boolean;
659
+ /**
660
+ * EN: Invoke effective function.
661
+ *
662
+ * ZH: 执行有效函数。
663
+ *
664
+ * Usage:
665
+ *
666
+ * ```javascript
667
+ * import { invokeFn } from "mazey";
668
+ *
669
+ * const ret = invokeFn(() => {
670
+ * console.log("invokeFn");
671
+ * });
672
+ * ```
673
+ *
674
+ * @param {function} fn 等待被执行的未知是否有效的函数
675
+ * @category Util
676
+ */
677
+ declare function invokeFn(fn: MazeyFunction, ...params: Parameters<MazeyFunction>): ReturnType<MazeyFunction> | null;
678
+ /**
679
+ * Alias of `invokeFn`.
680
+ *
681
+ * @hidden
682
+ */
683
+ declare function doFn(fn: MazeyFunction, ...params: Parameters<MazeyFunction>): ReturnType<MazeyFunction> | null;
684
+ /**
685
+ * Verify the validity of a non-empty array.
686
+ *
687
+ * Usage:
688
+ *
689
+ * ```javascript
690
+ * import { isNonEmptyArray } from "mazey";
691
+ *
692
+ * const ret = isNonEmptyArray([1, 2, 3]);
693
+ * console.log(ret);
694
+ * ```
695
+ *
696
+ * Output:
697
+ *
698
+ * ```text
699
+ * true
700
+ * ```
701
+ *
702
+ * @category Util
703
+ */
704
+ declare function isNonEmptyArray<T>(arr: Array<T>): boolean;
705
+ /**
706
+ * Verify the validity of a pure object.
707
+ *
708
+ * Usage:
709
+ *
710
+ * ```javascript
711
+ * import { isPureObject } from "mazey";
712
+ *
713
+ * const ret1 = isPureObject({ a: 1 });
714
+ * const ret2 = isPureObject("abc");
715
+ * const ret3 = isPureObject(null);
716
+ * const ret4 = isPureObject([]);
717
+ *
718
+ * console.log(ret1, ret2, ret3, ret4);
719
+ * ```
720
+ *
721
+ * Output:
722
+ *
723
+ * ```text
724
+ * true false false false
725
+ * ```
726
+ *
727
+ * @param {MazeyObject} obj The object to verify.
728
+ * @returns {boolean} Return TRUE if the object is a pure object.
729
+ * @category Util
730
+ */
731
+ declare function isPureObject(obj: MazeyObject): boolean;
732
+ /**
733
+ * Verify the validity of a function.
734
+ *
735
+ * Usage:
736
+ *
737
+ * ```javascript
738
+ * import { isFunction } from "mazey";
739
+ *
740
+ * const ret1 = isFunction(() => {});
741
+ * const ret2 = isFunction("abc");
742
+ * const ret3 = isFunction(null);
743
+ * console.log(ret1, ret2, ret3);
744
+ * ```
745
+ *
746
+ * Output:
747
+ *
748
+ * ```text
749
+ * true false false
750
+ * ```
751
+ *
752
+ * @param {MazeyObject} fn The function to verify.
753
+ * @returns {boolean} Return TRUE if the object is a function.
754
+ * @category Util
755
+ */
756
+ declare function isFunction(fn: MazeyObject): boolean;
757
+ /**
758
+ * Verify the validity of a string.
759
+ *
760
+ * Usage:
761
+ *
762
+ * ```javascript
763
+ * import { isString } from "mazey";
764
+ *
765
+ * const ret1 = isString("abc");
766
+ * const ret2 = isString({ a: 1 });
767
+ * const ret3 = isString(null);
768
+ * console.log(ret1, ret2, ret3);
769
+ * ```
770
+ *
771
+ * Output:
772
+ *
773
+ * ```text
774
+ * true false false
775
+ * ```
776
+ *
777
+ * @param {MazeyObject} str The string to verify.
778
+ * @returns {boolean} Return TRUE if the object is a string.
779
+ * @category Util
780
+ */
781
+ declare function isString(str: MazeyObject): boolean;
782
+ /**
783
+ * Verify the validity of a boolean.
784
+ *
785
+ * Usage:
786
+ *
787
+ * ```javascript
788
+ * import { isBool } from "mazey";
789
+ *
790
+ * const ret1 = isBool(true);
791
+ * const ret2 = isBool({ a: 1 });
792
+ * const ret3 = isBool("abc");
793
+ * const ret4 = isBool(null);
794
+ * console.log(ret1, ret2, ret3, ret4);
795
+ * ```
796
+ *
797
+ * Output:
798
+ *
799
+ * ```text
800
+ * true false false false
801
+ * ```
802
+ *
803
+ * @param {MazeyObject} bool The boolean to verify.
804
+ * @returns {boolean} Return TRUE if the object is a boolean.
805
+ * @category Util
806
+ */
807
+ declare function isBool(bool: MazeyObject): boolean;
808
+ /**
809
+ * Alias of `isBool`.
810
+ */
811
+ declare function isBoolean(bool: MazeyObject): boolean;
812
+ /**
813
+ * Verify the validity of a value.
814
+ *
815
+ * Usage:
816
+ *
817
+ * ```javascript
818
+ * import { isUdfOrNul } from "mazey";
819
+ *
820
+ * const ret1 = isUdfOrNul(undefined);
821
+ * const ret2 = isUdfOrNul(null);
822
+ * const ret3 = isUdfOrNul("abc");
823
+ * console.log(ret1, ret2, ret3);
824
+ * ```
825
+ *
826
+ * Output:
827
+ *
828
+ * ```text
829
+ * true true false
830
+ * ```
831
+ *
832
+ * @param {MazeyObject} val The value to verify.
833
+ * @returns {boolean} Return TRUE if the object is undefined or null.
834
+ * @category Util
835
+ */
836
+ declare function isUdfOrNul(val: MazeyObject): boolean;
837
+ /**
838
+ * Verify the validity of an array.
839
+ *
840
+ * Usage:
841
+ *
842
+ * ```javascript
843
+ * import { isArray } from "mazey";
844
+ *
845
+ * const ret1 = isArray([1, 2, 3]);
846
+ * const ret2 = isArray({ a: 1 });
847
+ * const ret3 = isArray("abc");
848
+ * const ret4 = isArray(null);
849
+ * console.log(ret1, ret2, ret3, ret4);
850
+ * ```
851
+ *
852
+ * Output:
853
+ *
854
+ * ```text
855
+ * true false false false
856
+ * ```
857
+ *
858
+ * @param {MazeyObject} obj The object to verify.
859
+ * @returns {boolean} Return TRUE if the object is an array.
860
+ * @category Util
861
+ */
862
+ declare function isArray(obj: MazeyObject): boolean;
863
+ /**
864
+ * Verify the validity of a non-empty object.
865
+ *
866
+ * Usage:
867
+ *
868
+ * ```javascript
869
+ * import { isNonEmptyObject } from "mazey";
870
+ *
871
+ * const ret1 = isNonEmptyObject({ a: 1 });
872
+ * const ret2 = isNonEmptyObject({});
873
+ * const ret3 = isNonEmptyObject("abc");
874
+ * const ret4 = isNonEmptyObject(null);
875
+ * console.log(ret1, ret2, ret3, ret4);
876
+ * ```
877
+ *
878
+ * Output:
879
+ *
880
+ * ```text
881
+ * true false false false
882
+ * ```
883
+ *
884
+ * @param obj
885
+ * @returns
886
+ */
887
+ declare function isNonEmptyObject(obj: MazeyObject): boolean;
888
+ /**
889
+ * Convert newline characters `\n` into HTML line breaks `<br />`.
890
+ *
891
+ * Usage:
892
+ *
893
+ * ```javascript
894
+ * import { convertToHtmlBreaks } from "mazey";
895
+ *
896
+ * const ret1 = convertToHtmlBreaks("a\nb\nc");
897
+ * const ret2 = convertToHtmlBreaks("a\n\nbc");
898
+ * console.log(ret1);
899
+ * console.log(ret2);
900
+ * ```
901
+ *
902
+ * Output:
903
+ *
904
+ * ```text
905
+ * a<br />b<br />c
906
+ * a<br /><br />bc
907
+ * ```
908
+ *
909
+ * @param {string} str The string to make a new line.
910
+ * @returns {string} A newline with `br`.
911
+ * @category Util
912
+ */
913
+ declare function convertToHtmlBreaks(str: string): string;
914
+ /**
915
+ * Alias of `convertToHtmlBreaks`.
916
+ *
917
+ * @hidden
918
+ */
919
+ declare function newLine(str: string): string;
920
+ /**
921
+ * Remove HTML tags from a string, and optionally newline characters.
922
+ *
923
+ * Usage:
924
+ *
925
+ * ```javascript
926
+ * import { removeHTML } from "mazey";
927
+ *
928
+ * const ret = removeHTML("<div>hello world</div>");
929
+ * console.log(ret);
930
+ * ```
931
+ *
932
+ * Output:
933
+ *
934
+ * ```text
935
+ * hello world
936
+ * ```
937
+ *
938
+ * @param {string} str 带 HTML 标签的字符串
939
+ * @returns {string} 字符串
940
+ * @category Util
941
+ */
942
+ declare function removeHTML(str: string, options?: {
943
+ removeNewLine?: boolean;
944
+ }): string;
945
+ /**
946
+ * Alias of `removeHTML`.
947
+ *
948
+ * @hidden
949
+ */
950
+ declare function removeHtml(str: string, options?: {
951
+ removeNewLine?: boolean;
952
+ }): string;
953
+ /**
954
+ * Alias of `removeHTML`.
955
+ *
956
+ * @hidden
957
+ */
958
+ declare function clearHTML(str: string, options?: {
959
+ removeNewLine?: boolean;
960
+ }): string;
961
+ /**
962
+ * Alias of `removeHTML`.
963
+ *
964
+ * @hidden
965
+ */
966
+ declare function clearHtml(str: string, options?: {
967
+ removeNewLine?: boolean;
968
+ }): string;
969
+ /**
970
+ * Sanitizes user input to prevent XSS attacks.
971
+ *
972
+ * Usage:
973
+ *
974
+ * ```javascript
975
+ * import { sanitizeInput } from "mazey";
976
+ *
977
+ * const ret = sanitizeInput("<div>hello world</div>");
978
+ * console.log(ret);
979
+ * ```
980
+ *
981
+ * Output:
982
+ *
983
+ * ```text
984
+ * &lt;div&gt;hello world&lt;/div&gt;
985
+ * ```
986
+ *
987
+ * @param input - The input string to sanitize
988
+ * @returns The sanitized input string
989
+ * @category Util
990
+ */
991
+ declare function sanitizeInput(input: string): string;
992
+ /**
993
+ * Reverses the sanitization done by the `sanitizeInput` function.
994
+ *
995
+ * Usage:
996
+ *
997
+ * ```javascript
998
+ * import { unsanitizeInput } from "mazey";
999
+ *
1000
+ * const ret = unsanitizeInput("&lt;div&gt;hello world&lt;/div&gt;");
1001
+ * console.log(ret);
1002
+ * ```
1003
+ *
1004
+ * Output:
1005
+ *
1006
+ * ```text
1007
+ * <div>hello world</div>
1008
+ * ```
1009
+ *
1010
+ * @param input - The input string to unsanitize
1011
+ * @returns The unsanitized input string
1012
+ * @category Util
1013
+ */
1014
+ declare function unsanitizeInput(input: string): string;
1015
+ /**
1016
+ * Alias of `unsanitizeInput`.
1017
+ *
1018
+ * @hidden
1019
+ */
1020
+ declare function unsanitize(str: string): string;
1021
+ /**
1022
+ * EN: Truncate string, Chinese characters count as 2 bytes.
1023
+ *
1024
+ * ZH: 截取字符串,中文算 2 个字节。
1025
+ *
1026
+ * Usage:
1027
+ *
1028
+ * ```javascript
1029
+ * import { cutZHString } from "mazey";
1030
+ *
1031
+ * const ret = cutZHString("hello world", 5);
1032
+ * console.log(ret);
1033
+ * ```
1034
+ *
1035
+ * Output:
1036
+ *
1037
+ * ```text
1038
+ * hello
1039
+ * ```
1040
+ *
1041
+ * @param {string} str 要截取的字符串
1042
+ * @param {number} len
1043
+ * @param {boolean} options.hasDot
1044
+ * @param {string} options.dotText
1045
+ * @returns {string} 返回截取后的字符串
1046
+ * @category Util
1047
+ */
1048
+ declare function cutZHString(str: string, len: number, options?: {
1049
+ hasDot?: boolean;
1050
+ dotText?: string;
1051
+ }): string;
1052
+ /**
1053
+ * Alias of `cutZHString`.
1054
+ *
1055
+ * Usage:
1056
+ *
1057
+ * ```javascript
1058
+ * import { truncateZHString } from "mazey";
1059
+ *
1060
+ * const ret = truncateZHString("hello world", 5);
1061
+ * console.log(ret);
1062
+ * ```
1063
+ *
1064
+ * Output:
1065
+ *
1066
+ * ```text
1067
+ * hello
1068
+ *
1069
+ * @param {string} str 要截取的字符串
1070
+ * @param {number} len
1071
+ * @param {boolean} hasDot
1072
+ * @returns {string} 返回截取后的字符串
1073
+ * @hidden
1074
+ */
1075
+ declare function truncateZHString(str: string, len: number, hasDot?: boolean): string;
1076
+ /**
1077
+ * Alias of `truncateZHString`.
1078
+ *
1079
+ * @hidden
1080
+ */
1081
+ declare function cutCHSString(str: string, len: number, hasDot?: boolean): string;
1082
+ /**
1083
+ * Verify the validity of axios response.
1084
+ *
1085
+ * Reference: [Handling Errors](https://axios-http.com/docs/handling_errors)
1086
+ *
1087
+ * @category Util
1088
+ * @hidden
1089
+ */
1090
+ declare function zAxiosIsValidRes(res: ZResResponse | undefined, options?: ZResIsValidResOptions): boolean;
1091
+ /**
1092
+ * Determine the validity of the data.
1093
+ *
1094
+ * Usage:
1095
+ *
1096
+ * ```javascript
1097
+ * import { isValidData } from "mazey";
1098
+ *
1099
+ * const validData = {
1100
+ * a: {
1101
+ * b: {
1102
+ * c: 413
1103
+ * }
1104
+ * }
1105
+ * };
1106
+ * const isValidDataResA = isValidData(validData, ["a", "b", "c"], 2333);
1107
+ * const isValidDataResB = isValidData(validData, ["a", "b", "c"], 413);
1108
+ * const isValidDataResC = isValidData(validData, ["d", "d"], 413);
1109
+ * console.log("isValidDataResA:", isValidDataResA);
1110
+ * console.log("isValidDataResB:", isValidDataResB);
1111
+ * console.log("isValidDataResC:", isValidDataResC);
1112
+ * ```
1113
+ *
1114
+ * Output:
1115
+ *
1116
+ * ```text
1117
+ * isValidDataResA: false
1118
+ * isValidDataResB: true
1119
+ * isValidDataResC: false
1120
+ * ```
1121
+ *
1122
+ * @param {any} data Original Data
1123
+ * @param {string[]} attributes Data Attributes
1124
+ * @param {any} validValue Given Value for verifying.
1125
+ * @returns {boolean} Return TRUE if the data is valid.
1126
+ * @category Util
1127
+ */
1128
+ declare function isValidData(data: MazeyObject, attributes: string[], validValue: SimpleType): boolean;
1129
+ /**
1130
+ * EN: Semantic file size, convert bytes into a readable file size.
1131
+ *
1132
+ * ZH: 语义化文件大小,把字节转换成正常文件大小。
1133
+ *
1134
+ * Usage:
1135
+ *
1136
+ * ```javascript
1137
+ * import { getFileSize } from "mazey";
1138
+ *
1139
+ * const ret = getFileSize(1024);
1140
+ * console.log(ret);
1141
+ * ```
1142
+ *
1143
+ * Output:
1144
+ *
1145
+ * ```text
1146
+ * 1 KB
1147
+ * ```
1148
+ *
1149
+ * @category Util
1150
+ */
1151
+ declare function getFileSize(size: number): string;
1152
+ /**
1153
+ * Generate a Hash Code from a string.
1154
+ *
1155
+ * Usage:
1156
+ *
1157
+ * ```javascript
1158
+ * import { genHashCode } from "mazey";
1159
+ *
1160
+ * const ret = genHashCode("hello world");
1161
+ * console.log(ret);
1162
+ * ```
1163
+ *
1164
+ * Output:
1165
+ *
1166
+ * ```text
1167
+ * 1794106052
1168
+ * ```
1169
+ *
1170
+ * Reference: [Generate a Hash from string in Javascript](https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery)
1171
+ *
1172
+ * @category Util
1173
+ */
1174
+ declare function genHashCode(str: string): number;
1175
+ /**
1176
+ * Return the formatted date string in the given format.
1177
+ *
1178
+ * Usage:
1179
+ *
1180
+ * ```javascript
1181
+ * import { formatDate } from "mazey";
1182
+ *
1183
+ * const ret1 = formatDate();
1184
+ * const ret2 = formatDate("Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)", "yyyy-MM-dd hh:mm:ss a");
1185
+ * const ret3 = formatDate(1641881235000, "yyyy-MM-dd hh:mm:ss a");
1186
+ * const ret4 = formatDate(new Date(2014, 1, 11), "MM/dd/yyyy");
1187
+ * console.log("Default formatDate value:", ret1);
1188
+ * console.log("String formatDate value:", ret2);
1189
+ * console.log("Number formatDate value:", ret3);
1190
+ * console.log("Date formatDate value:", ret4);
1191
+ * ```
1192
+ *
1193
+ * Output:
1194
+ *
1195
+ * ```text
1196
+ * Default formatDate value: 2023-01-11
1197
+ * String formatDate value: 2022-01-11 02:12:26 PM
1198
+ * Number formatDate value: 2022-01-11 02:07:15 PM
1199
+ * Date formatDate value: 02/11/2014
1200
+ * ```
1201
+ *
1202
+ * @param {MazeyDate} dateIns Original Date
1203
+ * @param {string} format Format String
1204
+ * @returns {string} Return the formatted date string.
1205
+ * @category Util
1206
+ */
1207
+ declare function formatDate(dateIns?: MazeyDate, format?: string): string;
1208
+ /**
1209
+ * Check if the given string is a mobile phone number.
1210
+ *
1211
+ * Usage:
1212
+ *
1213
+ * ```javascript
1214
+ * import { isMobile } from "mazey";
1215
+ *
1216
+ * const ret1 = isMobile("13800138000");
1217
+ * const ret2 = isMobile("1380013800");
1218
+ * const ret3 = isMobile("138001380000");
1219
+ * const ret4 = isMobile("1380013800a");
1220
+ * console.log(ret1, ret2, ret3, ret4);
1221
+ * ```
1222
+ *
1223
+ * Output:
1224
+ *
1225
+ * ```text
1226
+ * true false false false
1227
+ * ```
1228
+ *
1229
+ * @param mobile
1230
+ * @returns {boolean} Return true if the given string is a mobile phone number.
1231
+ * @category Util
1232
+ */
1233
+ declare function isValidPhoneNumber(mobile: string): boolean;
1234
+ /**
1235
+ * Check if the given string is a valid email.
1236
+ *
1237
+ * Usage:
1238
+ *
1239
+ * ```javascript
1240
+ * import { isValidEmail } from "mazey";
1241
+ *
1242
+ * const ret = isValidEmail("mazeyqian@gmail.com");
1243
+ * console.log(ret);
1244
+ * ```
1245
+ *
1246
+ * Output:
1247
+ *
1248
+ * ```text
1249
+ * true
1250
+ * ```
1251
+ *
1252
+ * @param email
1253
+ * @returns {boolean} Return true if the given string is a valid email.
1254
+ * @category Util
1255
+ */
1256
+ declare function isValidEmail(email: string): boolean;
1257
+ /**
1258
+ * Convert a given 10-hex number to a lowercase 26-hex string.
1259
+ *
1260
+ * Usage:
1261
+ *
1262
+ * ```javascript
1263
+ * import { convert10To26 } from "mazey";
1264
+ *
1265
+ * const ret1 = convert10To26(1);
1266
+ * const ret2 = convert10To26(26);
1267
+ * const ret3 = convert10To26(27);
1268
+ * const ret4 = convert10To26(52);
1269
+ * const ret5 = convert10To26(53);
1270
+ * console.log(ret1, ret2, ret3, ret4, ret5);
1271
+ * ```
1272
+ *
1273
+ * Output:
1274
+ *
1275
+ * ```text
1276
+ * a z aa az ba
1277
+ * ```
1278
+ *
1279
+ * @param {number} num
1280
+ * @returns {string} Return a lowercase 26-hex string.
1281
+ * @category Util
1282
+ */
1283
+ declare function convert10To26(num: number): string;
1284
+ /**
1285
+ * Get the current version.
1286
+ *
1287
+ * @hidden
1288
+ */
1289
+ declare function getCurrentVersion(): string;
1290
+ /**
1291
+ * Repeatedly fires a callback function with a certain interval until a specified condition is met.
1292
+ *
1293
+ * Usage:
1294
+ *
1295
+ * ```javascript
1296
+ * import { repeatUntilConditionMet } from "mazey";
1297
+ *
1298
+ * repeatUntilConditionMet(
1299
+ * () => {
1300
+ * console.log("repeatUntilConditionMet");
1301
+ * return true;
1302
+ * }, {
1303
+ * interval: 1000,
1304
+ * times: 10,
1305
+ * context: null,
1306
+ * args: [],
1307
+ * }, (result) => {
1308
+ * return result === true;
1309
+ * }
1310
+ * );
1311
+ * ```
1312
+ *
1313
+ * @param callback The callback function to fire.
1314
+ * @param options An object containing the options for the function.
1315
+ * @param options.interval The interval between each firing of the callback function, in milliseconds. Defaults to 1000.
1316
+ * @param options.times The maximum number of times to fire the callback function. Defaults to 10.
1317
+ * @param options.context The context to use when calling the callback function. Defaults to null.
1318
+ * @param options.args An array of arguments to pass to the callback function.
1319
+ * @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.
1320
+ * @category Util
1321
+ */
1322
+ declare function repeatUntilConditionMet<T extends (...args: MazeyFnParams) => MazeyFnReturn>(callback: T, options?: RepeatUntilOptions, condition?: (result: ReturnType<T>) => boolean): void;
1323
+ /**
1324
+ * Wait for a specified amount of time.
1325
+ *
1326
+ * Usage:
1327
+ *
1328
+ * ```javascript
1329
+ * import { waitTime } from "mazey";
1330
+ *
1331
+ * waitTime(1000).then((time) => {
1332
+ * console.log("waitTime:", time);
1333
+ * });
1334
+ * ```
1335
+ *
1336
+ * Output:
1337
+ *
1338
+ * ```text
1339
+ * waitTime: 1000
1340
+ * ```
1341
+ *
1342
+ * @param time The amount of time to wait, in milliseconds.
1343
+ * @returns A Promise that resolves after the specified time has elapsed.
1344
+ * @category Util
1345
+ */
1346
+ declare function waitTime(time: number): Promise<number>;
1347
+ /**
1348
+ * Alias of `waitTime`.
1349
+ *
1350
+ * @hidden
1351
+ */
1352
+ declare function sleep(time: number): Promise<number>;
1353
+ /**
1354
+ * Determine if it is a browser environment.
1355
+ *
1356
+ * Usage:
1357
+ *
1358
+ * ```javascript
1359
+ * import { isBrowser } from "mazey";
1360
+ *
1361
+ * const ret = isBrowser();
1362
+ * console.log(ret);
1363
+ * ```
1364
+ *
1365
+ * Output:
1366
+ *
1367
+ * ```text
1368
+ * true
1369
+ * ```
1370
+ *
1371
+ * @returns {boolean} true Yes
1372
+ * @category Browser Information
1373
+ */
1374
+ declare function isBrowser(): boolean;
1375
+
1376
+ /**
1377
+ * Get the query param's value of the current Web URL(`location.search`).
1378
+ *
1379
+ * Usage:
1380
+ *
1381
+ * ```javascript
1382
+ * import { getQueryParam } from "mazey";
1383
+ *
1384
+ * // http://example.com/?t1=1&t2=2&t3=3&t4=4#2333
1385
+ * // ?t1=1&t2=2&t3=3&t4=4
1386
+ * const p1 = getQueryParam("t3");
1387
+ * const p2 = getQueryParam("t4");
1388
+ * console.log(p1, p2);
1389
+ * ```
1390
+ *
1391
+ * Output:
1392
+ *
1393
+ * ```text
1394
+ * 3 4
1395
+ * ```
1396
+ *
1397
+ * @param {string} param Query param.
1398
+ * @returns {string} value
1399
+ * @category URL
1400
+ */
1401
+ declare function getQueryParam(param: string): string;
1402
+ /**
1403
+ * Get the all query params of the current Web URL(`location.search`).
1404
+ *
1405
+ * Usage:
1406
+ *
1407
+ * ```javascript
1408
+ * import { getAllQueryParams } from "mazey";
1409
+ *
1410
+ * // http://example.com/?t1=1&t2=2&t3=3&t4=4#2333
1411
+ * // ?t1=1&t2=2&t3=3&t4=4
1412
+ * const ret = getAllQueryParams();
1413
+ * console.log(ret);
1414
+ * ```
1415
+ *
1416
+ * Output:
1417
+ *
1418
+ * ```text
1419
+ * { t1: "1", t2: "2", t3: "3", t4: "4" }
1420
+ * ```
1421
+ *
1422
+ * @param {string} url Optional, The URL string.
1423
+ * @returns {object} The query params object.
1424
+ * @category URL
1425
+ */
1426
+ declare function getAllQueryParams(url?: string): SingleValueUrlParams;
1427
+ /**
1428
+ * Returns the value of the specified query parameter in the input URL.
1429
+ *
1430
+ * Usage:
1431
+ *
1432
+ * ```javascript
1433
+ * import { getUrlParam } from "mazey";
1434
+ *
1435
+ * const p1 = getUrlParam("http://example.com/?t1=1&t2=2&t3=3&t4=4", "t3");
1436
+ * const p2 = getUrlParam("http://example.com/?t1=1&t2=2&t3=3&t4=4", "t4");
1437
+ * console.log(p1, p2);
1438
+ * ```
1439
+ *
1440
+ * Output:
1441
+ *
1442
+ * ```text
1443
+ * 3 4
1444
+ * ```
1445
+ *
1446
+ * @param {string} url The URL string.
1447
+ * @param {string} param The query parameter to retrieve the value for.
1448
+ * @param {object} options The options object.
1449
+ * @param {boolean} options.returnArray Whether to return an array of values for the specified query parameter. Default is false.
1450
+ * @returns {string|string[]} The value of the specified query parameter, or an empty string if the parameter is not found.
1451
+ * @category URL
1452
+ */
1453
+ declare function getUrlParam(url: string, param: string, options?: {
1454
+ returnArray?: boolean;
1455
+ }): string | string[] | null;
1456
+ /**
1457
+ * Update the query param's value of the input URL.
1458
+ *
1459
+ * Usage:
1460
+ *
1461
+ * ```javascript
1462
+ * import { updateQueryParam } from "mazey";
1463
+ *
1464
+ * const ret1 = updateQueryParam("http://example.com/?t1=1&t2=2&t3=3&t4=4", "t3", "three");
1465
+ * const ret2 = updateQueryParam("http://example.com/?t1=1&t2=2&t3=3&t4=4", "t4", "four");
1466
+ * console.log(ret1);
1467
+ * console.log(ret2);
1468
+ * ```
1469
+ *
1470
+ * Output:
1471
+ *
1472
+ * ```text
1473
+ * http://example.com/?t1=1&t2=2&t3=three&t4=4
1474
+ * http://example.com/?t1=1&t2=2&t3=3&t4=four
1475
+ * ```
1476
+ *
1477
+ * @param {string} url URL string.
1478
+ * @param {string} param Query param.
1479
+ * @param {string} value Param's value.
1480
+ * @returns {string} URL.
1481
+ * @category URL
1482
+ */
1483
+ declare function updateQueryParam(url: string, param: string, value: string): string;
1484
+ /**
1485
+ * Get the hash query param's value of the current Web URL(`location.hash`).
1486
+ *
1487
+ * Usage:
1488
+ *
1489
+ * ```javascript
1490
+ * import { getHashQueryParam } from "mazey";
1491
+ *
1492
+ * // http://example.com/?#2333?t1=1&t2=2&t3=3&t4=4
1493
+ * // #2333?t1=1&t2=2&t3=3&t4=4
1494
+ * const p1 = getHashQueryParam("t3");
1495
+ * const p2 = getHashQueryParam("t4");
1496
+ * console.log(p1, p2);
1497
+ * ```
1498
+ *
1499
+ * Output:
1500
+ *
1501
+ * ```text
1502
+ * 3 4
1503
+ * ```
1504
+ *
1505
+ * @param {string} param Query param.
1506
+ * @returns {string} value
1507
+ * @category URL
1508
+ */
1509
+ declare function getHashQueryParam(param: string): string;
1510
+ /**
1511
+ * Get the domain of URL, and other params.
1512
+ *
1513
+ * Usage:
1514
+ *
1515
+ * ```javascript
1516
+ * import { getDomain } from "mazey";
1517
+ *
1518
+ * const ret1 = getDomain("http://example.com/?t1=1&t2=2&t3=3&t4=4");
1519
+ * const ret2 = getDomain("http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4", ["hostname", "pathname"]);
1520
+ * const ret3 = getDomain("http://example.com:7890/test/thanks", ["hostname"]);
1521
+ * const ret4 = getDomain("http://example.com:7890/test/thanks", ["host"]); // With Port
1522
+ * const ret5 = getDomain("http://example.com:7890/test/thanks", ["origin"]);
1523
+ * const ret6 = getDomain("http://example.com:7890/test/thanks?id=1", ["origin", "pathname", "search"]);
1524
+ * console.log(ret1);
1525
+ * console.log(ret2);
1526
+ * console.log(ret3);
1527
+ * console.log(ret4);
1528
+ * console.log(ret5);
1529
+ * console.log(ret6);
1530
+ * ```
1531
+ *
1532
+ * Output:
1533
+ *
1534
+ * ```text
1535
+ * example.com
1536
+ * example.com/test/thanks
1537
+ * example.com
1538
+ * example.com:7890
1539
+ * http://example.com:7890
1540
+ * http://example.com:7890/test/thanks?id=1
1541
+ * ```
1542
+ *
1543
+ * @param {string} url
1544
+ * @param {array} rules Object.keys(location), ["href", "origin", "protocol", "host", "hostname", "port", "pathname", "search", "hash"], ["hostname", "pathname"] = "km.mazey.net/plugins/servlet/mobile"
1545
+ * @category URL
1546
+ */
1547
+ declare function getDomain(url: string, rules?: string[]): string;
1548
+ /**
1549
+ * Checks if the given string is a valid URL, including **scheme URLs**.
1550
+ *
1551
+ * Usage:
1552
+ *
1553
+ * ```javascript
1554
+ * import { isValidUrl } from "mazey";
1555
+ *
1556
+ * const ret1 = isValidUrl("https://www.example.com");
1557
+ * const ret2 = isValidUrl("http://example.com/path/exx/ss");
1558
+ * const ret3 = isValidUrl("https://www.example.com/?q=hello&age=24#world");
1559
+ * const ret4 = isValidUrl("http://www.example.com/#world?id=9");
1560
+ * const ret5 = isValidUrl("ftp://example.com");
1561
+ * console.log(ret1, ret2, ret3, ret4, ret5);
1562
+ * ```
1563
+ *
1564
+ * Output:
1565
+ *
1566
+ * ```text
1567
+ * true true true true true
1568
+ * ```
1569
+ *
1570
+ * @remarks
1571
+ * If you are specifically checking for HTTP/HTTPS URLs, it is recommended to use the `isValidHttpUrl` function instead.
1572
+ * The `isValidUrl` function matches all scheme URLs, including FTP and other non-HTTP schemes.
1573
+ *
1574
+ * @param url - The URL to check.
1575
+ * @returns Returns `true` if the given string is a valid URL, else `false`.
1576
+ * @category URL
1577
+ */
1578
+ declare function isValidUrl(url: string): boolean;
1579
+ /**
1580
+ * Check if the given string is a valid HTTP/HTTPS URL.
1581
+ *
1582
+ * Usage:
1583
+ *
1584
+ * ```javascript
1585
+ * import { isValidHttpUrl } from "mazey";
1586
+ *
1587
+ * const ret1 = isValidHttpUrl("https://www.example.com");
1588
+ * const ret2 = isValidHttpUrl("http://example.com/path/exx/ss");
1589
+ * const ret3 = isValidHttpUrl("https://www.example.com/?q=hello&age=24#world");
1590
+ * const ret4 = isValidHttpUrl("http://www.example.com/#world?id=9");
1591
+ * const ret5 = isValidHttpUrl("//example.com/a/b/c?q=1", { strict: false });
1592
+ * const ret6 = isValidHttpUrl("ftp://example.com");
1593
+ * console.log(ret1, ret2, ret3, ret4, ret5, ret6);
1594
+ * ```
1595
+ *
1596
+ * Output:
1597
+ *
1598
+ * ```text
1599
+ * true true true true true false
1600
+ * ```
1601
+ *
1602
+ * @param url
1603
+ * @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`.
1604
+ * @returns {boolean} Return true if the given string is a valid HTTP/HTTPS URL.
1605
+ * @category URL
1606
+ */
1607
+ declare function isValidHttpUrl(url: string, options?: {
1608
+ strict: boolean;
1609
+ }): boolean;
1610
+ /**
1611
+ * EN: Get the file type of the url.
1612
+ *
1613
+ * ZH: 获取文件后缀名。
1614
+ *
1615
+ * Usage:
1616
+ *
1617
+ * ```javascript
1618
+ * import { getUrlFileType } from "mazey";
1619
+ *
1620
+ * const ret1 = getUrlFileType("https://example.com/a/b/c.png");
1621
+ * const ret2 = getUrlFileType("https://example.com/a/b/c.jpg");
1622
+ * const ret3 = getUrlFileType("https://example.com/a/b/c.jpeg");
1623
+ * const ret4 = getUrlFileType("/a/b/c.jpeg");
1624
+ * const ret5 = getUrlFileType("https://example.com/a/b/c.v/a");
1625
+ * console.log(ret1, ret2, ret3, ret4, ret5);
1626
+ * ```
1627
+ *
1628
+ * Output:
1629
+ *
1630
+ * ```text
1631
+ * png jpg jpeg jpeg ""
1632
+ * ```
1633
+ *
1634
+ * @param url
1635
+ * @returns
1636
+ * @category URL
1637
+ */
1638
+ declare function getUrlFileType(url: string): boolean | string;
1639
+ /**
1640
+ * Retrieve a query parameter from a script URL in the browser.
1641
+ *
1642
+ * Usage:
1643
+ *
1644
+ * ```html
1645
+ * <script src="https://example.com/example.js?test=hello&name=mazey"></script>
1646
+ * ```
1647
+ *
1648
+ * ```javascript
1649
+ * import { getScriptQueryParam } from "mazey";
1650
+ *
1651
+ * const ret = getScriptQueryParam("test", "https://example.com/example.js");
1652
+ * console.log(ret);
1653
+ * ```
1654
+ *
1655
+ * Output:
1656
+ *
1657
+ * ```text
1658
+ * hello
1659
+ * ```
1660
+ *
1661
+ * @param param - The name of the query parameter to retrieve.
1662
+ * @param matchString - An optional substring to match in the script URL.
1663
+ * If not provided, defaults to matching the ".js" substring.
1664
+ * @returns The decoded value of the specified query parameter, or an empty string if no matching parameter is found.
1665
+ * @category URL
1666
+ */
1667
+ declare function getScriptQueryParam(param: string, matchString?: string): string;
1668
+ /**
1669
+ * Convert an object to a query string.
1670
+ *
1671
+ * Usage:
1672
+ *
1673
+ * ```javascript
1674
+ * import { convertObjectToQuery } from "mazey";
1675
+ *
1676
+ * const ret = convertObjectToQuery({ t1: "1", t2: "2", t3: "3", t4: "4" });
1677
+ * console.log(ret);
1678
+ * ```
1679
+ *
1680
+ * Output:
1681
+ *
1682
+ * ```text
1683
+ * ?t1=1&t2=2&t3=3&t4=4
1684
+ * ```
1685
+ *
1686
+ * @param obj - The object to convert to a query string.
1687
+ * @returns The query string.
1688
+ * @category URL
1689
+ */
1690
+ declare function convertObjectToQuery(obj: {
1691
+ [key: string]: string;
1692
+ }): string;
1693
+ /**
1694
+ * Convert an HTTP URL to an HTTPS URL.
1695
+ *
1696
+ * Usage:
1697
+ *
1698
+ * ```javascript
1699
+ * import { convertHttpToHttps } from "mazey";
1700
+ *
1701
+ * const ret = convertHttpToHttps("http://example.com");
1702
+ * console.log(ret);
1703
+ * ```
1704
+ *
1705
+ * Output:
1706
+ *
1707
+ * ```text
1708
+ * https://example.com
1709
+ * ```
1710
+ *
1711
+ * @param url - The HTTP URL to convert to HTTPS.
1712
+ * @returns The HTTPS URL.
1713
+ * @category URL
1714
+ */
1715
+ declare function convertHttpToHttps(url: string): string;
1716
+ /**
1717
+ * Alias of `convertHttpToHttps`.
1718
+ *
1719
+ * @hidden
1720
+ */
1721
+ declare function replaceHttp(url: string): string;
1722
+ /**
1723
+ * Get the host of the URL.
1724
+ *
1725
+ * Usage:
1726
+ *
1727
+ * ```javascript
1728
+ * import { getUrlHost } from "mazey";
1729
+ *
1730
+ * const ret = getUrlHost("https://example.com/path/to/page");
1731
+ * console.log(ret);
1732
+ * ```
1733
+ *
1734
+ * Output:
1735
+ *
1736
+ * ```text
1737
+ * example.com
1738
+ * ```
1739
+ *
1740
+ * @param url - The URL to get the host from.
1741
+ * @returns The host of the URL.
1742
+ * @category URL
1743
+ */
1744
+ declare function getUrlHost(url: string): string;
1745
+ /**
1746
+ * Get the path of the URL.
1747
+ *
1748
+ * Usage:
1749
+ *
1750
+ * ```javascript
1751
+ * import { getUrlPath } from "mazey";
1752
+ *
1753
+ * const ret = getUrlPath("https://example.com/path/to/page");
1754
+ * console.log(ret);
1755
+ * ```
1756
+ *
1757
+ * Output:
1758
+ *
1759
+ * ```text
1760
+ * /path/to/page
1761
+ * ```
1762
+ *
1763
+ * @param url - The URL to get the path from.
1764
+ * @returns The path of the URL.
1765
+ * @category URL
1766
+ */
1767
+ declare function getUrlPath(url: string): string;
1768
+ /**
1769
+ * Listen to URL changes from:
1770
+ * - back/forward navigation
1771
+ * - hash changes
1772
+ * - history.pushState / history.replaceState
1773
+ *
1774
+ * @param callback - Called with current URL, previous URL, and trigger source.
1775
+ * @param options - { fireOnInit?: boolean } default true.
1776
+ * @returns unsubscribe function
1777
+ *
1778
+ * @category URL
1779
+ */
1780
+ declare function onURLChange(callback: (info: URLChangeInfo) => void, options?: OnURLChangeOptions): () => void;
1781
+
1782
+ /**
1783
+ * Modify `class`: determine `class`.
1784
+ *
1785
+ * Usage:
1786
+ *
1787
+ * ```javascript
1788
+ * import { hasClass, addClass, removeClass } from "mazey";
1789
+ *
1790
+ * const dom = document.querySelector("#box");
1791
+ * // Determine `class`
1792
+ * hasClass(dom, "test");
1793
+ * // Add `class`
1794
+ * addClass(dom, "test");
1795
+ * // Remove `class`
1796
+ * removeClass(dom, "test");
1797
+ * ```
1798
+ *
1799
+ * @category DOM
1800
+ */
1801
+ declare function hasClass(obj: MazeyElement, cls: string): boolean;
1802
+ /**
1803
+ * Add `class` to the element. The second parameter can be a single class name or an array of class names.
1804
+ *
1805
+ * Basic Usage:
1806
+ *
1807
+ * ```javascript
1808
+ * import { addClass } from "mazey";
1809
+ *
1810
+ * const ele = document.querySelector("#box");
1811
+ * addClass(ele, "test");
1812
+ * ```
1813
+ *
1814
+ * Output:
1815
+ *
1816
+ * ```html
1817
+ * <div id="box" class="test"></div>
1818
+ * ```
1819
+ *
1820
+ * Advanced Usage:
1821
+ *
1822
+ * ```javascript
1823
+ * import { addClass, genBrowserAttrs } from "mazey";
1824
+ *
1825
+ * const ele = document.querySelector("html");
1826
+ * addClass(ele, genBrowserAttrs());
1827
+ * ```
1828
+ *
1829
+ * Output:
1830
+ *
1831
+ * ```html
1832
+ * <html class="windows desktop webkit chrome"></html>
1833
+ * ```
1834
+ *
1835
+ * @category DOM
1836
+ */
1837
+ declare function addClass(ele: MazeyElement, cls: string | string[]): void;
1838
+ /**
1839
+ * Alias of `addClass`.
1840
+ *
1841
+ * @hidden
1842
+ */
1843
+ declare function setClass(ele: HTMLElement, cls: string): void;
1844
+ /**
1845
+ * Modify `class`: remove `class`.
1846
+ *
1847
+ * Usage:
1848
+ *
1849
+ * ```javascript
1850
+ * import { hasClass, addClass, removeClass } from "mazey";
1851
+ *
1852
+ * const dom = document.querySelector("#box");
1853
+ * // Determine `class`
1854
+ * hasClass(dom, "test");
1855
+ * // Add `class`
1856
+ * addClass(dom, "test");
1857
+ * // Remove `class`
1858
+ * removeClass(dom, "test");
1859
+ * ```
1860
+ *
1861
+ * @category DOM
1862
+ */
1863
+ declare function removeClass(obj: MazeyElement, cls: string): void;
1864
+ /**
1865
+ * EN: Add `<style>` in `<head>`.
1866
+ *
1867
+ * ZH: 添加样式标签; style: 样式标签内的字符串; id: `<style>` 标签的 `id`; 返回: 添加成功/失败。
1868
+ *
1869
+ * Usage:
1870
+ *
1871
+ * Example 1: Add the `<style>` with `id`, and repeated invoking will update the content instead of adding a new one.
1872
+ *
1873
+ * ```javascript
1874
+ * import { addStyle } from "mazey";
1875
+ *
1876
+ * addStyle(
1877
+ * "body { background-color: #333; }",
1878
+ * { id: "test" }
1879
+ * );
1880
+ * ```
1881
+ *
1882
+ * Output:
1883
+ *
1884
+ * ```html
1885
+ * <style id="test">body { background-color: #333; }</style>
1886
+ * ```
1887
+ *
1888
+ * Example 2: Add the `<style>` without `id`, and repeated invoking will add a new one.
1889
+ *
1890
+ * ```javascript
1891
+ * import { addStyle } from "mazey";
1892
+ *
1893
+ * addStyle("body { background-color: #444; }");
1894
+ * ```
1895
+ *
1896
+ * Output:
1897
+ *
1898
+ * ```html
1899
+ * <style>body { background-color: #444; }</style>
1900
+ * ```
1901
+ *
1902
+ * Example 3: Combine `genStyleString` and `addStyle` to add multiple styles at once.
1903
+ *
1904
+ * ```javascript
1905
+ * import { genStyleString, addStyle } from "mazey";
1906
+ *
1907
+ * const xStyle = genStyleString(
1908
+ * ".footer>.x-wish>a:first-child" +
1909
+ * ",div.wish-flex>a[href^='https://github.com/chengchuu']" +
1910
+ * ",.m-hide",
1911
+ * [ "display: none" ]
1912
+ * );
1913
+ * const yStyle = genStyleString(
1914
+ * ".footer>.y-wish:before",
1915
+ * [
1916
+ * `content: 'Copyright (c) chengchuu'`,
1917
+ * "color: inherit",
1918
+ * "padding-inline-start: var(--y-wish-1_5)",
1919
+ * "padding-inline-end: var(--y-wish-1_5)",
1920
+ * "padding-top: var(--y-wish-1)",
1921
+ * "padding-bottom: var(--y-wish-1)",
1922
+ * ]
1923
+ * );
1924
+ * addStyle(xStyle + yStyle, { id: "z-style" });
1925
+ * ```
1926
+ *
1927
+ * Output:
1928
+ *
1929
+ * ```html
1930
+ * <style id="z-style">.footer>.x-wish>a:first-child,div.wish-flex>a[href^='https://github.com/chengchuu'],.m-hide{display: none;}.footer>.y-wish:before{content: 'Copyright (c) chengchuu';color: inherit;padding-inline-start: var(--y-wish-1_5);padding-inline-end: var(--y-wish-1_5);padding-top: var(--y-wish-1);padding-bottom: var(--y-wish-1);}</style>
1931
+ * ```
1932
+ *
1933
+ * @category DOM
1934
+ */
1935
+ declare function addStyle(style: string, options?: {
1936
+ id?: string;
1937
+ }): boolean;
1938
+ /**
1939
+ * Sets the width and height of all images on the page based on their `src` attribute.
1940
+ * The `src` attribute should contain `width` and/or `height` values in the format "width=100" or "height=100".
1941
+ * If jQuery is available, this function uses jQuery to select the images. Otherwise, it uses pure JavaScript.
1942
+ *
1943
+ * Usage:
1944
+ *
1945
+ * ```html
1946
+ * <img src="image.jpg?width=100px&height=200px">
1947
+ * ```
1948
+ *
1949
+ * ```javascript
1950
+ * import { setImgSizeBySrc } from "mazey";
1951
+ *
1952
+ * setImgSizeBySrc();
1953
+ * ```
1954
+ *
1955
+ * Output:
1956
+ *
1957
+ * ```html
1958
+ * <img src="image.jpg?width=100px&height=200px" width="100px" height="200px">
1959
+ * ```
1960
+ *
1961
+ * @returns {boolean} - Returns `true` if images were found and their dimensions were set, otherwise `false`.
1962
+ * @category DOM
1963
+ */
1964
+ declare function setImgSizeBySrc(): boolean;
1965
+ /**
1966
+ * Alias of `setImgSizeBySrc`.
1967
+ *
1968
+ * @hidden
1969
+ */
1970
+ declare function setImgWidHeiBySrc(): boolean;
1971
+ /**
1972
+ * Generate the inline style string from the given parameters. The first parameter is the query selector, and the second parameter is the style array.
1973
+ *
1974
+ * Usage:
1975
+ *
1976
+ * ```javascript
1977
+ * const ret1 = genStyleString(".a", [ "color:red" ]);
1978
+ * const ret2 = genStyleString("#b", [ "color:red", "font-size:12px" ]);
1979
+ * console.log(ret1);
1980
+ * console.log(ret2);
1981
+ * ```
1982
+ *
1983
+ * Output:
1984
+ *
1985
+ * ```text
1986
+ * .a{color:red;}
1987
+ * #b{color:red;font-size:12px;}
1988
+ * ```
1989
+ *
1990
+ * Example: Combine `genStyleString` and `addStyle` to add multiple styles at once.
1991
+ *
1992
+ * ```javascript
1993
+ * import { genStyleString, addStyle } from "mazey";
1994
+ *
1995
+ * const xStyle = genStyleString(
1996
+ * ".footer>.x-wish>a:first-child" +
1997
+ * ",div.wish-flex>a[href^='https://github.com/chengchuu']" +
1998
+ * ",.m-hide",
1999
+ * [ "display: none" ]
2000
+ * );
2001
+ * const yStyle = genStyleString(
2002
+ * ".footer>.y-wish:before",
2003
+ * [
2004
+ * `content: 'Copyright (c) chengchuu'`,
2005
+ * "color: inherit",
2006
+ * "padding-inline-start: var(--y-wish-1_5)",
2007
+ * "padding-inline-end: var(--y-wish-1_5)",
2008
+ * "padding-top: var(--y-wish-1)",
2009
+ * "padding-bottom: var(--y-wish-1)",
2010
+ * ]
2011
+ * );
2012
+ * addStyle(xStyle + yStyle, { id: "z-style" });
2013
+ * ```
2014
+ *
2015
+ * Output:
2016
+ *
2017
+ * ```html
2018
+ * <style id="z-style">.footer>.x-wish>a:first-child,div.wish-flex>a[href^='https://github.com/chengchuu'],.m-hide{display: none;}.footer>.y-wish:before{content: 'Copyright (c) chengchuu';color: inherit;padding-inline-start: var(--y-wish-1_5);padding-inline-end: var(--y-wish-1_5);padding-top: var(--y-wish-1);padding-bottom: var(--y-wish-1);}</style>
2019
+ * ```
2020
+ *
2021
+ * @param {string} selector
2022
+ * @param {array} styleArray
2023
+ * @returns {string} The inline style string.
2024
+ * @category DOM
2025
+ */
2026
+ declare function genStyleString(selector: string, styleArray: Array<string>): string;
2027
+ /**
2028
+ * Get the value of the meta tag by the given name.
2029
+ *
2030
+ * Usage:
2031
+ *
2032
+ * ```html
2033
+ * <meta name="keywords" content="mazey,web,frontend">
2034
+ * ```
2035
+ *
2036
+ * ```javascript
2037
+ * import { getPageMeta } from "mazey";
2038
+ *
2039
+ * const keywords = getPageMeta("keywords");
2040
+ * console.log(keywords);
2041
+ * ```
2042
+ *
2043
+ * Output:
2044
+ *
2045
+ * ```text
2046
+ * mazey,web,frontend
2047
+ * ```
2048
+ *
2049
+ * @param {string} name - The name of the meta tag.
2050
+ * @returns {string} The content of the meta tag.
2051
+ * @category DOM
2052
+ */
2053
+ declare function getPageMeta(name: string): string;
2054
+
2055
+ /**
2056
+ * Prevent bubbling.
2057
+ *
2058
+ * Usage:
2059
+ *
2060
+ * ```javascript
2061
+ * import { cancelBubble } from "mazey";
2062
+ *
2063
+ * const ret1 = cancelBubble(e);
2064
+ * ```
2065
+ *
2066
+ * @category Event
2067
+ */
2068
+ declare function cancelBubble(e: Event): void;
2069
+ /**
2070
+ * Get the defined listeners.
2071
+ *
2072
+ * Usage:
2073
+ *
2074
+ * ```javascript
2075
+ * import { getDefineListeners } from "mazey";
2076
+ *
2077
+ * const ret = getDefineListeners();
2078
+ * console.log(ret);
2079
+ * ```
2080
+ *
2081
+ * Output:
2082
+ *
2083
+ * ```text
2084
+ * {}
2085
+ * ```
2086
+ *
2087
+ * @category Event
2088
+ * @hidden
2089
+ */
2090
+ declare function getDefineListeners(): DefineListeners;
2091
+ /**
2092
+ * Add event.
2093
+ *
2094
+ * Usage:
2095
+ *
2096
+ * ```javascript
2097
+ * import { addEvent } from "mazey";
2098
+ *
2099
+ * addEvent("test", (e) => {
2100
+ * console.log("test event:", e);
2101
+ * });
2102
+ * fireEvent("test");
2103
+ * ```
2104
+ *
2105
+ * Output:
2106
+ *
2107
+ * ```javascript
2108
+ * test event: { type: "test" }
2109
+ * ```
2110
+ *
2111
+ * @param type
2112
+ * @param fn
2113
+ * @category Event
2114
+ */
2115
+ declare function addEvent(type: string, fn: MazeyFn): void;
2116
+ /**
2117
+ * Fire/Invoke event.
2118
+ *
2119
+ * Usage:
2120
+ *
2121
+ * ```javascript
2122
+ * import { fireEvent } from "mazey";
2123
+ *
2124
+ * fireEvent("test");
2125
+ * ```
2126
+ *
2127
+ * @param type The event type.
2128
+ * @param params The event parameters.
2129
+ * @category Event
2130
+ */
2131
+ declare function fireEvent(type: string, params?: MazeyObject): void;
2132
+ /**
2133
+ * Alias of `fireEvent`.
2134
+ *
2135
+ * @hidden
2136
+ */
2137
+ declare function invokeEvent(type: string): void;
2138
+ /**
2139
+ * Remove event.
2140
+ *
2141
+ * Usage:
2142
+ *
2143
+ * ```javascript
2144
+ * import { removeEvent } from "mazey";
2145
+ *
2146
+ * removeEvent("test");
2147
+ * ```
2148
+ *
2149
+ * @param type
2150
+ * @param fn
2151
+ * @category Event
2152
+ */
2153
+ declare function removeEvent(type: string, fn: MazeyFn): void;
2154
+
2155
+ /**
2156
+ * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
2157
+ *
2158
+ * ZH: 存储/获取数据到 sessionStorage/localStorage。
2159
+ *
2160
+ * Usage:
2161
+ *
2162
+ * ```javascript
2163
+ * import { setSessionStorage, getSessionStorage, setLocalStorage, getLocalStorage } from "mazey";
2164
+ *
2165
+ * setSessionStorage("test", "123");
2166
+ * const ret1 = getSessionStorage("test");
2167
+ * setLocalStorage("test", "123");
2168
+ * const ret2 = getLocalStorage("test");
2169
+ * console.log(ret1, ret2);
2170
+ *
2171
+ * // or package in usage
2172
+ * const projectName = "mazey";
2173
+ * function mSetLocalStorage (key, value) {
2174
+ * return setLocalStorage(`${projectName}_${key}`, value);
2175
+ * }
2176
+ *
2177
+ * function mGetLocalStorage (key) {
2178
+ * return getLocalStorage(`${projectName}_${key}`);
2179
+ * }
2180
+ * ```
2181
+ *
2182
+ * Output:
2183
+ *
2184
+ * ```text
2185
+ * 123 123
2186
+ * ```
2187
+ *
2188
+ * @param {string} key 键
2189
+ * @returns {void} 返回值
2190
+ * @category Store
2191
+ */
2192
+ declare function setSessionStorage<T>(key: string, value?: T | null): void;
2193
+ /**
2194
+ * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
2195
+ *
2196
+ * ZH: 存储/获取数据到 sessionStorage/localStorage。
2197
+ *
2198
+ * Usage:
2199
+ *
2200
+ * ```javascript
2201
+ * import { setSessionStorage, getSessionStorage, setLocalStorage, getLocalStorage } from "mazey";
2202
+ *
2203
+ * setSessionStorage("test", "123");
2204
+ * const ret1 = getSessionStorage("test");
2205
+ * setLocalStorage("test", "123");
2206
+ * const ret2 = getLocalStorage("test");
2207
+ * console.log(ret1, ret2);
2208
+ *
2209
+ * // or package in usage
2210
+ * const projectName = "mazey";
2211
+ * function mSetLocalStorage (key, value) {
2212
+ * return setLocalStorage(`${projectName}_${key}`, value);
2213
+ * }
2214
+ *
2215
+ * function mGetLocalStorage (key) {
2216
+ * return getLocalStorage(`${projectName}_${key}`);
2217
+ * }
2218
+ * ```
2219
+ *
2220
+ * Output:
2221
+ *
2222
+ * ```text
2223
+ * 123 123
2224
+ * ```
2225
+ *
2226
+ * @param {string} key 键
2227
+ * @returns {any} 返回值
2228
+ * @category Store
2229
+ */
2230
+ declare function getSessionStorage<T>(key: string): T | null;
2231
+ /**
2232
+ * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
2233
+ *
2234
+ * ZH: 存储/获取数据到 sessionStorage/localStorage。
2235
+ *
2236
+ * Usage:
2237
+ *
2238
+ * ```javascript
2239
+ * import { setSessionStorage, getSessionStorage, setLocalStorage, getLocalStorage } from "mazey";
2240
+ *
2241
+ * setSessionStorage("test", "123");
2242
+ * const ret1 = getSessionStorage("test");
2243
+ * setLocalStorage("test", "123");
2244
+ * const ret2 = getLocalStorage("test");
2245
+ * console.log(ret1, ret2);
2246
+ *
2247
+ * // or package in usage
2248
+ * const projectName = "mazey";
2249
+ * function mSetLocalStorage (key, value) {
2250
+ * return setLocalStorage(`${projectName}_${key}`, value);
2251
+ * }
2252
+ *
2253
+ * function mGetLocalStorage (key) {
2254
+ * return getLocalStorage(`${projectName}_${key}`);
2255
+ * }
2256
+ * ```
2257
+ *
2258
+ * Output:
2259
+ *
2260
+ * ```text
2261
+ * 123 123
2262
+ * ```
2263
+ *
2264
+ * @param {string} key 键
2265
+ * @returns {void} 返回值
2266
+ * @category Store
2267
+ */
2268
+ declare function setLocalStorage<T>(key: string, value?: T | null): void;
2269
+ /**
2270
+ * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
2271
+ *
2272
+ * ZH: 存储/获取数据到 sessionStorage/localStorage。
2273
+ *
2274
+ * Usage:
2275
+ *
2276
+ * ```javascript
2277
+ * import { setSessionStorage, getSessionStorage, setLocalStorage, getLocalStorage } from "mazey";
2278
+ *
2279
+ * setSessionStorage("test", "123");
2280
+ * const ret1 = getSessionStorage("test");
2281
+ * setLocalStorage("test", "123");
2282
+ * const ret2 = getLocalStorage("test");
2283
+ * console.log(ret1, ret2);
2284
+ *
2285
+ * // or package in usage
2286
+ * const projectName = "mazey";
2287
+ * function mSetLocalStorage (key, value) {
2288
+ * return setLocalStorage(`${projectName}_${key}`, value);
2289
+ * }
2290
+ *
2291
+ * function mGetLocalStorage (key) {
2292
+ * return getLocalStorage(`${projectName}_${key}`);
2293
+ * }
2294
+ * ```
2295
+ *
2296
+ * Output:
2297
+ *
2298
+ * ```text
2299
+ * 123 123
2300
+ * ```
2301
+ *
2302
+ * @param {string} key 键
2303
+ * @returns {void} 返回值
2304
+ * @category Store
2305
+ */
2306
+ declare function getLocalStorage<T>(key: string): T | null;
2307
+ /**
2308
+ * EN: Handle Cookie.
2309
+ *
2310
+ * ZH: 设置/获取 Cookie。
2311
+ *
2312
+ * Usage:
2313
+ *
2314
+ * ```javascript
2315
+ * import { setCookie, getCookie } from "mazey";
2316
+ *
2317
+ * setCookie("test", "123", 30, "example.com"); // key value day domain
2318
+ * const ret = getCookie("test");
2319
+ * console.log(ret);
2320
+ * ```
2321
+ *
2322
+ * Output:
2323
+ *
2324
+ * ```text
2325
+ * 123
2326
+ * ```
2327
+ *
2328
+ * @category Store
2329
+ */
2330
+ declare function getCookie(name: string): string;
2331
+ /**
2332
+ * EN: Handle Cookie.
2333
+ *
2334
+ * ZH: 设置/获取 Cookie。
2335
+ *
2336
+ * Usage:
2337
+ *
2338
+ * ```javascript
2339
+ * import { setCookie, getCookie } from "mazey";
2340
+ *
2341
+ * setCookie("test", "123", 30, "example.com"); // key value day domain
2342
+ * const ret = getCookie("test");
2343
+ * console.log(ret);
2344
+ * ```
2345
+ *
2346
+ * Output:
2347
+ *
2348
+ * ```text
2349
+ * 123
2350
+ * ```
2351
+ *
2352
+ * @category Store
2353
+ */
2354
+ declare function setCookie(name: string, value: string, days?: number, domain?: string): void;
2355
+ /**
2356
+ * Delete a cookie by name.
2357
+ *
2358
+ * Usage:
2359
+ *
2360
+ * ```javascript
2361
+ * import { removeCookie } from "mazey";
2362
+ *
2363
+ * const ret = removeCookie("test");
2364
+ * console.log(ret);
2365
+ * ```
2366
+ *
2367
+ * Output:
2368
+ *
2369
+ * ```text
2370
+ * true
2371
+ * ```
2372
+ *
2373
+ * @param name - The name of the cookie to delete.
2374
+ * @returns `true` if the cookie was deleted successfully, `false` otherwise.
2375
+ * @category Store
2376
+ */
2377
+ declare function removeCookie(name: string): boolean;
2378
+ /**
2379
+ * Alias of `removeCookie`.
2380
+ *
2381
+ * @hidden
2382
+ */
2383
+ declare function delCookie(name: string): void;
2384
+
2385
+ /**
2386
+ * EN: Load a CSS file from the server.
2387
+ *
2388
+ * ZH: 动态加载 CSS 文件。
2389
+ *
2390
+ * Usage:
2391
+ *
2392
+ * ```javascript
2393
+ * import { loadCSS } from "mazey";
2394
+ *
2395
+ * loadCSS(
2396
+ * "http://example.com/path/example.css",
2397
+ * {
2398
+ * id: "iamid", // Optional, link ID, default none
2399
+ * }
2400
+ * )
2401
+ * .then(
2402
+ * res => {
2403
+ * console.log(`Load CSS Success: ${res}`);
2404
+ * }
2405
+ * )
2406
+ * .catch(
2407
+ * err => {
2408
+ * console.error(`Load CSS Fail: ${err.message}`)
2409
+ * }
2410
+ * );
2411
+ * ```
2412
+ *
2413
+ * Output:
2414
+ *
2415
+ * ```text
2416
+ * Load CSS Success: loaded
2417
+ * ```
2418
+ *
2419
+ * @param {string} url -- css资源路径
2420
+ * @param {string} options.id -- link标签id
2421
+ * @returns {Promise<string>} true -- 加载成功
2422
+ * @category Load
2423
+ */
2424
+ declare function loadCSS(url: string, options?: {
2425
+ id?: string;
2426
+ }): Promise<unknown>;
2427
+ /**
2428
+ * EN: Load a JavaScript file from the server and execute it.
2429
+ *
2430
+ * ZH: 动态加载 JavaScript 文件。
2431
+ *
2432
+ * Usage:
2433
+ *
2434
+ * ```javascript
2435
+ * import { loadScript } from "mazey";
2436
+ *
2437
+ * loadScript(
2438
+ * "http://example.com/static/js/plugin-2.1.1.min.js",
2439
+ * {
2440
+ * id: "iamid", // (Optional) script ID, default none
2441
+ * timeout: 5000, // (Optional) timeout, default `5000`
2442
+ * }
2443
+ * )
2444
+ * .then(
2445
+ * res => {
2446
+ * console.log(`Load JavaScript script: ${res}`);
2447
+ * }
2448
+ * )
2449
+ * .catch(
2450
+ * err => {
2451
+ * console.error(`Load JavaScript script: ${err.message}`);
2452
+ * }
2453
+ * );
2454
+ * ```
2455
+ *
2456
+ * Output:
2457
+ *
2458
+ * ```text
2459
+ * Load JavaScript script: loaded
2460
+ * ```
2461
+ *
2462
+ * @param {string} url -- JavaScript 资源路径
2463
+ * @param {string} options.id -- DOM ID
2464
+ * @param {function} options.callback -- 加载后回调函数
2465
+ * @param {number} options.timeout -- 超时时长
2466
+ * @param {boolean} options.isDefer -- 是否添加 defer 标签
2467
+ * @param {boolean} options.isAsync -- 是否添加 async 标签
2468
+ * @param {boolean} options.isCrossOrigin -- 是否跨域
2469
+ * @param {object} options.attributes -- 其他属性
2470
+ * @param {string} options.cssUrl -- CSS 资源路径
2471
+ * @returns {Promise<string>} -- true 成功
2472
+ * @category Load
2473
+ */
2474
+ declare function loadScript(url: string, options?: {
2475
+ id?: string;
2476
+ callback?: (...params: MazeyFnParams) => MazeyFnReturn;
2477
+ timeout?: number;
2478
+ isDefer?: boolean;
2479
+ isAsync?: boolean;
2480
+ isCrossOrigin?: boolean;
2481
+ attributes?: Record<string, string> | null;
2482
+ cssUrl?: string;
2483
+ }): LoadScriptReturns;
2484
+ /**
2485
+ * EN: Check whether the page is loaded successfully (Keep the compatibility if the browser's `load` event has been triggered).
2486
+ *
2487
+ * ZH: 页面加载完成。
2488
+ *
2489
+ * Usage:
2490
+ *
2491
+ * ```javascript
2492
+ * import { windowLoaded } from "mazey";
2493
+ *
2494
+ * windowLoaded()
2495
+ * .then(res => {
2496
+ * console.log(`Load Success: ${res}`);
2497
+ * })
2498
+ * .catch(err => {
2499
+ * console.log(`Load Timeout or Fail: ${err.message}`);
2500
+ * });
2501
+ * ```
2502
+ *
2503
+ * Output:
2504
+ *
2505
+ * ```text
2506
+ * Load Success: load
2507
+ * ```
2508
+ *
2509
+ * @param {number} timeout 超时时间 / 单位:毫秒,默认:30000(30 秒)
2510
+ * @returns {Promise<string>} document is loaded? "complete" "load" / "timeout"
2511
+ * @category Load
2512
+ */
2513
+ declare function windowLoaded(timeout?: number): Promise<string | Error>;
2514
+ /**
2515
+ * Load an image from the given URL.
2516
+ *
2517
+ * 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.
2518
+ *
2519
+ * Note that this method will not add the image to the DOM.
2520
+ *
2521
+ * Usage:
2522
+ *
2523
+ * ```javascript
2524
+ * import { loadImage } from "mazey";
2525
+ *
2526
+ * loadImage("https://example.com/example.png")
2527
+ * .then((img) => {
2528
+ * console.log(img);
2529
+ * })
2530
+ * .catch((err) => {
2531
+ * console.log(err);
2532
+ * });
2533
+ * ```
2534
+ *
2535
+ * @param {string} url - The URL of the image to load.
2536
+ * @returns {Promise} A Promise that resolves with the loaded image or rejects with an error.
2537
+ * @category Load
2538
+ */
2539
+ declare function loadImage(url: string): Promise<HTMLImageElement>;
2540
+ /**
2541
+ * Load a script from the given URL if it (`window["attribute"]`) has not already been loaded.
2542
+ *
2543
+ * Usage:
2544
+ *
2545
+ * ```javascript
2546
+ * import { loadScriptIfUndefined } from "mazey";
2547
+ *
2548
+ * loadScriptIfUndefined("xyz", "https://example.com/lib/xyz.min.js")
2549
+ * .then(() => {
2550
+ * console.log("xyz is loaded.");
2551
+ * })
2552
+ * .catch(err => {
2553
+ * console.log("Failed to load xyz.", err);
2554
+ * });
2555
+ * ```
2556
+ *
2557
+ * Output:
2558
+ *
2559
+ * ```text
2560
+ * xyz is loaded.
2561
+ * ```
2562
+ *
2563
+ * @param {string} windowAttribute - The name of the window attribute to check (e.g. `jQuery`, `axios`, etc.).
2564
+ * @param {string} url - The URL of the script to load.
2565
+ * @returns {Promise} A Promise that resolves when the script has been loaded.
2566
+ * @category Load
2567
+ */
2568
+ declare function loadScriptIfUndefined(windowAttribute: string, url: string): LoadScriptReturns;
2569
+
2570
+ /**
2571
+ * @hidden
2572
+ */
2573
+ declare function isSupportedEntryType(name: string): boolean;
2574
+ /**
2575
+ * Gets the first contentful paint (FCP) time of a web page using the Performance API.
2576
+ * The FCP time is the time it takes for the first piece of content to be painted on the screen.
2577
+ *
2578
+ * Usage:
2579
+ *
2580
+ * ```javascript
2581
+ * import { getFCP } from "mazey";
2582
+ *
2583
+ * getFCP().then(
2584
+ * res => {
2585
+ * console.log(`FCP: ${res}`);
2586
+ * }
2587
+ * );
2588
+ * ```
2589
+ *
2590
+ * Output:
2591
+ *
2592
+ * ```text
2593
+ * FCP: 123
2594
+ * ```
2595
+ *
2596
+ * @returns A promise that resolves with the FCP time in milliseconds, or 0 if the "paint" entry type is not supported.
2597
+ * @category Perf
2598
+ */
2599
+ declare function getFCP(): Promise<number>;
2600
+ /**
2601
+ * Gets the first paint (FP) time of a web page using the Performance API.
2602
+ * The FP time is the time it takes for the first pixel to be painted on the screen.
2603
+ *
2604
+ * Usage:
2605
+ *
2606
+ * ```javascript
2607
+ * import { getFP } from "mazey";
2608
+ *
2609
+ * getFP().then(
2610
+ * res => {
2611
+ * console.log(`FP: ${res}`);
2612
+ * }
2613
+ * );
2614
+ * ```
2615
+ *
2616
+ * Output:
2617
+ *
2618
+ * ```text
2619
+ * FP: 123
2620
+ * ```
2621
+ *
2622
+ * @returns A promise that resolves with the FP time in milliseconds, or 0 if the "paint" entry type is not supported.
2623
+ * @category Perf
2624
+ */
2625
+ declare function getFP(): Promise<number>;
2626
+ /**
2627
+ * Gets the largest contentful paint (LCP) time of a web page using the Performance API.
2628
+ * The LCP time is the time it takes for the largest piece of content to be painted on the screen.
2629
+ *
2630
+ * Usage:
2631
+ *
2632
+ * ```javascript
2633
+ * import { getLCP } from "mazey";
2634
+ *
2635
+ * getLCP().then(
2636
+ * res => {
2637
+ * console.log(`LCP: ${res}`);
2638
+ * }
2639
+ * );
2640
+ * ```
2641
+ *
2642
+ * Output:
2643
+ *
2644
+ * ```text
2645
+ * LCP: 123
2646
+ * ```
2647
+ *
2648
+ * @returns A promise that resolves with the LCP time in milliseconds, or 0 if the "largest-contentful-paint" entry type is not supported.
2649
+ * @category Perf
2650
+ */
2651
+ declare function getLCP(): Promise<number>;
2652
+ /**
2653
+ * Gets the first input delay (FID) of a web page using the Performance API.
2654
+ * The FID is the time it takes for the first user input to be processed by the browser.
2655
+ *
2656
+ * Usage:
2657
+ *
2658
+ * ```javascript
2659
+ * import { getFID } from "mazey";
2660
+ *
2661
+ * getFID().then(
2662
+ * res => {
2663
+ * console.log(`FID: ${res}`);
2664
+ * }
2665
+ * );
2666
+ * ```
2667
+ *
2668
+ * Output:
2669
+ *
2670
+ * ```text
2671
+ * FID: 123
2672
+ * ```
2673
+ *
2674
+ * @returns A promise that resolves with the FID in milliseconds, or 0 if the "first-input" entry type is not supported.
2675
+ * @category Perf
2676
+ */
2677
+ declare function getFID(): Promise<number>;
2678
+ /**
2679
+ * Gets the Cumulative Layout Shift (CLS) score of a web page using the Performance API.
2680
+ * The CLS score is a measure of how much the page layout shifts during loading.
2681
+ *
2682
+ * Usage:
2683
+ *
2684
+ * ```javascript
2685
+ * import { getCLS } from "mazey";
2686
+ *
2687
+ * getCLS().then(
2688
+ * res => {
2689
+ * console.log(`CLS: ${res}`);
2690
+ * }
2691
+ * );
2692
+ * ```
2693
+ *
2694
+ * Output:
2695
+ *
2696
+ * ```text
2697
+ * CLS: 123
2698
+ * ```
2699
+ *
2700
+ * @returns A promise that resolves with the CLS score, or 0 if the "layout-shift" entry type is not supported.
2701
+ * @category Perf
2702
+ */
2703
+ declare function getCLS(): Promise<number>;
2704
+ /**
2705
+ * Gets the time to first byte (TTFB) of a web page using the Performance API.
2706
+ * The TTFB is the time it takes for the first byte of the response to be received by the browser.
2707
+ *
2708
+ * Usage:
2709
+ *
2710
+ * ```javascript
2711
+ * import { getTTFB } from "mazey";
2712
+ *
2713
+ * getTTFB().then(
2714
+ * res => {
2715
+ * console.log(`TTFB: ${res}`);
2716
+ * }
2717
+ * );
2718
+ * ```
2719
+ *
2720
+ * Output:
2721
+ *
2722
+ * ```text
2723
+ * TTFB: 123
2724
+ * ```
2725
+ *
2726
+ * @returns The TTFB in milliseconds, or 0 if the navigation timing information is not available.
2727
+ * @category Perf
2728
+ */
2729
+ declare function getTTFB(): Promise<number>;
2730
+ /**
2731
+ * EN: Get page load time(`PerformanceNavigationTiming`).
2732
+ *
2733
+ * ZH: 获取页面加载相关的各项数据。
2734
+ *
2735
+ * @remarks
2736
+ * This function uses the [`PerformanceNavigationTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming) API to get page load time data.
2737
+ * 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.
2738
+ * 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/chengchuu/mazey/releases/tag/v3.9.7)).
2739
+ *
2740
+ * Usage:
2741
+ *
2742
+ * ```javascript
2743
+ * import { getPerformance } from "mazey";
2744
+ *
2745
+ * // `camelCase:false` (Default) Return underline(`a_b`) data.
2746
+ * // `camelCase:true` Return hump(`aB`) data.
2747
+ * getPerformance()
2748
+ * .then(res => {
2749
+ * console.log(JSON.stringify(res));
2750
+ * })
2751
+ * .catch(console.error);
2752
+ * ```
2753
+ *
2754
+ * Output:
2755
+ *
2756
+ * ```text
2757
+ * {"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}
2758
+ * ```
2759
+ *
2760
+ * Results:
2761
+ *
2762
+ * | Attribute | Description | Type | Values |
2763
+ * | :------------ | :------------ | :------------ | :------------ |
2764
+ * | dns_time | DNS Lookup | number | domainLookupEnd - domainLookupStart |
2765
+ * | tcp_time | Connection Negotiation | number | connectEnd - connectStart |
2766
+ * | response_time | Requests and Responses | number | responseStart - requestStart |
2767
+ * | white_time | White Screen | number | responseStart - navigationStart |
2768
+ * | dom_ready_time | Dom Ready | number | domContentLoadedEventStart - navigationStart |
2769
+ * | onload_time | Onload | number | loadEventStart - navigationStart |
2770
+ * | render_time | EventEnd | number | loadEventEnd -navigationStart |
2771
+ * | unload_time | Unload | number | (Optional) unloadEventEnd - unloadEventStart |
2772
+ * | redirect_time | Redirect | number | (Optional) redirectEnd - redirectStart |
2773
+ * | ssl_time | SSL | number | (Optional) connectEnd - secureConnectionStart |
2774
+ * | download_time | Download | number | (Optional) responseEnd - responseStart |
2775
+ *
2776
+ * @param {boolean} camelCase -- false(默认) 以下划线形式返回数据 true 以驼峰形式返回数据
2777
+ * @returns {Promise<object>} 加载数据
2778
+ * @category Perf
2779
+ */
2780
+ declare function getPerformance(camelCase?: boolean): Promise<WebPerformance | Error>;
2781
+
2782
+ /**
2783
+ * EN: Detect the margin of Safety. Determine if it is a secure PWA environment that it can run.
2784
+ *
2785
+ * ZH: 判断是否是安全的 PWA 环境。
2786
+ *
2787
+ * Usage:
2788
+ *
2789
+ * ```javascript
2790
+ * import { isSafePWAEnv } from "mazey";
2791
+ *
2792
+ * const ret = isSafePWAEnv();
2793
+ * console.log(ret);
2794
+ * ```
2795
+ *
2796
+ * Output:
2797
+ *
2798
+ * ```text
2799
+ * true
2800
+ * ```
2801
+ *
2802
+ * @environment Browser
2803
+ * @returns {boolean} true 是
2804
+ * @category Browser Information
2805
+ */
2806
+ declare function isSafePWAEnv(): boolean;
2807
+ /**
2808
+ * EN: Provides detailed information about the browser.
2809
+ *
2810
+ * ZH: 返回有关浏览器的详细信息。
2811
+ *
2812
+ * Usage:
2813
+ *
2814
+ * ```javascript
2815
+ * import { getBrowserInfo } from "mazey";
2816
+ *
2817
+ * const ret = getBrowserInfo();
2818
+ * console.log(ret);
2819
+ * ```
2820
+ *
2821
+ * Output:
2822
+ *
2823
+ * ```text
2824
+ * {"engine":"webkit","engineVs":"537.36","platform":"desktop","supporter":"chrome","supporterVs":"85.0.4183.121","system":"windows","systemVs":"10"}
2825
+ * ```
2826
+ *
2827
+ * Results:
2828
+ *
2829
+ * | Attribute | Description | Type | Values |
2830
+ * | :------------ | :------------ | :------------ | :------------ |
2831
+ * | **system** | System | string | android, ios, windows, macos, linux |
2832
+ * | systemVs | System version | string | Windows: 2000, xp, 2003, vista, 7, 8, 8.1, 10 macOS: ... |
2833
+ * | platform | Platform | string | desktop, mobile |
2834
+ * | engine | Engine | string | webkit, gecko, presto, trident |
2835
+ * | engineVs | Engine version | string | - |
2836
+ * | supporter | Supporter | string | edge, opera, chrome, safari, firefox, iexplore |
2837
+ * | supporterVs | Supporter version | string | - |
2838
+ * | shell | Shell | string | (Optional) wechat, qq_browser, qq_app, uc, 360, 2345, sougou, liebao, maxthon, bilibili |
2839
+ * | shellVs | Shell version | string | (Optional) 20/... |
2840
+ * | appleType | Apple device type | string | (Optional) ipad, iphone, ipod, iwatch |
2841
+ *
2842
+ * Example: Determine the environment of the mobile QQ.
2843
+ *
2844
+ * ```javascript
2845
+ * const { system, shell } = getBrowserInfo();
2846
+ * const isMobileQQ = ["android", "ios"].includes(system) && ["qq_browser", "qq_app"].includes(shell);
2847
+ * ```
2848
+ *
2849
+ * @environment Browser
2850
+ * @returns Browser information
2851
+ * @category Browser Information
2852
+ */
2853
+ declare function getBrowserInfo(): BrowserInfo;
2854
+ /**
2855
+ * EN: Generate browser attributes.
2856
+ *
2857
+ * ZH: 生成浏览器属性。
2858
+ *
2859
+ * Usage:
2860
+ *
2861
+ * ```javascript
2862
+ * import { genBrowserAttrs } from "mazey";
2863
+ *
2864
+ * const attrs = genBrowserAttrs();
2865
+ * console.log(attrs);
2866
+ * ```
2867
+ *
2868
+ * Output:
2869
+ *
2870
+ * ```text
2871
+ * ["windows", "desktop", "webkit", "chrome"]
2872
+ * ```
2873
+ *
2874
+ * @environment Browser
2875
+ * @param {string} prefix
2876
+ * @returns {array} Browser attributes
2877
+ * @category Browser Information
2878
+ */
2879
+ declare function genBrowserAttrs(prefix?: string, separator?: string): string[];
2880
+ /**
2881
+ * Detect webp support.
2882
+ *
2883
+ * Usage:
2884
+ *
2885
+ * ```javascript
2886
+ * import { isSupportWebp } from "mazey";
2887
+ *
2888
+ * isSupportWebp().then(res => {
2889
+ * console.log("isSupportWebp:", res);
2890
+ * });
2891
+ * ```
2892
+ *
2893
+ * Output:
2894
+ *
2895
+ * ```text
2896
+ * isSupportWebp: true
2897
+ * ```
2898
+ *
2899
+ * Reference: [Detect WEBP Support with JavaScript](https://davidwalsh.name/detect-webp)
2900
+ *
2901
+ * @category Browser Information
2902
+ */
2903
+ declare function isSupportWebp(): Promise<boolean>;
2904
+
2905
+ /**
2906
+ * EN: Custom console printing (`console`).
2907
+ *
2908
+ * ZH: 生成自定义控制台打印。
2909
+ *
2910
+ * Usage:
2911
+ *
2912
+ * ```javascript
2913
+ * import { genCustomConsole } from "mazey";
2914
+ *
2915
+ * const cusConsole = genCustomConsole("[MazeyLog]");
2916
+ * cusConsole.log("I am string.");
2917
+ * cusConsole.info("I am boolean.", true);
2918
+ * cusConsole.info("I am number.", 123, 456);
2919
+ * cusConsole.info("I am object.", { a: 123, b: 456});
2920
+ * ```
2921
+ *
2922
+ * Output:
2923
+ *
2924
+ * ```text
2925
+ * [MazeyLog] I am string.
2926
+ * [MazeyLog] I am boolean. true
2927
+ * [MazeyLog] I am number. 123 456
2928
+ * [MazeyLog] I am object. {a: 123, b: 456}
2929
+ * ```
2930
+ *
2931
+ * @param {string} prefix The prefix string.
2932
+ * @param {object} options The options object.
2933
+ * @param {boolean} options.enabled Whether logging is enabled.
2934
+ * @param {boolean} options.isClosed Deprecated, Use "enabled" instead.
2935
+ * @param {boolean} options.showWrap Whether to show the wrap.
2936
+ * @param {boolean} options.showDate Whether to show the date.
2937
+ * @param {string} options.locales A locale string.
2938
+ * @param {boolean} options.isStringifyObject Whether to stringify the object.
2939
+ * @param {function} options.logFn The function with Log.
2940
+ * @param {function} options.errorFn The function with Error.
2941
+ * @returns {object} The custom console object.
2942
+ * @category Debug
2943
+ */
2944
+ declare function genCustomConsole(prefix?: string, options?: {
2945
+ enabled?: boolean;
2946
+ isClosed?: boolean;
2947
+ showWrap?: boolean;
2948
+ showDate?: boolean;
2949
+ locales?: string;
2950
+ isStringifyObject?: boolean;
2951
+ logFn?: () => void;
2952
+ errorFn?: () => void;
2953
+ }): Console;
2954
+ /**
2955
+ * @hidden
2956
+ */
2957
+ declare const mazeyCon: Console;
2958
+ /**
2959
+ * EN: Print logs with Time.
2960
+ *
2961
+ * ZH: 打印带有时间的日志。
2962
+ *
2963
+ * Usage:
2964
+ *
2965
+ * ```javascript
2966
+ * timeCon("I am string.");
2967
+ * ```
2968
+ *
2969
+ * Output:
2970
+ *
2971
+ * ```text
2972
+ * 2024年11月2日周六 09:24:40 I am string.
2973
+ * ```
2974
+ *
2975
+ * @hidden
2976
+ */
2977
+ declare const timeCon: Console;
2978
+
2979
+ export { addClass, addEvent, addStyle, calLongestCommonSubsequence, calLongestCommonSubstring, camelCase2Underscore, camelCaseToKebabCase, cancelBubble, clearHTML, clearHtml, convert10To26, convertCamelToKebab, convertCamelToUnder, convertHttpToHttps, convertKebabToCamel, convertObjectToQuery, convertToHtmlBreaks, convertUnderToCamel, cutCHSString, cutZHString, debounce, deepCopy, deepCopyObject, delCookie, doFn, fireEvent, floatFixed, floatToPercent, formatDate, genBrowserAttrs, genCustomConsole, genHashCode, genRndNumString, genStyleString, genUniqueNumString, generateRndNum, generateUniqueNum, getAllQueryParams, getBrowserInfo, getCLS, getCookie, getCurrentVersion, getDefineListeners, getDomain, getFCP, getFID, getFP, getFileSize, getFriendlyInterval, getHashQueryParam, getLCP, getLocalStorage, getPageMeta, getPerformance, getQueryParam, getScriptQueryParam, getSessionStorage, getTTFB, getUrlFileType, getUrlHost, getUrlParam, getUrlPath, hasClass, inRate, invokeEvent, invokeFn, isArray, isBool, isBoolean, isBrowser, isFunction, isHit, isJSONString, isJsonString, isNonEmptyArray, isNonEmptyObject, isNumber, isPureObject, isSafePWAEnv, isString, isSupportWebp, isSupportedEntryType, isUdfOrNul, isValidData, isValidEmail, isValidHttpUrl, isValidPhoneNumber, isValidUrl, loadCSS, loadImage, loadScript, loadScriptIfUndefined, longestComSubsequence, longestComSubstring, mNow, mTrim, mazeyCon, newLine, onURLChange, removeClass, removeCookie, removeEvent, removeHTML, removeHtml, repeatUntilConditionMet, replaceHttp, sanitizeInput, setClass, setCookie, setImgSizeBySrc, setImgWidHeiBySrc, setLocalStorage, setSessionStorage, sleep, throttle, timeCon, truncateZHString, unsanitize, unsanitizeInput, updateQueryParam, waitTime, windowLoaded, zAxiosIsValidRes };