minutool 1.0.21 → 1.0.23

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
@@ -12,9 +12,16 @@ export declare const abortableFetch: (url: string, fetchOption?: RequestOption)
12
12
 
13
13
  /**
14
14
  * 可中止的 Fetch 请求
15
+ * 完全独立定义,避免与 Promise 类型混淆
15
16
  */
16
- export declare interface AbortablePromise<T> extends Promise<T> {
17
+ export declare interface AbortablePromise<T> extends PromiseLike<T> {
17
18
  abort: () => void;
19
+ abortSilently: () => void;
20
+ aborted: boolean;
21
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): AbortablePromise<TResult1 | TResult2>;
22
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): AbortablePromise<T | TResult>;
23
+ finally(onfinally?: (() => void) | undefined | null): AbortablePromise<T>;
24
+ readonly [Symbol.toStringTag]: "Promise";
18
25
  }
19
26
 
20
27
  export declare class AbortError extends Error {
@@ -132,43 +139,43 @@ export declare const between: (val: number, min: number, max: number, includeEqu
132
139
  /**
133
140
  * 绑定点击事件,并返回一个解绑函数
134
141
  * @param element - 要绑定事件的元素
135
- * @param callback - 事件回调函数
142
+ * @param payload - 事件回调函数
136
143
  * @returns 解绑函数
137
144
  */
138
- export declare const bindClick: (element: HTMLElement | string, callback: (event: Event) => void) => () => void;
145
+ export declare const bindClick: (element: EventTarget | string, payload: (event: Event) => void) => () => void;
139
146
 
140
147
  /**
141
148
  * 绑定DOM事件,并返回一个解绑函数
142
149
  * @param element - 要绑定事件的元素
143
150
  * @param eventName - 事件名称
144
- * @param callback - 事件回调函数
151
+ * @param payload - 事件回调函数
145
152
  * @returns 解绑函数
146
153
  */
147
- export declare const bindDomEvent: (element: HTMLElement | string, eventName: string, callback: (event: Event) => void) => () => void;
154
+ export declare const bindDomEvent: <E extends Event = Event>(element: EventTarget | string, eventName: string, payload: (event: E) => void) => () => void;
148
155
 
149
156
  /**
150
157
  * 绑定双击事件,并返回一个解绑函数
151
158
  * @param element - 要绑定事件的元素
152
- * @param callback - 事件回调函数
159
+ * @param payload - 事件回调函数
153
160
  * @returns 解绑函数
154
161
  */
155
- export declare const bindDoubleClick: (element: HTMLElement | string, callback: (event: Event) => void) => () => void;
162
+ export declare const bindDoubleClick: (element: EventTarget | string, payload: (event: Event) => void) => () => void;
156
163
 
157
164
  /**
158
165
  * 绑定键盘按键按下事件,并返回一个解绑函数
159
166
  * @param element - 要绑定事件的元素
160
- * @param callback - 事件回调函数
167
+ * @param payload - 事件回调函数
161
168
  * @returns 解绑函数
162
169
  */
163
- export declare const bindKeyDown: (element: HTMLElement | string, callback: (event: Event) => void) => () => void;
170
+ export declare const bindKeyDown: (element: EventTarget | string, payload: (event: Event) => void) => () => void;
164
171
 
165
172
  /**
166
173
  * 绑定键盘按键抬起事件,并返回一个解绑函数
167
174
  * @param element - 要绑定事件的元素
168
- * @param callback - 事件回调函数
175
+ * @param payload - 事件回调函数
169
176
  * @returns 解绑函数
170
177
  */
171
- export declare const bindKeyUp: (element: HTMLElement | string, callback: (event: Event) => void) => () => void;
178
+ export declare const bindKeyUp: (element: EventTarget | string, payload: (event: Event) => void) => () => void;
172
179
 
173
180
  /**
174
181
  * 绑定对象移动事件
@@ -478,7 +485,7 @@ export declare const escapeHtml: (str: string, tabSize?: number, allowLineBreake
478
485
  * @param handler 事件处理函数, 参数为事件对象和匹配的子元素 (event, target)
479
486
  * @return 返回一个取消事件委托的函数
480
487
  */
481
- export declare const eventDelegate: (parent: HTMLElement | string, selector: string, event: string, handler: (event: Event, target: HTMLElement) => void) => () => void;
488
+ export declare const eventDelegate: (parent: EventTarget | string, selector: string, event: string, handler: (event: Event, target: Element) => void) => () => void;
482
489
 
483
490
  /**
484
491
  * 退出全屏模式
@@ -600,7 +607,7 @@ export declare const getDomDimension: (dom: HTMLElement) => {
600
607
  * @example
601
608
  * getJson('/api/users').then(data => console.log(data))
602
609
  */
603
- export declare const getJson: (url: string, data?: any, option?: RequestOption) => Promise<any>;
610
+ export declare const getJson: (url: string, data?: any, option?: RequestOption) => AbortablePromise<any>;
604
611
 
605
612
  /**
606
613
  * 获取节点的 XPath
@@ -1391,14 +1398,14 @@ export declare const onDocReady: (handler: () => void) => void;
1391
1398
 
1392
1399
  /**
1393
1400
  * 监听节点树变更
1394
- * @param {HTMLElement} dom - 要监听的 DOM 节点
1395
- * @param {Function} callback - 回调函数
1396
- * @param {boolean} [includeElementChanged=true] - 是否包含表单元素的值变更
1401
+ * @param dom - 要监听的 DOM 节点
1402
+ * @param payload - 回调函数
1403
+ * @param includeElementChanged - 是否包含表单元素的值变更
1397
1404
  * @returns {void}
1398
1405
  * @example
1399
1406
  * onDomTreeChange(container, () => console.log('changed'))
1400
1407
  */
1401
- export declare const onDomTreeChange: (dom: HTMLElement, callback: () => void, includeElementChanged?: boolean) => void;
1408
+ export declare const onDomTreeChange: (dom: HTMLElement, payload: () => void, includeElementChanged?: boolean) => void;
1402
1409
 
1403
1410
  export declare const ONE_DAY: number;
1404
1411
 
@@ -1459,7 +1466,7 @@ export declare const parseUnit: (value: string | number, defaultUnit?: string) =
1459
1466
  * @example
1460
1467
  * postFiles('/api/upload', {avatar: fileObject})
1461
1468
  */
1462
- export declare const postFiles: (url: string, fileMap: Record<string, File>, data?: any, option?: RequestOption) => Promise<any>;
1469
+ export declare const postFiles: (url: string, fileMap: Record<string, File>, data?: any, option?: RequestOption) => AbortablePromise<any>;
1463
1470
 
1464
1471
  /**
1465
1472
  * 发送 POST 请求并获取 JSON 响应
@@ -1470,7 +1477,7 @@ export declare const postFiles: (url: string, fileMap: Record<string, File>, dat
1470
1477
  * @example
1471
1478
  * postJson('/api/users', {name: 'John'}).then(data => console.log(data))
1472
1479
  */
1473
- export declare const postJson: (url: string, data?: any, option?: RequestOption) => Promise<any>;
1480
+ export declare const postJson: (url: string, data?: any, option?: RequestOption) => AbortablePromise<any>;
1474
1481
 
1475
1482
  /**
1476
1483
  * 精度位数转小数表示法
@@ -1828,7 +1835,7 @@ export declare const toggleFullScreen: (element: any) => Promise<unknown>;
1828
1835
  * @param node HTML节点
1829
1836
  * @param event 事件名称
1830
1837
  */
1831
- export declare const triggerDomEvent: (node: HTMLElement, event: string) => void;
1838
+ export declare const triggerDomEvent: (node: EventTarget, event: string) => void;
1832
1839
 
1833
1840
  /**
1834
1841
  * 去除字符串首尾指定字符或空白