mazey 5.1.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  /**
2
- * EN: Computes the longest common substring of two strings.
3
- *
4
- * ZH: 计算两个字符串的最长公共子串。
2
+ * Compute the length of the longest common substring of two strings.
5
3
  *
6
4
  * Usage:
7
5
  *
@@ -31,9 +29,7 @@ declare function longestComSubstring(aStr: string, bStr: string): number;
31
29
  */
32
30
  declare function calLongestCommonSubstring(aStr: string, bStr: string): number;
33
31
  /**
34
- * EN: Computes the longest common subsequence of two strings.
35
- *
36
- * ZH: 计算两个字符串的最长公共子序列。
32
+ * Compute the length of the longest common subsequence of two strings.
37
33
  *
38
34
  * Usage:
39
35
  *
@@ -50,9 +46,9 @@ declare function calLongestCommonSubstring(aStr: string, bStr: string): number;
50
46
  * 4
51
47
  * ```
52
48
  *
53
- * @param {string} aStr 字符串
54
- * @param {string} bStr 字符串
55
- * @returns {number} 长度
49
+ * @param {string} aStr The first string.
50
+ * @param {string} bStr The second string.
51
+ * @returns {number} The length of the longest common subsequence.
56
52
  * @category Calculate and Formula
57
53
  */
58
54
  declare function longestComSubsequence(aStr: string, bStr: string): number;
@@ -63,16 +59,14 @@ declare function longestComSubsequence(aStr: string, bStr: string): number;
63
59
  */
64
60
  declare function calLongestCommonSubsequence(aStr: string, bStr: string): number;
65
61
  /**
66
- * EN: Hit probability (1% ~ 100%).
67
- *
68
- * ZH: 百分位概率。
62
+ * Return whether a random value falls within the given probability.
69
63
  *
70
64
  * Usage:
71
65
  *
72
66
  * ```javascript
73
67
  * import { isHit } from "mazey";
74
68
  *
75
- * const ret = isHit(0.5); // 0.01 ~ 1 true/false
69
+ * const ret = isHit(0.5); // A 50% chance of returning true.
76
70
  * console.log(ret);
77
71
  * ```
78
72
  *
@@ -103,8 +97,8 @@ declare function calLongestCommonSubsequence(aStr: string, bStr: string): number
103
97
  * 499994 500006
104
98
  * ```
105
99
  *
106
- * @param {number} rate 0.1 ~ 1 => 1% ~ 100%
107
- * @returns {boolean} true 命中
100
+ * @param {number} rate Probability expressed as a value from 0 to 1.
101
+ * @returns {boolean} Whether the random value is less than the probability.
108
102
  * @category Calculate and Formula
109
103
  */
110
104
  declare function isHit(rate: number): boolean;
@@ -467,6 +461,24 @@ declare function isJSONString(str: string): boolean;
467
461
  * @hidden
468
462
  */
469
463
  declare function isJsonString(str: string): boolean;
464
+ /**
465
+ * Parse a JSON string and return a caller-defined fallback when parsing fails.
466
+ *
467
+ * Usage:
468
+ *
469
+ * ```javascript
470
+ * import { parseJsonSafe } from "mazey";
471
+ *
472
+ * const data = parseJsonSafe('{"enabled":true}');
473
+ * const fallback = parseJsonSafe("invalid", {});
474
+ * ```
475
+ *
476
+ * @param value JSON string to parse.
477
+ * @param fallback Value returned when parsing fails. Defaults to `null`.
478
+ * @returns The parsed JSON value or the supplied fallback.
479
+ * @category Util
480
+ */
481
+ declare function parseJsonSafe<T, F = null>(value: string, fallback?: F): T | F;
470
482
  /**
471
483
  * Generate a random string of number, `genRndNumString(7)` => "7658495".
472
484
  *
@@ -500,9 +512,8 @@ declare function genRndNumString(n?: number): string;
500
512
  */
501
513
  declare function generateRndNum(n?: number): string;
502
514
  /**
503
- * EN: Generate a unique identifier number based on time: `genUniqueNumString()` => `1538324722364123`
504
- *
505
- * ZH: 根据时间生成唯一标志的数字:`genUniqueNumString()` => `1538324722364123`。
515
+ * Generate a numeric identifier by combining the current timestamp with a
516
+ * random numeric suffix.
506
517
  *
507
518
  * Usage:
508
519
  *
@@ -522,7 +533,8 @@ declare function generateRndNum(n?: number): string;
522
533
  * 1538324722364123
523
534
  * ```
524
535
  *
525
- * @param {number} n 随机数的长度
536
+ * @param {number} n Length of the random numeric suffix.
537
+ * @returns {string} A timestamp-based numeric identifier.
526
538
  * @category Util
527
539
  */
528
540
  declare function genUniqueNumString(n?: number): string;
@@ -533,9 +545,7 @@ declare function genUniqueNumString(n?: number): string;
533
545
  */
534
546
  declare function generateUniqueNum(n?: number): string;
535
547
  /**
536
- * EN: Get timestamp.
537
- *
538
- * ZH: 获取时间戳。
548
+ * Get the current timestamp in milliseconds.
539
549
  *
540
550
  * Usage:
541
551
  *
@@ -552,13 +562,12 @@ declare function generateUniqueNum(n?: number): string;
552
562
  * 1585325367122
553
563
  * ```
554
564
  *
565
+ * @returns {number} The current timestamp in milliseconds.
555
566
  * @category Util
556
567
  */
557
568
  declare function mNow(): number;
558
569
  /**
559
- * EN: Floating point number to percentage 0.2 => 20%
560
- *
561
- * ZH: 浮点数转为百分比 0.2 => 20%。
570
+ * Convert a floating-point ratio to a percentage string.
562
571
  *
563
572
  * Usage:
564
573
  *
@@ -578,15 +587,14 @@ declare function mNow(): number;
578
587
  * 20.00%
579
588
  * ```
580
589
  *
581
- * @param {number} num 浮点数
582
- * @param {number} fixSize 保留几位浮点数
590
+ * @param {number} num Floating-point ratio to convert.
591
+ * @param {number} fixSize Number of decimal places in the percentage.
592
+ * @returns {string} The percentage string.
583
593
  * @category Util
584
594
  */
585
595
  declare function floatToPercent(num: number, fixSize?: number): string;
586
596
  /**
587
- * EN: Keep the specified number of decimal places for floating-point numbers.
588
- *
589
- * ZH: 浮点数保留指定位。
597
+ * Format a number with a fixed number of decimal places.
590
598
  *
591
599
  * Usage:
592
600
  *
@@ -606,13 +614,14 @@ declare function floatToPercent(num: number, fixSize?: number): string;
606
614
  * 0.20
607
615
  * ```
608
616
  *
617
+ * @param num Number or numeric string to format.
618
+ * @param size Number of decimal places.
619
+ * @returns The fixed-point string.
609
620
  * @category Util
610
621
  */
611
622
  declare function floatFixed(num: number | string, size?: number): string;
612
623
  /**
613
- * EN: Throttle, used to limit the frequency of function execution over time.
614
- *
615
- * ZH: 节流,用于限制函数在一段时间内的执行频率。
624
+ * Limit how frequently a function can be invoked over time.
616
625
  *
617
626
  * Usage:
618
627
  *
@@ -626,6 +635,11 @@ declare function floatFixed(num: number | string, size?: number): string;
626
635
  *
627
636
  * Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
628
637
  *
638
+ * @param func Function to throttle.
639
+ * @param wait Minimum interval between invocations, in milliseconds.
640
+ * @param options.leading Whether to invoke on the leading edge.
641
+ * @param options.trailing Whether to invoke on the trailing edge.
642
+ * @returns The throttled function.
629
643
  * @category Util
630
644
  */
631
645
  declare function throttle<T extends (...args: MazeyFnParams) => MazeyFnReturn>(func: T, wait: number, options?: {
@@ -633,9 +647,8 @@ declare function throttle<T extends (...args: MazeyFnParams) => MazeyFnReturn>(f
633
647
  trailing?: boolean;
634
648
  }): ThrottleFunc<T>;
635
649
  /**
636
- * EN: Debounce, used to delay the execution of a function until a specified time has passed since the last invocation.
637
- *
638
- * ZH: 防抖,用于在最后一次调用后的指定时间内延迟函数的执行。
650
+ * Delay function execution until the specified time has passed since the last
651
+ * invocation.
639
652
  *
640
653
  * Usage:
641
654
  *
@@ -647,6 +660,10 @@ declare function throttle<T extends (...args: MazeyFnParams) => MazeyFnReturn>(f
647
660
  * }, 1000, true);
648
661
  * ```
649
662
  *
663
+ * @param func Function to debounce.
664
+ * @param wait Delay after the last invocation, in milliseconds.
665
+ * @param immediate Whether to invoke on the leading edge instead.
666
+ * @returns The debounced function.
650
667
  * @category Util
651
668
  */
652
669
  declare function debounce<T extends (...args: MazeyFnParams) => MazeyFnReturn>(func: T, wait: number, immediate?: boolean): DebounceFunc<T>;
@@ -727,9 +744,7 @@ declare function getFriendlyInterval(start?: number | string | Date, end?: numbe
727
744
  */
728
745
  declare function formatDurationFromMs(durationMs: number): string;
729
746
  /**
730
- * EN: Check whether it is a right number.
731
- *
732
- * ZH: 判断是否有效数字。
747
+ * Check whether a value is a number allowed by the supplied options.
733
748
  *
734
749
  * Usage:
735
750
  *
@@ -752,16 +767,14 @@ declare function formatDurationFromMs(durationMs: number): string;
752
767
  * true false false true false true
753
768
  * ```
754
769
  *
755
- * @param {*} num 被判断的值
770
+ * @param {*} num Value to check.
756
771
  * @param options Controls whether `NaN`, `Infinity`, or other non-finite values count as numbers.
757
- * @returns {boolean} true 是数字
772
+ * @returns {boolean} Whether the value is an allowed number.
758
773
  * @category Util
759
774
  */
760
775
  declare function isNumber(num: unknown, options?: IsNumberOptions): boolean;
761
776
  /**
762
- * EN: Invoke effective function.
763
- *
764
- * ZH: 执行有效函数。
777
+ * Invoke a value only when it is a function.
765
778
  *
766
779
  * Usage:
767
780
  *
@@ -773,7 +786,9 @@ declare function isNumber(num: unknown, options?: IsNumberOptions): boolean;
773
786
  * });
774
787
  * ```
775
788
  *
776
- * @param {function} fn 等待被执行的未知是否有效的函数
789
+ * @param {function} fn Potential function to invoke.
790
+ * @param params Arguments passed to the function.
791
+ * @returns The function result, or `null` when `fn` is not callable.
777
792
  * @category Util
778
793
  */
779
794
  declare function invokeFn(fn: MazeyFunction | null | undefined, ...params: Parameters<MazeyFunction>): ReturnType<MazeyFunction> | null;
@@ -1037,8 +1052,8 @@ declare function newLine(str: string): string;
1037
1052
  * hello world
1038
1053
  * ```
1039
1054
  *
1040
- * @param {string} str 带 HTML 标签的字符串
1041
- * @returns {string} 字符串
1055
+ * @param {string} str A string that may contain HTML tags.
1056
+ * @returns {string} The string with HTML tags removed.
1042
1057
  * @category Util
1043
1058
  */
1044
1059
  declare function removeHTML(str: string, options?: {
@@ -1121,9 +1136,8 @@ declare function unsanitizeInput(input: string): string;
1121
1136
  */
1122
1137
  declare function unsanitize(str: string): string;
1123
1138
  /**
1124
- * EN: Truncate string, Chinese characters count as 2 bytes.
1125
- *
1126
- * ZH: 截取字符串,中文算 2 个字节。
1139
+ * Truncate a string by weighted length, counting non-ASCII characters as two
1140
+ * units.
1127
1141
  *
1128
1142
  * Usage:
1129
1143
  *
@@ -1140,11 +1154,11 @@ declare function unsanitize(str: string): string;
1140
1154
  * hello
1141
1155
  * ```
1142
1156
  *
1143
- * @param {string} str 要截取的字符串
1144
- * @param {number} len
1145
- * @param {boolean} options.hasDot
1146
- * @param {string} options.dotText
1147
- * @returns {string} 返回截取后的字符串
1157
+ * @param {string} str String to truncate.
1158
+ * @param {number} len Maximum weighted length.
1159
+ * @param {boolean} options.hasDot Whether to append truncation text.
1160
+ * @param {string} options.dotText Text appended when truncation occurs.
1161
+ * @returns {string} The truncated string.
1148
1162
  * @category Util
1149
1163
  */
1150
1164
  declare function cutZHString(str: string | null | undefined, len: number, options?: {
@@ -1167,11 +1181,12 @@ declare function cutZHString(str: string | null | undefined, len: number, option
1167
1181
  *
1168
1182
  * ```text
1169
1183
  * hello
1184
+ * ```
1170
1185
  *
1171
- * @param {string} str 要截取的字符串
1172
- * @param {number} len
1173
- * @param {boolean} hasDot
1174
- * @returns {string} 返回截取后的字符串
1186
+ * @param {string} str String to truncate.
1187
+ * @param {number} len Maximum weighted length.
1188
+ * @param {boolean} hasDot Whether to append the default truncation text.
1189
+ * @returns {string} The truncated string.
1175
1190
  * @hidden
1176
1191
  */
1177
1192
  declare function truncateZHString(str: string | null | undefined, len: number, hasDot?: boolean): string;
@@ -1229,9 +1244,7 @@ declare function zAxiosIsValidRes(res: ZResResponse | undefined, options?: ZResI
1229
1244
  */
1230
1245
  declare function isValidData(data: MazeyObject, attributes: string[], validValue: SimpleType): boolean;
1231
1246
  /**
1232
- * EN: Semantic file size, convert bytes into a readable file size.
1233
- *
1234
- * ZH: 语义化文件大小,把字节转换成正常文件大小。
1247
+ * Convert a byte count to a human-readable file size.
1235
1248
  *
1236
1249
  * Usage:
1237
1250
  *
@@ -1248,6 +1261,8 @@ declare function isValidData(data: MazeyObject, attributes: string[], validValue
1248
1261
  * 1 KB
1249
1262
  * ```
1250
1263
  *
1264
+ * @param size File size in bytes.
1265
+ * @returns A rounded file-size string, or an empty string for a non-positive or non-finite value.
1251
1266
  * @category Util
1252
1267
  */
1253
1268
  declare function getFileSize(size: number): string;
@@ -1274,6 +1289,31 @@ declare function getFileSize(size: number): string;
1274
1289
  * @category Util
1275
1290
  */
1276
1291
  declare function genHashCode(str: string): number;
1292
+ /**
1293
+ * Generate a lowercase SHA-256 hexadecimal digest with the Web Crypto API.
1294
+ *
1295
+ * Usage:
1296
+ *
1297
+ * ```javascript
1298
+ * import { sha256Hex } from "mazey";
1299
+ *
1300
+ * const digest = await sha256Hex("hello world");
1301
+ * console.log(digest);
1302
+ * ```
1303
+ *
1304
+ * Output:
1305
+ *
1306
+ * ```text
1307
+ * b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
1308
+ * ```
1309
+ *
1310
+ * @remarks Requires Web Crypto. String input also requires `TextEncoder`.
1311
+ * @param input Text or binary data to hash.
1312
+ * @returns A promise that resolves to the lowercase hexadecimal digest.
1313
+ * @throws When the required platform API is unavailable. Digest failures are propagated.
1314
+ * @category Util
1315
+ */
1316
+ declare function sha256Hex(input: string | BufferSource): Promise<string>;
1277
1317
  /**
1278
1318
  * Check whether an unknown value represents a valid date.
1279
1319
  *
@@ -1828,9 +1868,7 @@ declare function isValidHttpUrl(url: string, options?: {
1828
1868
  strict: boolean;
1829
1869
  }): boolean;
1830
1870
  /**
1831
- * EN: Get the file type of the url.
1832
- *
1833
- * ZH: 获取文件后缀名。
1871
+ * Get the file extension from a URL or path.
1834
1872
  *
1835
1873
  * Usage:
1836
1874
  *
@@ -2082,9 +2120,7 @@ declare function setClass(ele: HTMLElement, cls: string): void;
2082
2120
  */
2083
2121
  declare function removeClass(obj: MazeyElement, cls: string): void;
2084
2122
  /**
2085
- * EN: Add `<style>` in `<head>`.
2086
- *
2087
- * ZH: 添加样式标签; style: 样式标签内的字符串; id: `<style>` 标签的 `id`; 返回: 添加成功/失败。
2123
+ * Add a `<style>` element to the document `<head>`.
2088
2124
  *
2089
2125
  * Usage:
2090
2126
  *
@@ -2150,6 +2186,10 @@ declare function removeClass(obj: MazeyElement, cls: string): void;
2150
2186
  * <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>
2151
2187
  * ```
2152
2188
  *
2189
+ * @param style CSS text to add to the document.
2190
+ * @param options.id Optional `<style>` element ID. An existing element with
2191
+ * the same ID is updated instead of duplicated.
2192
+ * @returns Whether non-empty CSS text was added or updated.
2153
2193
  * @category DOM
2154
2194
  */
2155
2195
  declare function addStyle(style: string, options?: {
@@ -2271,6 +2311,62 @@ declare function genStyleString(selector: string, styleArray: Array<string>): st
2271
2311
  * @category DOM
2272
2312
  */
2273
2313
  declare function getPageMeta(name: string): string;
2314
+ /**
2315
+ * Check whether a value is a CSS selector supported by the supplied query
2316
+ * root without allowing selector syntax errors to escape.
2317
+ *
2318
+ * Usage:
2319
+ *
2320
+ * ```javascript
2321
+ * import { isValidCssSelector } from "mazey";
2322
+ *
2323
+ * isValidCssSelector(".message > img"); // true
2324
+ * isValidCssSelector("["); // false
2325
+ * isValidCssSelector("", { allowEmpty: true }); // true
2326
+ * ```
2327
+ *
2328
+ * @remarks Browser only unless a compatible `ParentNode` is supplied.
2329
+ * @param selector Value to validate as a CSS selector.
2330
+ * @param options.allowEmpty Whether an empty or whitespace-only string is accepted. Defaults to `false`.
2331
+ * @param options.root Query root used to validate browser support. Defaults to `document` when available.
2332
+ * @returns Whether the selector is accepted by the query root.
2333
+ * @category DOM
2334
+ */
2335
+ declare function isValidCssSelector(selector: unknown, options?: {
2336
+ allowEmpty?: boolean;
2337
+ root?: ParentNode;
2338
+ }): boolean;
2339
+ /**
2340
+ * Extract text from a cloned element without modifying the original DOM.
2341
+ * Images can be replaced by their `alt` text, selected descendants can be
2342
+ * removed, and whitespace can be normalized before returning the text.
2343
+ *
2344
+ * Invalid exclusion selectors are ignored.
2345
+ *
2346
+ * Usage:
2347
+ *
2348
+ * ```javascript
2349
+ * import { extractElementText } from "mazey";
2350
+ *
2351
+ * const element = document.querySelector(".message");
2352
+ * const text = extractElementText(element, {
2353
+ * excludeSelector: ".message-actions",
2354
+ * });
2355
+ * ```
2356
+ *
2357
+ * @remarks Browser only.
2358
+ * @param element Element whose cloned contents are read.
2359
+ * @param options.excludeSelector Selector for descendants to remove from the clone.
2360
+ * @param options.replaceImagesWithAlt Whether images with an `alt` attribute are replaced by that text. Defaults to `true`.
2361
+ * @param options.normalizeWhitespace Whether whitespace is collapsed and trimmed. Defaults to `true`.
2362
+ * @returns Extracted text from the cloned element.
2363
+ * @category DOM
2364
+ */
2365
+ declare function extractElementText(element: Element, options?: {
2366
+ excludeSelector?: string;
2367
+ replaceImagesWithAlt?: boolean;
2368
+ normalizeWhitespace?: boolean;
2369
+ }): string;
2274
2370
 
2275
2371
  /**
2276
2372
  * Prevent bubbling.
@@ -2373,9 +2469,7 @@ declare function invokeEvent(type: string, params?: MazeyObject): void;
2373
2469
  declare function removeEvent(type: string, fn?: MazeyFn): void;
2374
2470
 
2375
2471
  /**
2376
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
2377
- *
2378
- * ZH: 存储/获取数据到 sessionStorage/localStorage。
2472
+ * Serialize a value as JSON and store it in `sessionStorage`.
2379
2473
  *
2380
2474
  * Usage:
2381
2475
  *
@@ -2388,7 +2482,7 @@ declare function removeEvent(type: string, fn?: MazeyFn): void;
2388
2482
  * const ret2 = getLocalStorage("test");
2389
2483
  * console.log(ret1, ret2);
2390
2484
  *
2391
- * // or package in usage
2485
+ * // Wrap the helpers with a project-specific key prefix.
2392
2486
  * const projectName = "mazey";
2393
2487
  * function mSetLocalStorage (key, value) {
2394
2488
  * return setLocalStorage(`${projectName}_${key}`, value);
@@ -2405,15 +2499,14 @@ declare function removeEvent(type: string, fn?: MazeyFn): void;
2405
2499
  * 123 123
2406
2500
  * ```
2407
2501
  *
2408
- * @param {string} key 键
2409
- * @returns {void} 返回值
2502
+ * @param {string} key Storage key.
2503
+ * @param value Value to serialize and store.
2504
+ * @returns {void} This function does not return a value.
2410
2505
  * @category Store
2411
2506
  */
2412
2507
  declare function setSessionStorage<T>(key: string, value?: T | null): void;
2413
2508
  /**
2414
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
2415
- *
2416
- * ZH: 存储/获取数据到 sessionStorage/localStorage。
2509
+ * Read a value from `sessionStorage`, parsing JSON when possible.
2417
2510
  *
2418
2511
  * Usage:
2419
2512
  *
@@ -2426,7 +2519,7 @@ declare function setSessionStorage<T>(key: string, value?: T | null): void;
2426
2519
  * const ret2 = getLocalStorage("test");
2427
2520
  * console.log(ret1, ret2);
2428
2521
  *
2429
- * // or package in usage
2522
+ * // Wrap the helpers with a project-specific key prefix.
2430
2523
  * const projectName = "mazey";
2431
2524
  * function mSetLocalStorage (key, value) {
2432
2525
  * return setLocalStorage(`${projectName}_${key}`, value);
@@ -2443,15 +2536,13 @@ declare function setSessionStorage<T>(key: string, value?: T | null): void;
2443
2536
  * 123 123
2444
2537
  * ```
2445
2538
  *
2446
- * @param {string} key 键
2447
- * @returns {any} 返回值
2539
+ * @param {string} key Storage key.
2540
+ * @returns The parsed value, raw stored value, or `null` when no value exists.
2448
2541
  * @category Store
2449
2542
  */
2450
2543
  declare function getSessionStorage<T>(key: string): T | null;
2451
2544
  /**
2452
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
2453
- *
2454
- * ZH: 存储/获取数据到 sessionStorage/localStorage。
2545
+ * Serialize a value as JSON and store it in `localStorage`.
2455
2546
  *
2456
2547
  * Usage:
2457
2548
  *
@@ -2464,7 +2555,7 @@ declare function getSessionStorage<T>(key: string): T | null;
2464
2555
  * const ret2 = getLocalStorage("test");
2465
2556
  * console.log(ret1, ret2);
2466
2557
  *
2467
- * // or package in usage
2558
+ * // Wrap the helpers with a project-specific key prefix.
2468
2559
  * const projectName = "mazey";
2469
2560
  * function mSetLocalStorage (key, value) {
2470
2561
  * return setLocalStorage(`${projectName}_${key}`, value);
@@ -2481,15 +2572,14 @@ declare function getSessionStorage<T>(key: string): T | null;
2481
2572
  * 123 123
2482
2573
  * ```
2483
2574
  *
2484
- * @param {string} key 键
2485
- * @returns {void} 返回值
2575
+ * @param {string} key Storage key.
2576
+ * @param value Value to serialize and store.
2577
+ * @returns {void} This function does not return a value.
2486
2578
  * @category Store
2487
2579
  */
2488
2580
  declare function setLocalStorage<T>(key: string, value?: T | null): void;
2489
2581
  /**
2490
- * EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).
2491
- *
2492
- * ZH: 存储/获取数据到 sessionStorage/localStorage。
2582
+ * Read a value from `localStorage`, parsing JSON when possible.
2493
2583
  *
2494
2584
  * Usage:
2495
2585
  *
@@ -2502,7 +2592,7 @@ declare function setLocalStorage<T>(key: string, value?: T | null): void;
2502
2592
  * const ret2 = getLocalStorage("test");
2503
2593
  * console.log(ret1, ret2);
2504
2594
  *
2505
- * // or package in usage
2595
+ * // Wrap the helpers with a project-specific key prefix.
2506
2596
  * const projectName = "mazey";
2507
2597
  * function mSetLocalStorage (key, value) {
2508
2598
  * return setLocalStorage(`${projectName}_${key}`, value);
@@ -2519,22 +2609,20 @@ declare function setLocalStorage<T>(key: string, value?: T | null): void;
2519
2609
  * 123 123
2520
2610
  * ```
2521
2611
  *
2522
- * @param {string} key 键
2523
- * @returns {void} 返回值
2612
+ * @param {string} key Storage key.
2613
+ * @returns The parsed value, raw stored value, or `null` when no value exists.
2524
2614
  * @category Store
2525
2615
  */
2526
2616
  declare function getLocalStorage<T>(key: string): T | null;
2527
2617
  /**
2528
- * EN: Handle Cookie.
2529
- *
2530
- * ZH: 设置/获取 Cookie。
2618
+ * Get a cookie value by name.
2531
2619
  *
2532
2620
  * Usage:
2533
2621
  *
2534
2622
  * ```javascript
2535
2623
  * import { setCookie, getCookie } from "mazey";
2536
2624
  *
2537
- * setCookie("test", "123", 30, "example.com"); // key value day domain
2625
+ * setCookie("test", "123", 30, "example.com"); // name, value, days, domain
2538
2626
  * const ret = getCookie("test");
2539
2627
  * console.log(ret);
2540
2628
  * ```
@@ -2545,20 +2633,20 @@ declare function getLocalStorage<T>(key: string): T | null;
2545
2633
  * 123
2546
2634
  * ```
2547
2635
  *
2636
+ * @param name Cookie name.
2637
+ * @returns The cookie value, or an empty string when the cookie does not exist.
2548
2638
  * @category Store
2549
2639
  */
2550
2640
  declare function getCookie(name: string): string;
2551
2641
  /**
2552
- * EN: Handle Cookie.
2553
- *
2554
- * ZH: 设置/获取 Cookie。
2642
+ * Set a cookie value.
2555
2643
  *
2556
2644
  * Usage:
2557
2645
  *
2558
2646
  * ```javascript
2559
2647
  * import { setCookie, getCookie } from "mazey";
2560
2648
  *
2561
- * setCookie("test", "123", 30, "example.com"); // key value day domain
2649
+ * setCookie("test", "123", 30, "example.com"); // name, value, days, domain
2562
2650
  * const ret = getCookie("test");
2563
2651
  * console.log(ret);
2564
2652
  * ```
@@ -2569,6 +2657,11 @@ declare function getCookie(name: string): string;
2569
2657
  * 123
2570
2658
  * ```
2571
2659
  *
2660
+ * @param name Cookie name.
2661
+ * @param value Cookie value.
2662
+ * @param days Number of days until expiration. Omit for a session cookie.
2663
+ * @param domain Optional cookie domain.
2664
+ * @returns {void} This function does not return a value.
2572
2665
  * @category Store
2573
2666
  */
2574
2667
  declare function setCookie(name: string, value: string, days?: number, domain?: string): void;
@@ -2603,9 +2696,7 @@ declare function removeCookie(name: string): boolean;
2603
2696
  declare function delCookie(name: string): void;
2604
2697
 
2605
2698
  /**
2606
- * EN: Load a CSS file from the server.
2607
- *
2608
- * ZH: 动态加载 CSS 文件。
2699
+ * Load a CSS file dynamically.
2609
2700
  *
2610
2701
  * Usage:
2611
2702
  *
@@ -2636,18 +2727,16 @@ declare function delCookie(name: string): void;
2636
2727
  * Load CSS Success: loaded
2637
2728
  * ```
2638
2729
  *
2639
- * @param {string} url -- css资源路径
2640
- * @param {string} options.id -- link标签id
2641
- * @returns {Promise<string>} true -- 加载成功
2730
+ * @param {string} url URL of the CSS resource.
2731
+ * @param {string} options.id Optional ID for the `<link>` element.
2732
+ * @returns {Promise<string>} A promise that resolves to `"loaded"` after the stylesheet loads.
2642
2733
  * @category Load
2643
2734
  */
2644
2735
  declare function loadCSS(url: string, options?: {
2645
2736
  id?: string;
2646
2737
  }): Promise<string>;
2647
2738
  /**
2648
- * EN: Load a JavaScript file from the server and execute it.
2649
- *
2650
- * ZH: 动态加载 JavaScript 文件。
2739
+ * Load and execute a JavaScript file dynamically.
2651
2740
  *
2652
2741
  * Usage:
2653
2742
  *
@@ -2679,16 +2768,16 @@ declare function loadCSS(url: string, options?: {
2679
2768
  * Load JavaScript script: loaded
2680
2769
  * ```
2681
2770
  *
2682
- * @param {string} url -- JavaScript 资源路径
2683
- * @param {string} options.id -- DOM ID
2684
- * @param {function} options.callback -- 加载后回调函数
2685
- * @param {number} options.timeout -- 超时时长
2686
- * @param {boolean} options.isDefer -- 是否添加 defer 标签
2687
- * @param {boolean} options.isAsync -- 是否添加 async 标签
2688
- * @param {boolean} options.isCrossOrigin -- 是否跨域
2689
- * @param {object} options.attributes -- 其他属性
2690
- * @param {string} options.cssUrl -- CSS 资源路径
2691
- * @returns {Promise<string>} -- true 成功
2771
+ * @param {string} url URL of the JavaScript resource.
2772
+ * @param {string} options.id Optional ID for the `<script>` element.
2773
+ * @param {function} options.callback Callback invoked after the script loads.
2774
+ * @param {number} options.timeout Timeout in milliseconds.
2775
+ * @param {boolean} options.isDefer Whether to set the `defer` attribute.
2776
+ * @param {boolean} options.isAsync Whether to set the `async` attribute.
2777
+ * @param {boolean} options.isCrossOrigin Whether to request the script anonymously across origins.
2778
+ * @param {object} options.attributes Additional attributes for the `<script>` element.
2779
+ * @param {string} options.cssUrl Optional CSS resource to begin loading before the script is inserted.
2780
+ * @returns {Promise<string>} A promise that resolves to `"loaded"` after the script loads.
2692
2781
  * @category Load
2693
2782
  */
2694
2783
  declare function loadScript(url: string, options?: {
@@ -2702,9 +2791,8 @@ declare function loadScript(url: string, options?: {
2702
2791
  cssUrl?: string;
2703
2792
  }): LoadScriptReturns;
2704
2793
  /**
2705
- * EN: Check whether the page is loaded successfully (Keep the compatibility if the browser's `load` event has been triggered).
2706
- *
2707
- * ZH: 页面加载完成。
2794
+ * Wait for the page to finish loading, including when the `load` event has
2795
+ * already fired.
2708
2796
  *
2709
2797
  * Usage:
2710
2798
  *
@@ -2726,8 +2814,8 @@ declare function loadScript(url: string, options?: {
2726
2814
  * Load Success: load
2727
2815
  * ```
2728
2816
  *
2729
- * @param {number} timeout 超时时间 / 单位:毫秒,默认:30000(30 秒)
2730
- * @returns {Promise<string>} document is loaded? "complete" "load" / "timeout"
2817
+ * @param {number} timeout Timeout in milliseconds. Defaults to 30,000.
2818
+ * @returns {Promise<string>} A promise that resolves to `"complete"` or `"load"`, or rejects on timeout.
2731
2819
  * @category Load
2732
2820
  */
2733
2821
  declare function windowLoaded(timeout?: number): Promise<string>;
@@ -2948,9 +3036,7 @@ declare function getCLS(): Promise<number>;
2948
3036
  */
2949
3037
  declare function getTTFB(): Promise<number>;
2950
3038
  /**
2951
- * EN: Get page load time(`PerformanceNavigationTiming`).
2952
- *
2953
- * ZH: 获取页面加载相关的各项数据。
3039
+ * Get page-load metrics from the Navigation Timing APIs.
2954
3040
  *
2955
3041
  * @remarks
2956
3042
  * This function uses the [`PerformanceNavigationTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming) API to get page load time data.
@@ -2961,8 +3047,8 @@ declare function getTTFB(): Promise<number>;
2961
3047
  * ```javascript
2962
3048
  * import { getPerformance } from "mazey";
2963
3049
  *
2964
- * // `camelCase:false` (Default) Return underline(`a_b`) data.
2965
- * // `camelCase:true` Return hump(`aB`) data.
3050
+ * // `camelCase: false` (default) returns snake_case keys such as `a_b`.
3051
+ * // `camelCase: true` returns camelCase keys such as `aB`.
2966
3052
  * getPerformance()
2967
3053
  * .then(res => {
2968
3054
  * console.log(JSON.stringify(res));
@@ -2992,8 +3078,8 @@ declare function getTTFB(): Promise<number>;
2992
3078
  * | ssl_time | SSL | number | (Optional) connectEnd - secureConnectionStart |
2993
3079
  * | download_time | Download | number | (Optional) responseEnd - responseStart |
2994
3080
  *
2995
- * @param {boolean} camelCase -- false(默认) 以下划线形式返回数据 true 以驼峰形式返回数据
2996
- * @returns {Promise<object>} 加载数据
3081
+ * @param {boolean} camelCase Whether to return camelCase keys. Defaults to `false`, which returns snake_case keys.
3082
+ * @returns {Promise<object>} The collected page-load metrics.
2997
3083
  * @category Perf
2998
3084
  */
2999
3085
  declare function getPerformance(camelCase?: boolean): Promise<WebPerformance>;
@@ -3060,9 +3146,7 @@ declare function isSafePWAEnv(options?: IsSafePWAEnvOptions): boolean;
3060
3146
  */
3061
3147
  declare function isStandalonePWA(): boolean;
3062
3148
  /**
3063
- * EN: Provides detailed information about the browser.
3064
- *
3065
- * ZH: 返回有关浏览器的详细信息。
3149
+ * Return detailed information about the current browser.
3066
3150
  *
3067
3151
  * Usage:
3068
3152
  *
@@ -3107,9 +3191,7 @@ declare function isStandalonePWA(): boolean;
3107
3191
  */
3108
3192
  declare function getBrowserInfo(): BrowserInfo;
3109
3193
  /**
3110
- * EN: Generate browser attributes.
3111
- *
3112
- * ZH: 生成浏览器属性。
3194
+ * Generate browser attributes from the detected browser information.
3113
3195
  *
3114
3196
  * Usage:
3115
3197
  *
@@ -3158,9 +3240,7 @@ declare function genBrowserAttrs(prefix?: string, separator?: string): string[];
3158
3240
  declare function isSupportWebp(): Promise<boolean>;
3159
3241
 
3160
3242
  /**
3161
- * EN: Custom console printing (`console`).
3162
- *
3163
- * ZH: 生成自定义控制台打印。
3243
+ * Create a configurable wrapper around the global `console`.
3164
3244
  *
3165
3245
  * Usage:
3166
3246
  *
@@ -3211,9 +3291,7 @@ declare function genCustomConsole(prefix?: string, options?: {
3211
3291
  */
3212
3292
  declare const mazeyCon: Console;
3213
3293
  /**
3214
- * EN: Print logs with Time.
3215
- *
3216
- * ZH: 打印带有时间的日志。
3294
+ * Print logs with a localized timestamp.
3217
3295
  *
3218
3296
  * Usage:
3219
3297
  *
@@ -3224,12 +3302,12 @@ declare const mazeyCon: Console;
3224
3302
  * Output:
3225
3303
  *
3226
3304
  * ```text
3227
- * 2024年11月2日周六 09:24:40 I am string.
3305
+ * [localized date and time] I am string.
3228
3306
  * ```
3229
3307
  *
3230
3308
  * @hidden
3231
3309
  */
3232
3310
  declare const timeCon: Console;
3233
3311
 
3234
- export { addClass, addEvent, addStyle, calLongestCommonSubsequence, calLongestCommonSubstring, camelCase2Underscore, camelCaseToKebabCase, cancelBubble, clearHTML, clearHtml, convert10To26, convertCamelToKebab, convertCamelToUnder, convertHttpToHttps, convertKebabToCamel, convertObjectToQuery, convertToHtmlBreaks, convertUnderToCamel, cutCHSString, cutZHString, debounce, deepCopy, deepCopyObject, deepFreeze, delCookie, doFn, fireEvent, floatFixed, floatToPercent, formatDate, formatDurationFromMs, genBrowserAttrs, genCustomConsole, genHashCode, genRndNumString, genStyleString, genUniqueNumString, generateCalendarVersion, generateRndNum, generateUniqueNum, getAllQueryParams, getBrowserInfo, getCLS, getCookie, getCurrentVersion, getDateDifference, 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, isStandalonePWA, isString, isSupportWebp, isSupportedEntryType, isUdfOrNul, isValidData, isValidDate, isValidEmail, isValidHttpUrl, isValidPhoneNumber, isValidUrl, loadCSS, loadImage, loadScript, loadScriptIfUndefined, longestComSubsequence, longestComSubstring, mNow, mTrim, mazeyCon, newLine, onURLChange, parseGitHubRepository, removeClass, removeCookie, removeEvent, removeHTML, removeHtml, repeatUntilConditionMet, replaceHttp, sanitizeInput, setClass, setCookie, setImgSizeBySrc, setImgWidHeiBySrc, setLocalStorage, setSessionStorage, sleep, throttle, timeCon, toJavaScriptGlobalName, truncateZHString, unsanitize, unsanitizeInput, updateQueryParam, waitTime, windowLoaded, zAxiosIsValidRes };
3312
+ export { addClass, addEvent, addStyle, calLongestCommonSubsequence, calLongestCommonSubstring, camelCase2Underscore, camelCaseToKebabCase, cancelBubble, clearHTML, clearHtml, convert10To26, convertCamelToKebab, convertCamelToUnder, convertHttpToHttps, convertKebabToCamel, convertObjectToQuery, convertToHtmlBreaks, convertUnderToCamel, cutCHSString, cutZHString, debounce, deepCopy, deepCopyObject, deepFreeze, delCookie, doFn, extractElementText, fireEvent, floatFixed, floatToPercent, formatDate, formatDurationFromMs, genBrowserAttrs, genCustomConsole, genHashCode, genRndNumString, genStyleString, genUniqueNumString, generateCalendarVersion, generateRndNum, generateUniqueNum, getAllQueryParams, getBrowserInfo, getCLS, getCookie, getCurrentVersion, getDateDifference, 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, isStandalonePWA, isString, isSupportWebp, isSupportedEntryType, isUdfOrNul, isValidCssSelector, isValidData, isValidDate, isValidEmail, isValidHttpUrl, isValidPhoneNumber, isValidUrl, loadCSS, loadImage, loadScript, loadScriptIfUndefined, longestComSubsequence, longestComSubstring, mNow, mTrim, mazeyCon, newLine, onURLChange, parseGitHubRepository, parseJsonSafe, removeClass, removeCookie, removeEvent, removeHTML, removeHtml, repeatUntilConditionMet, replaceHttp, sanitizeInput, setClass, setCookie, setImgSizeBySrc, setImgWidHeiBySrc, setLocalStorage, setSessionStorage, sha256Hex, sleep, throttle, timeCon, toJavaScriptGlobalName, truncateZHString, unsanitize, unsanitizeInput, updateQueryParam, waitTime, windowLoaded, zAxiosIsValidRes };
3235
3313
  export type { GitHubRepositoryDetails, IsSafePWAEnvOptions };