minutool 1.0.0 → 1.0.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/dist/index.d.ts CHANGED
@@ -1,75 +1,114 @@
1
1
  /**
2
- * 数组分块
3
- * @param {Array} list 数据
4
- * @param {Number} size 每块大小
5
- * @return {Array[]}
2
+ * 使用 Fetch API 实现可中止的请求,支持超时设置
3
+ * @param {string} url - 请求 URL
4
+ * @param {any} [options={}] - 请求选项,包括 method、headers、body、timeout 等
5
+ * @returns {AbortablePromise<any>} 返回可中止的 Promise 对象
6
+ * @example
7
+ * const req = abortableFetch('/api/data');
8
+ * req.abort(); // 中止请求
9
+ */
10
+ export declare const abortableFetch: (url: string, options?: any) => AbortablePromise<any>;
11
+
12
+ /**
13
+ * 可中止的 Fetch 请求
14
+ */
15
+ export declare interface AbortablePromise<T> extends Promise<T> {
16
+ abort: () => void;
17
+ }
18
+
19
+ /**
20
+ * 将数组分割成指定大小的块
21
+ * @param {T[]} list - 源数组
22
+ * @param {number} size - 每块的大小
23
+ * @returns {T[][]} 分块后的二维数组
24
+ * @example
25
+ * arrayChunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]
6
26
  */
7
27
  export declare const arrayChunk: <T = any>(list: T[], size: number) => T[][];
8
28
 
9
29
  /**
10
- * array_column
11
- * @param arr
12
- * @param col_name
13
- * @returns {Array}
30
+ * 从数组中提取指定列的值
31
+ * @param {T[]} arr - 源数组
32
+ * @param {keyof T} col_name - 列名(对象的键)
33
+ * @returns {any[]} 提取的列值数组
34
+ * @example
35
+ * arrayColumn([{id: 1, name: 'A'}, {id: 2, name: 'B'}], 'name') // ['A', 'B']
14
36
  */
15
37
  export declare const arrayColumn: <T = any>(arr: T[], col_name: keyof T) => any[];
16
38
 
17
39
  /**
18
40
  * 数组去重
19
- * @param {Array} arr
20
- * @returns {*}
41
+ * @param {T[]} arr - 源数组
42
+ * @returns {T[]} 去重后的数组
43
+ * @example
44
+ * arrayDistinct([1, 2, 2, 3, 3, 3]) // [1, 2, 3]
21
45
  */
22
46
  export declare const arrayDistinct: <T = any>(arr: T[]) => T[];
23
47
 
24
48
  /**
25
- * array group
26
- * @param arr
27
- * @param by_key
28
- * @param limit limit one child
29
- * @returns {*}
49
+ * 按指定键对数组进行分组
50
+ * @param {T[]} arr - 源数组
51
+ * @param {keyof T} by_key - 分组依据的键
52
+ * @param {boolean} [limit] - 是否限制每组只保留一个元素
53
+ * @returns {Record<string, T[]> | Record<string, T>} 分组后的对象
54
+ * @example
55
+ * arrayGroup([{type: 'A', val: 1}, {type: 'A', val: 2}], 'type')
56
+ * // { A: [{type: 'A', val: 1}, {type: 'A', val: 2}] }
30
57
  */
31
58
  export declare const arrayGroup: <T extends Record<string, any>>(arr: T[], by_key: keyof T, limit?: boolean) => Record<string, T[]> | Record<string, T>;
32
59
 
33
60
  /**
34
- * @param arr
35
- * @param val
36
- * @return {string|null}
61
+ * 查找数组中指定值的索引
62
+ * @param {T[]} arr - 源数组
63
+ * @param {T} val - 要查找的值
64
+ * @returns {string|null} 返回索引字符串,未找到返回 null
65
+ * @example
66
+ * arrayIndex(['a', 'b', 'c'], 'b') // '1'
37
67
  */
38
68
  export declare const arrayIndex: <T = any>(arr: T[], val: T) => string | null;
39
69
 
40
70
  /**
41
- * 按照对象 KEY 排序
42
- * @param {Object} obj
43
- * @return {{}}
71
+ * 按照对象的键进行字母顺序排序
72
+ * @param {T} obj - 源对象
73
+ * @returns {T} 键排序后的对象
74
+ * @example
75
+ * arraySortByKey({c: 3, a: 1, b: 2}) // {a: 1, b: 2, c: 3}
44
76
  */
45
77
  export declare const arraySortByKey: <T extends Record<string, any>>(obj: T) => T;
46
78
 
47
79
  /**
48
80
  * 从数组末尾开始移除值为 falsy 的元素,直到遇到第一个 truthy 元素
49
- * @param arr 要处理的数组
50
- * @returns 处理后的数组
81
+ * @param {any[]} arr - 要处理的数组
82
+ * @returns {any[]} 处理后的数组
83
+ * @example
84
+ * arrayTrimTail([1, 2, 0, false, null]) // [1, 2]
51
85
  */
52
86
  export declare const arrayTrimTail: (arr: any[]) => any[];
53
87
 
54
88
  /**
55
- * base64 解码
56
- * @param {string} text
57
- * @returns {string}
89
+ * Base64 解码
90
+ * @param {string} text - Base64 编码的字符串
91
+ * @returns {string} 解码后的字符串
92
+ * @example
93
+ * base64Decode('SGVsbG8=') // 'Hello'
58
94
  */
59
95
  export declare const base64Decode: (text: string) => string;
60
96
 
61
97
  /**
62
- * text base64
63
- * @param {String} text
64
- * @return {string}
65
- * @constructor
98
+ * 字符串转 Base64 编码
99
+ * @param {string} text - 要编码的字符串
100
+ * @returns {string} Base64 编码后的字符串
101
+ * @example
102
+ * Base64Encode('Hello') // 'SGVsbG8='
66
103
  */
67
104
  export declare const Base64Encode: (text: string) => string;
68
105
 
69
106
  /**
70
- * URL 安全模式进行 base64 编码
71
- * @param {String} text
72
- * @return {string}
107
+ * URL 安全模式进行 Base64 编码(替换 + 和 / 为 - 和 _)
108
+ * @param {string} text - 要编码的字符串
109
+ * @returns {string} URL 安全的 Base64 编码字符串
110
+ * @example
111
+ * base64UrlSafeEncode('test') // URL安全的Base64字符串
73
112
  */
74
113
  export declare const base64UrlSafeEncode: (text: string) => string;
75
114
 
@@ -84,12 +123,21 @@ export declare const base64UrlSafeEncode: (text: string) => string;
84
123
  export declare const between: (val: number, min: number, max: number, includeEqual?: boolean) => boolean;
85
124
 
86
125
  /**
87
- * 转换blob数据到base64
88
- * @param {Blob} blob
89
- * @returns {Promise<unknown>}
126
+ * 转换 Blob 数据到 Base64 Data URL
127
+ * @param {Blob} blob - Blob 对象
128
+ * @returns {Promise<unknown>} 返回 Base64 Data URL 字符串的 Promise
129
+ * @example
130
+ * blobToBase64(blob).then(base64 => console.log(base64))
90
131
  */
91
132
  export declare const blobToBase64: (blob: Blob) => Promise<unknown>;
92
133
 
134
+ /**
135
+ * 将 Blob 转换为 Data URI
136
+ * @param {Blob} blob - Blob 对象
137
+ * @returns {Promise<string>} 返回 Data URI 字符串
138
+ * @example
139
+ * blobToDataUri(blob).then(uri => console.log(uri))
140
+ */
93
141
  export declare const blobToDataUri: (blob: Blob) => Promise<string>;
94
142
 
95
143
  /**
@@ -101,11 +149,20 @@ export declare const BLOCK_TAGS: string[];
101
149
 
102
150
  /**
103
151
  * 构建 HTML Input:hidden 标签
104
- * @param {Object} maps {key:value}
105
- * @return {string}
152
+ * @param {Record<string, any>} maps - 键值对对象
153
+ * @returns {string} 返回 HTML 字符串
154
+ * @example
155
+ * buildHtmlHidden({name: 'John', age: 30}) // '<input type="hidden" name="name" value="John"/>...'
106
156
  */
107
157
  export declare const buildHtmlHidden: (maps: Record<string, any>) => string;
108
158
 
159
+ /**
160
+ * 构建 CSS 变量对象(自动添加 -- 前缀和 px 单位)
161
+ * @param {Record<string, number|string|undefined>} vars - CSS 变量对象
162
+ * @returns {Record<string, string>} 返回格式化后的 CSS 变量对象
163
+ * @example
164
+ * buildStyleVars({width: 100, color: 'red'}) // {'--width': '100px', '--color': 'red'}
165
+ */
109
166
  export declare const buildStyleVars: (vars: Record<string, number | string | undefined>) => Record<string, string>;
110
167
 
111
168
  /**
@@ -129,38 +186,52 @@ export declare function capitalize(str: string): string;
129
186
 
130
187
  /**
131
188
  * 清理对象中的 null 值
189
+ * @param {any} obj - 要清理的对象
190
+ * @param {boolean} [recursive=false] - 是否递归清理子对象
191
+ * @returns {any} 返回清理后的对象
192
+ * @example
193
+ * cleanNull({a: 1, b: null, c: {d: null}}, true) // {a: 1, c: {}}
132
194
  */
133
195
  export declare const cleanNull: (obj: any, recursive?: boolean) => any;
134
196
 
135
197
  /**
136
- * 计时(该方法采用timeout方式,不够精准
137
- * @param {Number} timeout
138
- * @param {Function} tickFunc
139
- * @param {Function} onFinish
198
+ * 倒计时函数(该方法采用 setTimeout 方式,不够精准)
199
+ * @param {number} timeout - 倒计时总秒数
200
+ * @param {Function} [tickFunc] - 每秒回调函数,接收剩余秒数作为参数
201
+ * @param {Function} [onFinish] - 倒计时结束回调函数
202
+ * @returns {void}
203
+ * @example
204
+ * countDown(10, (sec) => console.log(sec), () => console.log('done'))
140
205
  */
141
206
  export declare const countDown: (timeout: number, tickFunc?: (timeout: number) => void, onFinish?: () => void) => void;
142
207
 
143
208
  /**
144
- * 创建HTML节点
145
- * @param {String} html
146
- * @param {HTMLElement|null} parentNode 父级节点
147
- * @returns {HTMLElement|HTMLElement[]}
209
+ * 创建 HTML 节点
210
+ * @param {string} html - HTML 字符串
211
+ * @param {HTMLElement|null} [parentNode=null] - 父级节点,如果提供则自动添加到父节点
212
+ * @returns {Node|Node[]} 返回创建的节点,单个或多个
213
+ * @example
214
+ * createDomByHtml('<div>Hello</div>')
148
215
  */
149
216
  export declare const createDomByHtml: (html: string, parentNode?: HTMLElement | null) => Node | Node[];
150
217
 
151
218
  /**
152
- * CSS 选择器转义
153
- * @param {String} str
154
- * @returns {String}
219
+ * CSS 选择器转义(处理特殊字符)
220
+ * @param {string} str - 要转义的字符串
221
+ * @returns {string} 转义后的字符串
222
+ * @example
223
+ * cssSelectorEscape('my#id') // 'my\\#id'
155
224
  */
156
225
  export declare const cssSelectorEscape: (str: string) => string;
157
226
 
158
227
  /**
159
- * 中英文字符串截取(中文按照2个字符长度计算)
160
- * @param str
161
- * @param len
162
- * @param eclipse_text
163
- * @returns {*}
228
+ * 中英文字符串截取(中文按照 2 个字符长度计算)
229
+ * @param {string} str - 要截取的字符串
230
+ * @param {number} len - 截取长度
231
+ * @param {string} [eclipse_text='...'] - 省略符,默认为 '...'
232
+ * @returns {string} 返回截取后的字符串
233
+ * @example
234
+ * cutString('中文English', 6, '...') // '中文E...'
164
235
  */
165
236
  export declare const cutString: (str: string, len: number, eclipse_text?: string) => string;
166
237
 
@@ -181,13 +252,23 @@ export declare const DAY_TUESDAY = 2;
181
252
  export declare const DAY_WEDNESDAY = 3;
182
253
 
183
254
  /**
184
- * 在事件被触发n秒后再执行回调,如果在这n秒内又被触发,则重新计时。
185
- * @param {Function} fn
186
- * @param {Number} intervalMiSec
187
- * @return {(function(): void)|*}
255
+ * 防抖函数
256
+ * 在事件被触发 n 秒后再执行回调,如果在这 n 秒内又被触发,则重新计时。
257
+ * @param {Function} fn - 要防抖的函数
258
+ * @param {number} intervalMiSec - 间隔时间(毫秒)
259
+ * @returns {Function} 返回防抖后的函数
260
+ * @example
261
+ * const debounced = debounce(() => console.log('called'), 1000)
188
262
  */
189
263
  export declare const debounce: (fn: Function, intervalMiSec: number) => Function;
190
264
 
265
+ /**
266
+ * 解码 HTML 实体(包括 script 和 HTML 标签过滤)
267
+ * @param {string} str - 包含 HTML 实体的字符串
268
+ * @returns {string} 返回解码后的字符串
269
+ * @example
270
+ * decodeHTMLEntities('&lt;div&gt;') // '<div>'
271
+ */
191
272
  export declare const decodeHTMLEntities: (str: string) => string;
192
273
 
193
274
  /**
@@ -200,8 +281,11 @@ export declare const decodeHTMLEntities: (str: string) => string;
200
281
  export declare function deepClone<T>(obj: T): T;
201
282
 
202
283
  /**
203
- * 删除cookie
204
- * @param name
284
+ * 删除 Cookie
285
+ * @param {string} name - Cookie 名称
286
+ * @returns {void}
287
+ * @example
288
+ * deleteCookie('username')
205
289
  */
206
290
  export declare const deleteCookie: (name: string) => void;
207
291
 
@@ -212,12 +296,21 @@ export declare const deleteCookie: (name: string) => void;
212
296
  */
213
297
  export declare const detectedPrecision: (...numbers: number[]) => number;
214
298
 
299
+ /**
300
+ * 检测浏览器语言(支持完全匹配和前缀匹配)
301
+ * @param {string[]} supportedLngs - 支持的语言列表
302
+ * @returns {string} 返回匹配的语言或第一个支持的语言
303
+ * @example
304
+ * detectLanguage(['en', 'zh-CN', 'zh']) // '根据浏览器语言返回匹配的语言'
305
+ */
215
306
  export declare const detectLanguage: (supportedLngs: string[]) => any;
216
307
 
217
308
  /**
218
309
  * 计算数字位数
219
- * @param {Number} n
220
- * @returns
310
+ * @param {number} n - 要计算的数字
311
+ * @returns {number} 返回数字的位数
312
+ * @example
313
+ * digitCount(123) // 3
221
314
  */
222
315
  export declare const digitCount: (n: number) => number;
223
316
 
@@ -237,8 +330,11 @@ export declare const disabled: (el: HTMLElement | string, disabledClass?: string
237
330
 
238
331
  /**
239
332
  * 下载文件
240
- * @param {String} uri
241
- * @param {String} fileName
333
+ * @param {string} uri - 文件 URI(支持 Data URI 和普通 URL)
334
+ * @param {string} fileName - 保存的文件名
335
+ * @returns {void}
336
+ * @example
337
+ * downloadFile('data:text/plain;base64,SGVsbG8=', 'hello.txt')
242
338
  */
243
339
  export declare const downloadFile: (uri: string, fileName: string) => void;
244
340
 
@@ -251,37 +347,49 @@ export declare const enabled: (el: HTMLElement | string, disabledClass?: string)
251
347
 
252
348
  /**
253
349
  * 进入全屏模式
254
- * @param {HTMLElement} element
350
+ * @param {HTMLElement} element - 要全屏显示的元素
351
+ * @returns {Promise<void>} 返回 Promise,全屏操作完成后 resolve
352
+ * @throws {string} 如果浏览器不支持全屏,抛出错误
353
+ * @example
354
+ * enterFullScreen(document.body)
255
355
  */
256
356
  export declare const enterFullScreen: (element: any) => Promise<void>;
257
357
 
258
358
  /**
259
- * HTML实例转字符串
260
- * @param {string} entity
261
- * @returns {string}
359
+ * HTML 实体转字符串
360
+ * @param {string} entity - HTML 实体字符串(如 &#72;&#101;&#108;&#108;&#111;)
361
+ * @returns {string} 返回解码后的字符串
362
+ * @example
363
+ * entityToString('&#72;&#101;') // 'He'
262
364
  */
263
365
  export declare const entityToString: (entity: string) => string;
264
366
 
265
367
  /**
266
- * 转义HTML到属性值
267
- * @param {String} s
268
- * @param preserveCR
269
- * @returns {string}
368
+ * 转义 HTML 到属性值(处理属性中的特殊字符)
369
+ * @param {string} s - 要转义的字符串
370
+ * @param {string} [preserveCR=''] - 是否保留回车符
371
+ * @returns {string} 返回转义后的字符串
372
+ * @example
373
+ * escapeAttr('Hello "World"') // 'Hello &quot;World&quot;'
270
374
  */
271
375
  export declare const escapeAttr: (s: string, preserveCR?: string) => string;
272
376
 
273
377
  /**
274
- * 转义HTML
275
- * @param {string} str
276
- * @param {Number} tabSize tab宽度,如果设置为0,表示去除tab
277
- * @param {Boolean} allowLineBreaker 是否允许换行
278
- * @returns {string}
378
+ * 转义 HTML(将特殊字符转换为 HTML 实体)
379
+ * @param {string} str - 要转义的字符串
380
+ * @param {number} [tabSize=2] - Tab 宽度,如果设置为 0,表示去除 tab
381
+ * @param {boolean} [allowLineBreaker=true] - 是否允许换行
382
+ * @returns {string} 返回转义后的 HTML
383
+ * @example
384
+ * escapeHtml('<div>Hello</div>') // '&lt;div&gt;Hello&lt;/div&gt;'
279
385
  */
280
386
  export declare const escapeHtml: (str: string, tabSize?: number, allowLineBreaker?: boolean) => string;
281
387
 
282
388
  /**
283
- * 退出全屏
284
- * @returns {Promise<void>}
389
+ * 退出全屏模式
390
+ * @returns {Promise<void>} 返回 Promise,退出全屏操作完成后 resolve
391
+ * @example
392
+ * exitFullScreen()
285
393
  */
286
394
  export declare const exitFullScreen: () => Promise<void>;
287
395
 
@@ -295,57 +403,80 @@ export declare const exitFullScreen: () => Promise<void>;
295
403
  export declare const extract: (es_template: string, params: Record<string, any>) => string;
296
404
 
297
405
  /**
298
- * 将文件转换为 Base64 data URL
406
+ * 将文件转换为 Base64 Data URI
299
407
  * 支持 File/Blob 对象,或字符串 URL(http(s)/相对/blob:)
300
- * @param {File|Blob|String} file
301
- * @returns {Promise<String|null>} 返回 data URL 字符串,失败返回 null
408
+ * @param {File|Blob|string} file - 文件对象或 URL 字符串
409
+ * @returns {Promise<string|null>} 返回 Data URL 字符串,失败返回 null
410
+ * @example
411
+ * fileToBase64DataUri(file).then(uri => console.log(uri))
302
412
  */
303
413
  export declare const fileToBase64DataUri: (file: File | Blob | string) => Promise<string | null>;
304
414
 
305
415
  /**
306
- * 通过选择器查找子节点(强制添加 :scope来约束必须是子节点)
307
- * @param {String} selector
308
- * @param {Node} parent
309
- * @return {Node[]}
416
+ * 通过选择器查找子节点(强制添加 :scope 来约束必须是子节点)
417
+ * @param {string|HTMLElement|HTMLElement[]|NodeList|HTMLCollection} selector - 选择器或 DOM 元素
418
+ * @param {Document|HTMLElement} [parent=document] - 父节点,默认为 document
419
+ * @returns {HTMLElement[]} 返回查找到的所有元素数组
420
+ * @example
421
+ * findAll('.item', container)
310
422
  */
311
423
  export declare const findAll: (selector: string | HTMLElement | HTMLElement[] | NodeList | HTMLCollection, parent?: Document | HTMLElement) => HTMLElement[];
312
424
 
313
425
  /**
314
- * @param {String|Object} selector 选择器,如果是Object,则直接返回Object
315
- * @param {Node} parent
316
- * @return {Node}
426
+ * 通过选择器查找单个节点
427
+ * @param {string|HTMLElement} selector - 选择器,如果是 HTMLElement,则直接返回
428
+ * @param {Document|HTMLElement} [parent=document] - 父节点,默认为 document
429
+ * @returns {HTMLElement} 返回查找到的元素
430
+ * @example
431
+ * findOne('.item')
317
432
  */
318
433
  export declare const findOne: (selector: string | HTMLElement, parent?: Document | HTMLElement) => HTMLElement;
319
434
 
435
+ /**
436
+ * 修复基本 URL(将相对路径转换为绝对 URL)
437
+ * @param {string} url - 要修复的 URL
438
+ * @param {string} baseUrl - 基本 URL
439
+ * @returns {string} 返回修复后的 URL
440
+ * @example
441
+ * fixBaseUrl('/path', 'https://example.com') // 'https://example.com/path'
442
+ */
320
443
  export declare const fixBaseUrl: (url: string, baseUrl: string) => string;
321
444
 
322
445
  /**
323
- * 格式化日期(以PHP方式格式化)
324
- * @param {String} format
325
- * @param {Object,Number,String} date 日期,可以是日期对象、毫秒数或者日期字符串,缺省为今天
326
- * @return {String}
446
+ * 格式化日期(以 PHP 方式格式化)
447
+ * @param {string} format - 格式化字符串(支持 PHP date 函数的格式)
448
+ * @param {Date|number|string|null} [date=null] - 日期,可以是日期对象、毫秒数或者日期字符串,缺省为今天
449
+ * @returns {string} 返回格式化后的日期字符串
450
+ * @example
451
+ * formatDate('Y-m-d H:i:s') // '2024-03-11 15:30:00'
327
452
  */
328
453
  export declare const formatDate: (format: string, date?: Date | number | string | null) => string;
329
454
 
330
455
  /**
331
- * 获取元素的位置(相对于视口)
332
- * @param {HTMLElement} el
333
- * @returns
456
+ * 获取元素的位置(相对于视口)
457
+ * @param {HTMLElement} el - DOM 元素
458
+ * @param {boolean} [autoFixInvisible=false] - 是否自动修正隐藏元素无法测量的 bug
459
+ * @returns {RectObject} 返回元素的位置和尺寸信息
460
+ * @example
461
+ * getBoundingClientRect(element) // {top: 100, left: 50, width: 200, height: 100, ...}
334
462
  */
335
463
  export declare const getBoundingClientRect: (el: HTMLElement, autoFixInvisible?: boolean) => RectObject;
336
464
 
337
465
  /**
338
- * 获取cookie
339
- * @param {String} name
340
- * @returns {string|null}
466
+ * 获取 Cookie
467
+ * @param {string} name - Cookie 名称
468
+ * @returns {string|null} 返回 Cookie 值,未找到返回 null
469
+ * @example
470
+ * getCookie('username') // 'john'
341
471
  */
342
472
  export declare const getCookie: (name: string) => string | null;
343
473
 
344
474
  /**
345
- * 获取对象宽、高
346
- * 通过设置 visibility 方式进行获取
347
- * @param {HTMLElement} dom
348
- * @return {{width: number, height: number}}
475
+ * 获取对象宽、高(通过设置 visibility 方式进行获取)
476
+ * @param {HTMLElement} dom - DOM 元素
477
+ * @returns {{width: number, height: number}} 返回元素的宽度和高度
478
+ * @example
479
+ * getDomDimension(element) // {width: 100, height: 50}
349
480
  */
350
481
  export declare const getDomDimension: (dom: HTMLElement) => {
351
482
  width: number;
@@ -353,62 +484,111 @@ export declare const getDomDimension: (dom: HTMLElement) => {
353
484
  };
354
485
 
355
486
  /**
356
- * get node xpath
357
- * @param el
358
- * @return {String}
487
+ * 发送 GET 请求并获取 JSON 响应
488
+ * @param {string} url - 请求 URL
489
+ * @param {any} [data=null] - 请求数据
490
+ * @param {RequestOption} [option={}] - 请求选项
491
+ * @returns {Promise<any>} 返回解析后的 JSON 数据
492
+ * @example
493
+ * getJson('/api/users').then(data => console.log(data))
494
+ */
495
+ export declare const getJson: (url: string, data?: any, option?: RequestOption) => Promise<any>;
496
+
497
+ /**
498
+ * 获取节点的 XPath
499
+ * @param {HTMLElement|null} el - DOM 元素
500
+ * @returns {string|null} 返回 XPath 字符串,失败返回 null
501
+ * @example
502
+ * getNodeXPath(element) // '/html[1]/body[1]/div[1]'
359
503
  */
360
504
  export declare const getNodeXPath: (el: HTMLElement | null) => string | null;
361
505
 
362
506
  /**
363
- * 获取u8字符串长度(一个中文字按照3个字数计算)
364
- * @param str
365
- * @returns {number}
507
+ * 获取 UTF-8 字符串长度(一个中文字按照 3 个字数计算)
508
+ * @param {string} str - 要计算的字符串
509
+ * @returns {number} 返回字符串长度
510
+ * @example
511
+ * getUTF8StrLen('中文') // 6
366
512
  */
367
513
  export declare const getUTF8StrLen: (str: string) => number;
368
514
 
515
+ /**
516
+ * 获取日期所在周数(ISO 8601 标准)
517
+ * @param {Date} date - 日期对象
518
+ * @returns {number} 返回周数
519
+ * @example
520
+ * getWeekNumber(new Date('2024-03-11')) // 11
521
+ */
522
+ export declare const getWeekNumber: (date: Date) => number;
523
+
369
524
  /** 黄金分割比 0.618 **/
370
525
  export declare const GOLDEN_RATIO: number;
371
526
 
527
+ /**
528
+ * 生成全局唯一 ID
529
+ * @param {string} [prefix=''] - ID 前缀
530
+ * @returns {string} 返回唯一 ID
531
+ * @example
532
+ * guid('user') // 'guid_user123_1'
533
+ */
372
534
  export declare const guid: (prefix?: string) => string;
373
535
 
374
536
  /**
375
- * 隐藏节点(通过设置display:none方式)
376
- * @param {Node|String} dom
537
+ * 隐藏节点(通过设置 display:none 方式)
538
+ * @param {HTMLElement|string} dom - DOM 元素或选择器
539
+ * @returns {void}
540
+ * @example
541
+ * hide('#myElement')
377
542
  */
378
543
  export declare const hide: (dom: HTMLElement | string) => void;
379
544
 
380
545
  /**
381
- * 高亮文本
382
- * @param {String} text 文本
383
- * @param {String} kw 关键字
384
- * @param {String} replaceTpl 替换模板
385
- * @returns {void|string|*}
546
+ * 高亮文本(将关键字用指定模板包裹)
547
+ * @param {string} text - 原始文本
548
+ * @param {string} kw - 关键字
549
+ * @param {string} [replaceTpl='<span class="matched">%s</span>'] - 替换模板,%s 为占位符
550
+ * @returns {string} 返回高亮后的 HTML
551
+ * @example
552
+ * highlightText('Hello World', 'World') // 'Hello <span class="matched">World</span>'
386
553
  */
387
554
  export declare const highlightText: (text: string, kw: string, replaceTpl?: string) => string;
388
555
 
389
556
  /**
390
- * Convert html to plain text
391
- * @param {String} html
392
- * @returns {string}
557
+ * HTML 转换为纯文本(移除所有标签和样式)
558
+ * @param {string} html - HTML 字符串
559
+ * @returns {string} 返回纯文本
560
+ * @example
561
+ * html2Text('<p>Hello <b>World</b></p>') // 'Hello World'
393
562
  */
394
563
  export declare const html2Text: (html: string) => string;
395
564
 
396
565
  /**
397
- * 通过 Image 获取base64数据
398
- * @param img
399
- * @returns {string|string|*|string|null}
566
+ * 通过 Image 元素获取 Base64 数据
567
+ * @param {HTMLImageElement} img - 图片元素
568
+ * @returns {string|null} 返回 Base64 Data URL,失败返回 null
569
+ * @example
570
+ * imgToBase64(imageElement) // 'data:image/png;base64,...'
400
571
  */
401
572
  export declare const imgToBase64: (img: HTMLImageElement) => string | null;
402
573
 
403
574
  /**
404
575
  * 在头部插入样式
405
- * @param {String} styleSheetStr 样式代码
406
- * @param {String} id 样式ID,如果提供ID,将会检测是否已经插入,可以避免重复插入
407
- * @param {Document} doc 文档上下文
408
- * @return {HTMLStyleElement}
576
+ * @param {string} styleSheetStr - 样式代码
577
+ * @param {string} [id=''] - 样式 ID,如果提供 ID,将会检测是否已经插入,可以避免重复插入
578
+ * @param {Document} [doc=document] - 文档上下文
579
+ * @returns {HTMLStyleElement|null} 返回创建的 style 元素
580
+ * @example
581
+ * insertStyleSheet('.test { color: red; }', 'my-style')
409
582
  */
410
583
  export declare const insertStyleSheet: (styleSheetStr: string, id?: string, doc?: Document) => HTMLStyleElement | null;
411
584
 
585
+ /**
586
+ * 检测值是否为 BodyInit 可接受的类型
587
+ * @param {any} value - 要检测的值
588
+ * @returns {boolean} 如果是 BodyInit 可接受的类型返回 true,否则返回 false
589
+ */
590
+ export declare const isBodyInit: (value: any) => value is BodyInit;
591
+
412
592
  /**
413
593
  * 判断对象是否为空
414
594
  * @param obj - 要判断的对象
@@ -419,41 +599,83 @@ export declare const insertStyleSheet: (styleSheetStr: string, id?: string, doc?
419
599
  */
420
600
  export declare function isEmptyObject(obj: object): boolean;
421
601
 
602
+ /**
603
+ * 检测是否为 Firefox 浏览器
604
+ * @returns {boolean} 如果是 Firefox 浏览器,返回 true,否则返回 false
605
+ * @example
606
+ * isFirefox() // false
607
+ */
608
+ export declare const isFirefox: () => boolean;
609
+
610
+ /**
611
+ * 检测元素是否可聚焦
612
+ * @param {HTMLElement} el - DOM 元素
613
+ * @returns {boolean} 如果元素可聚焦返回 true,否则返回 false
614
+ * @example
615
+ * isFocusable(inputElement) // true
616
+ */
422
617
  export declare const isFocusable: (el: HTMLElement) => boolean;
423
618
 
619
+ /**
620
+ * 检测是否为函数
621
+ * @param {any} value - 要检测的值
622
+ * @returns {boolean} 如果是函数返回 true,否则返回 false
623
+ * @example
624
+ * isFunction(() => {}) // true
625
+ */
424
626
  export declare const isFunction: (value: any) => boolean;
425
627
 
426
628
  /**
427
629
  * 检测是否正在全屏
428
- * @returns {boolean}
630
+ * @returns {boolean} 如果当前正在全屏模式,返回 true,否则返回 false
631
+ * @example
632
+ * isInFullScreen() // false
429
633
  */
430
634
  export declare const isInFullScreen: () => boolean;
431
635
 
432
636
  /**
433
637
  * 判断字符串是否符合 JSON 标准
434
- * @param {String} json
435
- * @returns {boolean}
638
+ * @param {string} json - 要检测的字符串
639
+ * @returns {boolean} 如果是有效 JSON 返回 true,否则返回 false
640
+ * @example
641
+ * isJSON('{"name":"John"}') // true
436
642
  */
437
643
  export declare const isJSON: (json: string) => boolean;
438
644
 
645
+ /**
646
+ * 检测字符串是否为有效的 JSON
647
+ * @param {string} json - 要检测的字符串
648
+ * @returns {boolean} 如果是有效 JSON 返回 true,否则返回 false
649
+ * @example
650
+ * isJson('{"name":"John"}') // true
651
+ */
439
652
  export declare const isJson: (json: string) => boolean;
440
653
 
441
654
  /**
442
- * 检测目标是否为 Object
443
- * @param {*} item
444
- * @returns {boolean}
655
+ * 检测目标是否为 Object(非数组的对象)
656
+ * @param {any} item - 要检测的对象
657
+ * @returns {boolean} 如果是对象返回 true,否则返回 false
658
+ * @example
659
+ * isObject({}) // true
660
+ * isObject([]) // false
445
661
  */
446
662
  export declare const isObject: (item: any) => boolean;
447
663
 
448
664
  /**
449
- * 检测对象是否为Promise对象
450
- * @param {*} obj
451
- * @returns {boolean}
665
+ * 检测对象是否为 Promise 对象
666
+ * @param {any} obj - 要检测的对象
667
+ * @returns {boolean} 如果是 Promise 返回 true,否则返回 false
668
+ * @example
669
+ * isPromise(Promise.resolve()) // true
452
670
  */
453
671
  export declare const isPromise: (obj: any) => boolean;
454
672
 
455
673
  /**
456
674
  * 检测是否为 URL(不包含 blob: data: file: 等协议)
675
+ * @param {string} str - 要检测的字符串
676
+ * @returns {boolean} 如果是 URL 返回 true,否则返回 false
677
+ * @example
678
+ * isUrl('https://example.com') // true
457
679
  */
458
680
  export declare const isUrl: (str: string) => boolean;
459
681
 
@@ -487,17 +709,33 @@ export declare const keepRectInContainer: (objDim: Dimension, ctnDim?: Dimension
487
709
  };
488
710
 
489
711
  /**
490
- * 挂载css文件
491
- * @param {String} file
492
- * @param {Boolean} forceReload 是否强制重新挂载,缺省不重复挂载
712
+ * 限制数值在指定范围内
713
+ * @param {number} num - 要限制的数值
714
+ * @param {number} min - 最小值
715
+ * @param {number} max - 最大值
716
+ * @returns {number} 返回限制后的数值
717
+ * @example
718
+ * limit(150, 0, 100) // 100
719
+ */
720
+ export declare const limit: (num: number, min: number, max: number) => number;
721
+
722
+ /**
723
+ * 挂载 CSS 文件
724
+ * @param {string} file - CSS 文件路径
725
+ * @param {boolean} [forceReload=false] - 是否强制重新挂载,缺省不重复挂载
726
+ * @returns {Promise<void>} 返回 Promise,加载完成后 resolve
727
+ * @example
728
+ * loadCss('/styles/theme.css')
493
729
  */
494
730
  export declare const loadCss: (file: string, forceReload?: boolean) => Promise<void>;
495
731
 
496
732
  /**
497
- * 加载script脚本
498
- * @param {String} src 脚本地址
499
- * @param {Boolean} forceReload 是否强制重新加载,缺省为去重加载
500
- * @return {Promise}
733
+ * 加载 Script 脚本
734
+ * @param {string} src - 脚本地址
735
+ * @param {boolean} [forceReload=false] - 是否强制重新加载,缺省为去重加载
736
+ * @returns {Promise<void>} 返回 Promise,加载完成后 resolve
737
+ * @example
738
+ * loadScript('/scripts/lib.js')
501
739
  */
502
740
  export declare const loadScript: (src: string, forceReload?: boolean) => Promise<void>;
503
741
 
@@ -508,6 +746,15 @@ export declare const loadScript: (src: string, forceReload?: boolean) => Promise
508
746
  */
509
747
  export declare const lockElementInteraction: (el: HTMLElement | string, payload: (reset: () => void) => void) => void;
510
748
 
749
+ /**
750
+ * 计算字符串的 MD5 哈希值
751
+ * @param {string} string - 要计算 MD5 的字符串
752
+ * @param {string} [key] - HMAC 密钥(可选)
753
+ * @param {boolean} [raw] - 是否返回原始字符串,默认返回十六进制字符串
754
+ * @returns {string} 返回 MD5 哈希值
755
+ * @example
756
+ * md5('Hello World') // 'b10a8db164e0754105b7a99be72e3fe5'
757
+ */
511
758
  export declare const md5: (string: string, key?: string, raw?: boolean) => string;
512
759
 
513
760
  /**
@@ -820,38 +1067,77 @@ export declare const MIME_EXTENSION_MAP: {
820
1067
  zip: string;
821
1068
  };
822
1069
 
1070
+ export declare const MIME_FORM = "application/x-www-form-urlencoded";
1071
+
1072
+ export declare const MIME_HTML = "text/html";
1073
+
1074
+ export declare const MIME_JSON = "application/json";
1075
+
1076
+ export declare const MIME_MULTIPART = "multipart/form-data";
1077
+
1078
+ export declare const MIME_TEXT = "text/plain";
1079
+
1080
+ /**
1081
+ * 将 mm 转换为磅(Point)
1082
+ * @param {number} mm - 毫米值
1083
+ * @returns {number} 返回磅值
1084
+ * @example
1085
+ * mmToPt(1) // 2.83
1086
+ */
1087
+ export declare const mmToPt: (mm: number) => number;
1088
+
823
1089
  /**
824
1090
  * 毫米转换成像素
825
- * @param {float} dimension
826
- * @param {int} dpi
827
- * @returns int
1091
+ * @param {number} dimension - 毫米值
1092
+ * @param {number} [dpi=STAND_DPI] - DPI 值,默认为标准 DPI (96)
1093
+ * @returns {number} 返回像素值
1094
+ * @example
1095
+ * mmToPx(25.4) // 96
828
1096
  */
829
1097
  export declare const mmToPx: (dimension: number, dpi?: number) => number;
830
1098
 
1099
+ /**
1100
+ * 将 mm 转换为 TWIP(Twentieth of a Point)
1101
+ * @param {number} mm - 毫米值
1102
+ * @returns {number} 返回 TWIP 值
1103
+ * @example
1104
+ * mmToTwip(1) // 57
1105
+ */
1106
+ export declare const mmToTwip: (mm: number) => number;
1107
+
831
1108
  export declare const MONTH_NAMES_CN: string[];
832
1109
 
833
1110
  export declare const MONTH_NAMES_SHORT_CN: string[];
834
1111
 
835
1112
  export declare const MONTH_NOW: number;
836
1113
 
1114
+ /**
1115
+ * 毫秒转换为“时分秒前”格式
1116
+ * @param {number} ms - 毫秒数
1117
+ * @returns {string} 返回格式化后的字符串
1118
+ * @example
1119
+ * msToHMS(3661000) // '1小时0分钟1秒前'
1120
+ */
837
1121
  export declare const msToHMS: (ms: number) => string;
838
1122
 
839
1123
  /**
840
- * 更低占用执行mutation监听,支持指定最小间隔时间执行回调
841
- * @param {Node} dom
842
- * @param {Object} option
843
- * @param {Boolean} option.attributes
844
- * @param {Boolean} option.subtree
845
- * @param {Boolean} option.childList
846
- * @param {Function} payload
847
- * @param {Number} minInterval 执行回调最小间隔时间(毫秒)
1124
+ * 更低占用执行 mutation 监听,支持指定最小间隔时间执行回调
1125
+ * @param {HTMLElement} dom - 要监听的 DOM 节点
1126
+ * @param {MutationObserverInit} option - MutationObserver 配置选项
1127
+ * @param {Function} payload - 回调函数,接收 MutationObserver 实例作为参数
1128
+ * @param {number} [minInterval=10] - 执行回调最小间隔时间(毫秒)
1129
+ * @returns {void}
1130
+ * @example
1131
+ * mutationEffective(dom, {attributes: true, childList: true}, (obs) => console.log('changed'))
848
1132
  */
849
1133
  export declare const mutationEffective: (dom: HTMLElement, option: MutationObserverInit, payload: (obs: MutationObserver) => void, minInterval?: number) => void;
850
1134
 
851
1135
  /**
852
- * 获取当前节点在父结点中的索引号
853
- * @param node
854
- * @return {number}
1136
+ * 获取当前节点在父节点中的索引号
1137
+ * @param {HTMLElement} node - DOM 节点
1138
+ * @returns {number} 返回索引号,如果没有父节点返回 -1
1139
+ * @example
1140
+ * nodeIndex(element) // 2
855
1141
  */
856
1142
  export declare const nodeIndex: (node: HTMLElement) => number;
857
1143
 
@@ -868,10 +1154,12 @@ export declare const nodeIndex: (node: HTMLElement) => number;
868
1154
  export declare function objectGet<T = any>(obj: any, path: string, defaultValue?: T): T;
869
1155
 
870
1156
  /**
871
- * 对象属性名转换
872
- * @param {Object} obj
873
- * @param {Object} mapping
874
- * @return {{}}
1157
+ * 对象属性名转换(根据映射表重命名属性)
1158
+ * @param {Record<string, any>} obj - 源对象
1159
+ * @param {Record<string, string>} mapping - 属性名映射表
1160
+ * @returns {Record<string, any>} 返回转换后的对象
1161
+ * @example
1162
+ * objectKeyMapping({a: 1, b: 2}, {a: 'x'}) // {x: 1, b: 2}
875
1163
  */
876
1164
  export declare const objectKeyMapping: (obj: Record<string, any>, mapping: Record<string, string>) => Record<string, any>;
877
1165
 
@@ -895,11 +1183,23 @@ export declare function objectMerge<T extends object>(target: T, ...sources: Par
895
1183
  */
896
1184
  export declare function objectSet(obj: any, path: string, value: any): void;
897
1185
 
1186
+ /**
1187
+ * 将对象转换为 URL 查询字符串
1188
+ * @param {Record<string, any>} data - 数据对象
1189
+ * @returns {string} 返回查询字符串
1190
+ * @example
1191
+ * objToQuery({name: 'John', age: 30}) // 'name=John&age=30'
1192
+ */
1193
+ export declare const objToQuery: (data: Record<string, any>) => string;
1194
+
898
1195
  /**
899
1196
  * 监听节点树变更
900
- * @param {Node} dom
901
- * @param {Function} callback
902
- * @param {Boolean} includeElementChanged 是否包含表单元素的值变更
1197
+ * @param {HTMLElement} dom - 要监听的 DOM 节点
1198
+ * @param {Function} callback - 回调函数
1199
+ * @param {boolean} [includeElementChanged=true] - 是否包含表单元素的值变更
1200
+ * @returns {void}
1201
+ * @example
1202
+ * onDomTreeChange(container, () => console.log('changed'))
903
1203
  */
904
1204
  export declare const onDomTreeChange: (dom: HTMLElement, callback: () => void, includeElementChanged?: boolean) => void;
905
1205
 
@@ -919,6 +1219,8 @@ export declare const ONE_YEAR365: number;
919
1219
 
920
1220
  export declare const ONE_YEAR366: number;
921
1221
 
1222
+ export declare const onHover: (el: HTMLElement | string, onHoverIn: () => void, onHoverOut: () => void) => void;
1223
+
922
1224
  /**
923
1225
  * 非自关闭标签
924
1226
  * https://www.w3schools.com/html/html_blocks.asp
@@ -926,18 +1228,84 @@ export declare const ONE_YEAR366: number;
926
1228
  */
927
1229
  export declare const PAIR_TAGS: string[];
928
1230
 
1231
+ /**
1232
+ * 上传文件
1233
+ * @param {string} url - 请求 URL
1234
+ * @param {Record<string, File>} fileMap - 文件对象映射
1235
+ * @param {any} [data=null] - 额外的表单数据
1236
+ * @param {RequestOption} [option={}] - 请求选项
1237
+ * @returns {Promise<any>} 返回解析后的 JSON 数据
1238
+ * @example
1239
+ * postFiles('/api/upload', {avatar: fileObject})
1240
+ */
1241
+ export declare const postFiles: (url: string, fileMap: Record<string, File>, data?: any, option?: RequestOption) => Promise<any>;
1242
+
1243
+ /**
1244
+ * 发送 POST 请求并获取 JSON 响应
1245
+ * @param {string} url - 请求 URL
1246
+ * @param {any} [data=null] - 请求数据
1247
+ * @param {RequestOption} [option={}] - 请求选项
1248
+ * @returns {Promise<any>} 返回解析后的 JSON 数据
1249
+ * @example
1250
+ * postJson('/api/users', {name: 'John'}).then(data => console.log(data))
1251
+ */
1252
+ export declare const postJson: (url: string, data?: any, option?: RequestOption) => Promise<any>;
1253
+
929
1254
  /**
930
1255
  * 精度位数转小数表示法
931
- * @param {Number} precision 精度位数
932
- * @returns {Float} 精度小数表示法,如 0.01
1256
+ * @param {number} precision - 精度位数
1257
+ * @returns {number} 精度小数表示法,如 0.01
1258
+ * @example
1259
+ * precisionToStep(2) // 0.01
933
1260
  */
934
1261
  export declare const precisionToStep: (precision: number) => number;
935
1262
 
936
1263
  /**
937
1264
  * 打印调用堆栈
1265
+ * @returns {void}
1266
+ * @example
1267
+ * printStack() // 在控制台输出堆栈信息
938
1268
  */
939
1269
  export declare const printStack: () => void;
940
1270
 
1271
+ /**
1272
+ * 将磅(Point)转换为 mm
1273
+ * @param {number} pt - 磅值
1274
+ * @returns {number} 返回毫米值
1275
+ * @example
1276
+ * ptToMm(2.83) // 1
1277
+ */
1278
+ export declare const ptToMm: (pt: number) => number;
1279
+
1280
+ /**
1281
+ * 像素转毫米
1282
+ * @param {number} px - 像素值
1283
+ * @param {number} [dpi=STAND_DPI] - DPI 值,默认为标准 DPI (96)
1284
+ * @returns {number} 返回毫米值
1285
+ * @example
1286
+ * pxToMm(96) // 25.4
1287
+ */
1288
+ export declare const pxToMm: (px: number, dpi?: number) => number;
1289
+
1290
+ /**
1291
+ * 替换 URL 中的查询参数
1292
+ * @param {string} url - 原始 URL
1293
+ * @param {Record<string, any>} newQuery - 新的查询参数对象
1294
+ * @returns {string} 返回更新后的 URL
1295
+ * @example
1296
+ * queryReplace('http://example.com?a=1', {b: 2}) // 'http://example.com?a=1&b=2'
1297
+ */
1298
+ export declare const queryReplace: (url: string, newQuery: Record<string, any>) => string;
1299
+
1300
+ /**
1301
+ * 将 URL 查询字符串转换为对象
1302
+ * @param {string} query - 查询字符串
1303
+ * @returns {Record<string, string>} 返回键值对对象
1304
+ * @example
1305
+ * queryToObj('name=John&age=30') // {name: 'John', age: '30'}
1306
+ */
1307
+ export declare const queryToObj: (query: string) => Record<string, string>;
1308
+
941
1309
  /**
942
1310
  * 随机整数
943
1311
  * @param {Number} min
@@ -964,17 +1332,21 @@ export declare const randomWords: (count?: number, letterMax?: number) => string
964
1332
 
965
1333
  /**
966
1334
  * 矩形相交(包括边重叠情况)
967
- * @param {Object} rect1
968
- * @param {Object} rect2
969
- * @returns {boolean}
1335
+ * @param {Dimension} rect1 - 第一个矩形对象
1336
+ * @param {Dimension} rect2 - 第二个矩形对象
1337
+ * @returns {boolean} 如果两个矩形相交返回 true,否则返回 false
1338
+ * @example
1339
+ * rectAssoc({left: 0, top: 0, width: 100, height: 100}, {left: 50, top: 50, width: 100, height: 100}) // true
970
1340
  */
971
1341
  export declare const rectAssoc: (rect1: Dimension, rect2: Dimension) => boolean;
972
1342
 
973
1343
  /**
974
1344
  * 检测矩形是否在指定布局内部
975
- * @param rect
976
- * @param layout
977
- * @returns {*}
1345
+ * @param {Dimension} rect - 要检测的矩形
1346
+ * @param {Dimension} layout - 布局矩形
1347
+ * @returns {boolean} 如果矩形在布局内部返回 true,否则返回 false
1348
+ * @example
1349
+ * rectInLayout(rect, layout) // true
978
1350
  */
979
1351
  export declare const rectInLayout: (rect: Dimension, layout: Dimension) => boolean;
980
1352
 
@@ -988,9 +1360,11 @@ declare interface RectObject {
988
1360
  }
989
1361
 
990
1362
  /**
991
- * 正则表达式转义
992
- * @param str
993
- * @returns {string}
1363
+ * 正则表达式转义(将特殊字符转义)
1364
+ * @param {string} str - 要转义的字符串
1365
+ * @returns {string} 返回转义后的字符串
1366
+ * @example
1367
+ * regQuote('a.b') // 'a\\.b'
994
1368
  */
995
1369
  export declare const regQuote: (str: string) => string;
996
1370
 
@@ -1000,8 +1374,34 @@ export declare const regQuote: (str: string) => string;
1000
1374
  */
1001
1375
  export declare const REMOVABLE_TAGS: string[];
1002
1376
 
1377
+ /**
1378
+ * 移除 DOM 节点
1379
+ * @param {HTMLElement|string} dom - DOM 元素或选择器
1380
+ * @returns {Node|null} 返回被移除的节点,如果未找到返回 null
1381
+ * @example
1382
+ * remove('#myElement')
1383
+ */
1003
1384
  export declare const remove: (dom: HTMLElement | string) => Node | null;
1004
1385
 
1386
+ /**
1387
+ * 发送 HTTP 请求
1388
+ * @param {string} url - 请求 URL
1389
+ * @param {BodyInit|null} [data=null] - 请求数据,可以是字符串、FormData、URLSearchParams、Blob、ArrayBuffer 等,如果是对象会根据 ContentType 自动转换(例如 application/json 会自动 JSON.stringify)
1390
+ * @param {RequestOption} option - 请求选项
1391
+ * @returns {AbortablePromise<Response>} 返回可中止的 Promise
1392
+ * @example
1393
+ * request('/api/data', null, {method: 'GET'})
1394
+ */
1395
+ export declare const request: (url: string, data: (BodyInit | null) | undefined, option: RequestOption) => AbortablePromise<Response>;
1396
+
1397
+ declare interface RequestOption {
1398
+ method?: string;
1399
+ headers?: Record<string, string>;
1400
+ ContentType?: string;
1401
+ Accept?: string;
1402
+ timeout?: number;
1403
+ }
1404
+
1005
1405
  /**
1006
1406
  * 取整
1007
1407
  * @param {Number} num
@@ -1026,30 +1426,56 @@ export declare const sanitizeFileName: (name: string) => string;
1026
1426
  export declare const SELF_CLOSING_TAGS: string[];
1027
1427
 
1028
1428
  /**
1029
- * 设置cookie
1030
- * @param {String} name
1031
- * @param {String} value
1032
- * @param {Number} days
1033
- * @param {String} path
1429
+ * 设置 Cookie
1430
+ * @param {string} name - Cookie 名称
1431
+ * @param {string} value - Cookie 值
1432
+ * @param {number} days - 有效天数,0 表示会话 Cookie
1433
+ * @param {string} [path='/'] - Cookie 路径,默认为根路径
1434
+ * @returns {void}
1435
+ * @example
1436
+ * setCookie('username', 'john', 7)
1034
1437
  */
1035
1438
  export declare const setCookie: (name: string, value: string, days: number, path?: string) => void;
1036
1439
 
1037
1440
  /**
1038
- * 显示节点(通过设置display为空方式)
1039
- * @param {HTMLElement} dom
1040
- * @param dom
1441
+ * 显示节点(通过设置 display 为空方式)
1442
+ * @param {HTMLElement|string} dom - DOM 元素或选择器
1443
+ * @returns {void}
1444
+ * @example
1445
+ * show('#myElement')
1041
1446
  */
1042
1447
  export declare const show: (dom: HTMLElement | string) => void;
1043
1448
 
1044
1449
  /**
1045
- * 通过ImageSrc获取base64(网络请求模式)
1046
- * @param src
1047
- * @returns {Promise<unknown>}
1450
+ * 通过图片 URL 获取 Base64(网络请求模式)
1451
+ * @param {string} src - 图片 URL
1452
+ * @param {boolean} [cache=false] - 是否缓存结果
1453
+ * @returns {Promise<unknown>} 返回 Base64 Data URL 的 Promise
1454
+ * @example
1455
+ * srcToBase64('https://example.com/image.png').then(base64 => console.log(base64))
1048
1456
  */
1049
1457
  export declare const srcToBase64: (src: string, cache?: boolean) => Promise<unknown>;
1050
1458
 
1051
1459
  export declare const STAND_DPI = 96;
1052
1460
 
1461
+ /**
1462
+ * 将字符串分割成指定长度的数组
1463
+ * @param {string} str - 要分割的字符串
1464
+ * @param {number} size - 每段的长度
1465
+ * @returns {string[]} 返回分割后的数组
1466
+ * @example
1467
+ * strChunk('abcdef', 2) // ['ab', 'cd', 'ef']
1468
+ */
1469
+ export declare const strChunk: (str: string, size: number) => string[];
1470
+
1471
+ /**
1472
+ * 字符串转换为 HTML 实体
1473
+ * @param {string} str - 要转换的字符串
1474
+ * @param {number} [radix] - 进制,为 16 时使用十六进制
1475
+ * @returns {string} 返回 HTML 实体字符串
1476
+ * @example
1477
+ * stringToEntity('AB', 16) // '&#x41;&#x42;'
1478
+ */
1053
1479
  export declare const stringToEntity: (str: string, radix?: number) => string;
1054
1480
 
1055
1481
  /**
@@ -1076,28 +1502,35 @@ export declare const stringToEntity: (str: string, radix?: number) => string;
1076
1502
  export declare const stripSlashes: (str: string) => string;
1077
1503
 
1078
1504
  /**
1079
- * 字符串转成首字母大写
1080
- * @param {String} str
1081
- * @param {Boolean} capitalize_first 是否将第一个单词首字母大写
1082
- * @return {string}
1505
+ * 字符串转成首字母大写(Pascal Case)
1506
+ * @param {string} str - 要转换的字符串
1507
+ * @param {boolean} [capitalize_first=false] - 是否将第一个单词首字母大写
1508
+ * @returns {string} 返回转换后的字符串
1509
+ * @example
1510
+ * strToPascalCase('hello-world', true) // 'HelloWorld'
1083
1511
  */
1084
1512
  export declare const strToPascalCase: (str: string, capitalize_first?: boolean) => string;
1085
1513
 
1086
1514
  /**
1087
- * 节流
1515
+ * 节流函数
1088
1516
  * 规定在一个单位时间内,只能触发一次函数。如果这个函数单位时间内触发多次函数,只有一次生效。
1089
- * @param {Function} fn
1090
- * @param {Number} intervalMiSec
1091
- * @return {(function(): void)|*}
1517
+ * @param {Function} fn - 要节流的函数
1518
+ * @param {number} intervalMiSec - 间隔时间(毫秒)
1519
+ * @returns {Function} 返回节流后的函数
1520
+ * @example
1521
+ * const throttled = throttle(() => console.log('called'), 1000)
1092
1522
  */
1093
1523
  export declare const throttle: (fn: Function, intervalMiSec: number) => Function;
1094
1524
 
1095
1525
  /**
1096
1526
  * 更有效果的节流函数
1097
1527
  * 区别:如果函数执行间隔还没到期,放入下一个时间周期执行,如果已经有下一周期未执行,当前触发作废。
1098
- * 这种效果在 **Change 类型函数场景中更有效果,可以确保最后一次变更能够有效执行
1099
- * @param {Function} fn
1100
- * @param {Number} intervalMiSec
1528
+ * 这种效果在 Change 类型函数场景中更有效果,可以确保最后一次变更能够有效执行
1529
+ * @param {Function} fn - 要节流的函数
1530
+ * @param {number} intervalMiSec - 间隔时间(毫秒)
1531
+ * @returns {Function} 返回节流后的函数
1532
+ * @example
1533
+ * const throttled = throttleEffect(() => console.log('called'), 1000)
1101
1534
  */
1102
1535
  export declare const throttleEffect: (fn: Function, intervalMiSec: number) => Function;
1103
1536
 
@@ -1110,18 +1543,22 @@ export declare const throttleEffect: (fn: Function, intervalMiSec: number) => Fu
1110
1543
  export declare const toggleDisabled: (el: HTMLElement | string, disabledClass?: string, forceEnabled?: boolean | null) => void;
1111
1544
 
1112
1545
  /**
1113
- * 切换全屏
1114
- * @param element
1115
- * @returns {Promise<unknown>}
1546
+ * 切换全屏模式(全屏时退出,非全屏时进入)
1547
+ * @param {HTMLElement} element - 要全屏显示的元素
1548
+ * @returns {Promise<unknown>} 返回 Promise
1549
+ * @example
1550
+ * toggleFullScreen(document.body)
1116
1551
  */
1117
1552
  export declare const toggleFullScreen: (element: any) => Promise<unknown>;
1118
1553
 
1119
1554
  /**
1120
1555
  * 去除字符串首尾指定字符或空白
1121
- * @param {String} str 源字符串
1122
- * @param {String} chars 指定字符,默认为空白
1123
- * @param {Number} dir 方向
1124
- * @returns {*|boolean}
1556
+ * @param {string} str - 源字符串
1557
+ * @param {string} [chars=''] - 指定字符,默认为空白
1558
+ * @param {number} [dir=TRIM_BOTH] - 方向(TRIM_BOTH/TRIM_LEFT/TRIM_RIGHT)
1559
+ * @returns {string} 返回去除后的字符串
1560
+ * @example
1561
+ * trim('__hello__', '_') // 'hello'
1125
1562
  */
1126
1563
  export declare const trim: (str: string, chars?: string, dir?: number) => string;
1127
1564
 
@@ -1143,29 +1580,40 @@ export declare const TRIM_RIGHT = 2;
1143
1580
  export declare function truncate(str: string, length: number, suffix?: string): string;
1144
1581
 
1145
1582
  /**
1146
- * 反转义HTML
1147
- * @param {String} html
1148
- * @returns {string}
1583
+ * 反转义 HTML(将 HTML 实体转换为字符)
1584
+ * @param {string} html - 包含 HTML 实体的字符串
1585
+ * @returns {string} 返回反转义后的字符串
1586
+ * @example
1587
+ * unescapeHtml('&lt;div&gt;') // '<div>'
1149
1588
  */
1150
1589
  export declare const unescapeHtml: (html: string) => string;
1151
1590
 
1152
1591
  /**
1153
- * urlBase64Data 数据缓存
1154
- * @param {String} url
1155
- * @param {String|Null} b64Data base64 数据,传入 null 则为读取缓存,这里不是不是base64,而是 base64 data URL
1156
- * @returns {String|Null} 读取缓存时返回 base64 data URL 字符串,未命中返回 null
1592
+ * URLBase64 Data URL 数据缓存
1593
+ * @param {string} url - 文件 URL
1594
+ * @param {string|null} [b64Data=null] - Base64 Data URL 数据,传入 null 则为读取缓存
1595
+ * @returns {string|null} 读取缓存时返回 Base64 Data URL 字符串,未命中返回 null
1596
+ * @example
1597
+ * urlB64DataCache('http://example.com/img.png', dataUrl) // 设置缓存
1598
+ * urlB64DataCache('http://example.com/img.png') // 读取缓存
1157
1599
  */
1158
1600
  export declare const urlB64DataCache: (url: string, b64Data?: string | null) => string | null;
1159
1601
 
1160
1602
  /**
1161
- * @param {String} srcStr
1162
- * @return {string}
1603
+ * UTF-8 解码
1604
+ * @param {string} srcStr - 要解码的字符串
1605
+ * @returns {string} 返回解码后的字符串
1606
+ * @example
1607
+ * utf8Decode(encodedStr) // 'decoded string'
1163
1608
  */
1164
1609
  export declare const utf8Decode: (srcStr: string) => string;
1165
1610
 
1166
1611
  /**
1167
- * @param {String} srcStr
1168
- * @returns {string}
1612
+ * UTF-8 编码
1613
+ * @param {string} srcStr - 要编码的字符串
1614
+ * @returns {string} 返回编码后的字符串
1615
+ * @example
1616
+ * utf8Encode('string') // 'encoded string'
1169
1617
  */
1170
1618
  export declare const utf8Encode: (srcStr: string) => string;
1171
1619