minutool 1.0.20 → 1.0.22
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 +84 -12
- package/dist/minutool.js +674 -635
- package/dist/minutool.js.map +1 -1
- package/dist/minutool.umd.cjs +5 -5
- package/dist/minutool.umd.cjs.map +1 -1
- package/package.json +1 -1
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
|
|
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 {
|
|
@@ -92,6 +99,16 @@ export declare const arraySortByKey: <T extends Record<string, any>>(obj: T) =>
|
|
|
92
99
|
*/
|
|
93
100
|
export declare const arrayTrimTail: (arr: any[]) => any[];
|
|
94
101
|
|
|
102
|
+
/**
|
|
103
|
+
* 类型断言辅助函数:明确告诉 TypeScript 某个值是 AbortablePromise
|
|
104
|
+
* 用于解决 TypeScript 类型推导在某些情况下无法识别 AbortablePromise 的问题
|
|
105
|
+
* @param promise - 实际上是 AbortablePromise 的对象
|
|
106
|
+
* @returns 带有正确类型的 AbortablePromise
|
|
107
|
+
* @example
|
|
108
|
+
* const req = asAbortable(abortableFetch('/api').then(res => res.json()));
|
|
109
|
+
*/
|
|
110
|
+
export declare const asAbortable: <T>(promise: any) => AbortablePromise<T>;
|
|
111
|
+
|
|
95
112
|
/**
|
|
96
113
|
* Base64 解码
|
|
97
114
|
* @param {string} text - Base64 编码的字符串
|
|
@@ -129,6 +146,54 @@ export declare const base64UrlSafeEncode: (text: string) => string;
|
|
|
129
146
|
*/
|
|
130
147
|
export declare const between: (val: number, min: number, max: number, includeEqual?: boolean) => boolean;
|
|
131
148
|
|
|
149
|
+
/**
|
|
150
|
+
* 绑定点击事件,并返回一个解绑函数
|
|
151
|
+
* @param element - 要绑定事件的元素
|
|
152
|
+
* @param payload - 事件回调函数
|
|
153
|
+
* @returns 解绑函数
|
|
154
|
+
*/
|
|
155
|
+
export declare const bindClick: (element: HTMLElement | string, payload: (event: Event) => void) => () => void;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 绑定DOM事件,并返回一个解绑函数
|
|
159
|
+
* @param element - 要绑定事件的元素
|
|
160
|
+
* @param eventName - 事件名称
|
|
161
|
+
* @param payload - 事件回调函数
|
|
162
|
+
* @returns 解绑函数
|
|
163
|
+
*/
|
|
164
|
+
export declare const bindDomEvent: (element: HTMLElement | string, eventName: string, payload: (event: Event) => void) => () => void;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 绑定双击事件,并返回一个解绑函数
|
|
168
|
+
* @param element - 要绑定事件的元素
|
|
169
|
+
* @param payload - 事件回调函数
|
|
170
|
+
* @returns 解绑函数
|
|
171
|
+
*/
|
|
172
|
+
export declare const bindDoubleClick: (element: HTMLElement | string, payload: (event: Event) => void) => () => void;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 绑定键盘按键按下事件,并返回一个解绑函数
|
|
176
|
+
* @param element - 要绑定事件的元素
|
|
177
|
+
* @param payload - 事件回调函数
|
|
178
|
+
* @returns 解绑函数
|
|
179
|
+
*/
|
|
180
|
+
export declare const bindKeyDown: (element: HTMLElement | string, payload: (event: Event) => void) => () => void;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 绑定键盘按键抬起事件,并返回一个解绑函数
|
|
184
|
+
* @param element - 要绑定事件的元素
|
|
185
|
+
* @param payload - 事件回调函数
|
|
186
|
+
* @returns 解绑函数
|
|
187
|
+
*/
|
|
188
|
+
export declare const bindKeyUp: (element: HTMLElement | string, payload: (event: Event) => void) => () => void;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 绑定对象移动事件
|
|
192
|
+
* @param element - 要移动的元素
|
|
193
|
+
* @param handle - 拖动句柄,默认为元素本身
|
|
194
|
+
*/
|
|
195
|
+
export declare function bindNodeMove(element: HTMLElement | string, handle?: HTMLElement | string | null): () => void;
|
|
196
|
+
|
|
132
197
|
/**
|
|
133
198
|
* 转换 Blob 数据到 Base64 Data URL
|
|
134
199
|
* @param {Blob} blob - Blob 对象
|
|
@@ -430,7 +495,7 @@ export declare const escapeHtml: (str: string, tabSize?: number, allowLineBreake
|
|
|
430
495
|
* @param handler 事件处理函数, 参数为事件对象和匹配的子元素 (event, target)
|
|
431
496
|
* @return 返回一个取消事件委托的函数
|
|
432
497
|
*/
|
|
433
|
-
export declare const eventDelegate: (parent: HTMLElement, selector: string, event: string, handler: (event: Event, target: HTMLElement) => void) => () => void;
|
|
498
|
+
export declare const eventDelegate: (parent: HTMLElement | string, selector: string, event: string, handler: (event: Event, target: HTMLElement) => void) => () => void;
|
|
434
499
|
|
|
435
500
|
/**
|
|
436
501
|
* 退出全屏模式
|
|
@@ -552,7 +617,7 @@ export declare const getDomDimension: (dom: HTMLElement) => {
|
|
|
552
617
|
* @example
|
|
553
618
|
* getJson('/api/users').then(data => console.log(data))
|
|
554
619
|
*/
|
|
555
|
-
export declare const getJson: (url: string, data?: any, option?: RequestOption) =>
|
|
620
|
+
export declare const getJson: (url: string, data?: any, option?: RequestOption) => AbortablePromise<any>;
|
|
556
621
|
|
|
557
622
|
/**
|
|
558
623
|
* 获取节点的 XPath
|
|
@@ -846,8 +911,8 @@ export declare const loadScript: (src: string, forceReload?: boolean) => Promise
|
|
|
846
911
|
|
|
847
912
|
/**
|
|
848
913
|
* 绑定元素,禁止交互
|
|
849
|
-
* @param
|
|
850
|
-
* @param
|
|
914
|
+
* @param el - DOM 元素或选择器
|
|
915
|
+
* @param payload - 处理函数,参数为 reset
|
|
851
916
|
*/
|
|
852
917
|
export declare const lockElementInteraction: (el: HTMLElement | string, payload: (reset: () => void) => void) => void;
|
|
853
918
|
|
|
@@ -1343,14 +1408,14 @@ export declare const onDocReady: (handler: () => void) => void;
|
|
|
1343
1408
|
|
|
1344
1409
|
/**
|
|
1345
1410
|
* 监听节点树变更
|
|
1346
|
-
* @param
|
|
1347
|
-
* @param
|
|
1348
|
-
* @param
|
|
1411
|
+
* @param dom - 要监听的 DOM 节点
|
|
1412
|
+
* @param payload - 回调函数
|
|
1413
|
+
* @param includeElementChanged - 是否包含表单元素的值变更
|
|
1349
1414
|
* @returns {void}
|
|
1350
1415
|
* @example
|
|
1351
1416
|
* onDomTreeChange(container, () => console.log('changed'))
|
|
1352
1417
|
*/
|
|
1353
|
-
export declare const onDomTreeChange: (dom: HTMLElement,
|
|
1418
|
+
export declare const onDomTreeChange: (dom: HTMLElement, payload: () => void, includeElementChanged?: boolean) => void;
|
|
1354
1419
|
|
|
1355
1420
|
export declare const ONE_DAY: number;
|
|
1356
1421
|
|
|
@@ -1378,7 +1443,14 @@ export declare const onEvent: (event: string | symbol, handler: EventListenerOrE
|
|
|
1378
1443
|
|
|
1379
1444
|
export declare const onEvents: (events: (string | symbol)[], handler: EventListenerOrEventListenerObject) => () => void;
|
|
1380
1445
|
|
|
1381
|
-
|
|
1446
|
+
/**
|
|
1447
|
+
* 绑定元素 hover 事件,返回解绑函数
|
|
1448
|
+
* @param el - DOM 元素或选择器
|
|
1449
|
+
* @param onHoverIn - 鼠标进入回调函数
|
|
1450
|
+
* @param onHoverOut - 鼠标离开回调函数
|
|
1451
|
+
* @returns 返回解绑函数
|
|
1452
|
+
*/
|
|
1453
|
+
export declare const onHover: (el: HTMLElement | string, onHoverIn: () => void, onHoverOut: () => void) => () => void;
|
|
1382
1454
|
|
|
1383
1455
|
/**
|
|
1384
1456
|
* 非自关闭标签
|
|
@@ -1404,7 +1476,7 @@ export declare const parseUnit: (value: string | number, defaultUnit?: string) =
|
|
|
1404
1476
|
* @example
|
|
1405
1477
|
* postFiles('/api/upload', {avatar: fileObject})
|
|
1406
1478
|
*/
|
|
1407
|
-
export declare const postFiles: (url: string, fileMap: Record<string, File>, data?: any, option?: RequestOption) =>
|
|
1479
|
+
export declare const postFiles: (url: string, fileMap: Record<string, File>, data?: any, option?: RequestOption) => AbortablePromise<any>;
|
|
1408
1480
|
|
|
1409
1481
|
/**
|
|
1410
1482
|
* 发送 POST 请求并获取 JSON 响应
|
|
@@ -1415,7 +1487,7 @@ export declare const postFiles: (url: string, fileMap: Record<string, File>, dat
|
|
|
1415
1487
|
* @example
|
|
1416
1488
|
* postJson('/api/users', {name: 'John'}).then(data => console.log(data))
|
|
1417
1489
|
*/
|
|
1418
|
-
export declare const postJson: (url: string, data?: any, option?: RequestOption) =>
|
|
1490
|
+
export declare const postJson: (url: string, data?: any, option?: RequestOption) => AbortablePromise<any>;
|
|
1419
1491
|
|
|
1420
1492
|
/**
|
|
1421
1493
|
* 精度位数转小数表示法
|