minutool 1.0.24 → 1.0.26
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 +33 -24
- package/dist/minutool.js +888 -851
- 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
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* const req = abortableFetch('/api/data');
|
|
9
9
|
* req.abort('canceled'); // 中止请求
|
|
10
10
|
*/
|
|
11
|
-
export declare const abortableFetch: (url: string, fetchOption?: RequestOption) => AbortablePromise<
|
|
11
|
+
export declare const abortableFetch: <T = any>(url: string, fetchOption?: RequestOption) => AbortablePromise<T>;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* 可中止的 Fetch 请求
|
|
@@ -46,7 +46,7 @@ export declare const arrayChunk: <T = any>(list: T[], size: number) => T[][];
|
|
|
46
46
|
* @example
|
|
47
47
|
* arrayColumn([{id: 1, name: 'A'}, {id: 2, name: 'B'}], 'name') // ['A', 'B']
|
|
48
48
|
*/
|
|
49
|
-
export declare const arrayColumn: <T = any>(arr: T[], col_name: keyof T) =>
|
|
49
|
+
export declare const arrayColumn: <T = any>(arr: T[], col_name: keyof T) => T[keyof T][];
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* 数组去重
|
|
@@ -57,7 +57,7 @@ export declare const arrayColumn: <T = any>(arr: T[], col_name: keyof T) => any[
|
|
|
57
57
|
* arrayDistinct([1, 2, 2, 3, 3, 3]) // [1, 2, 3]
|
|
58
58
|
* arrayDistinct([{id: 1}, {id: 2}, {id: 1}], (item, index) => item.id) // [{id: 1}, {id: 2}]
|
|
59
59
|
*/
|
|
60
|
-
export declare const arrayDistinct: <T = any>(arr: T[], payload?: (item: T, index: number) =>
|
|
60
|
+
export declare const arrayDistinct: <T = any, K = any>(arr: T[], payload?: (item: T, index: number) => K) => T[];
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* 按指定键对数组进行分组
|
|
@@ -79,7 +79,7 @@ export declare const arrayGroup: <T extends Record<string, any>>(arr: T[], by_ke
|
|
|
79
79
|
* @example
|
|
80
80
|
* arrayIndex(['a', 'b', 'c'], 'b') // '1'
|
|
81
81
|
*/
|
|
82
|
-
export declare const arrayIndex: <T = any>(arr: T[], val: T) =>
|
|
82
|
+
export declare const arrayIndex: <T = any>(arr: T[], val: T) => number | null;
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* 按照对象的键进行字母顺序排序
|
|
@@ -97,7 +97,7 @@ export declare const arraySortByKey: <T extends Record<string, any>>(obj: T) =>
|
|
|
97
97
|
* @example
|
|
98
98
|
* arrayTrimTail([1, 2, 0, false, null]) // [1, 2]
|
|
99
99
|
*/
|
|
100
|
-
export declare const arrayTrimTail: (arr:
|
|
100
|
+
export declare const arrayTrimTail: <T>(arr: T[]) => T[];
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
103
|
* Base64 解码
|
|
@@ -142,7 +142,7 @@ export declare const between: (val: number, min: number, max: number, includeEqu
|
|
|
142
142
|
* @param payload - 事件回调函数
|
|
143
143
|
* @returns 解绑函数
|
|
144
144
|
*/
|
|
145
|
-
export declare const bindClick: (element: EventTarget | string, payload: (event:
|
|
145
|
+
export declare const bindClick: (element: EventTarget | string, payload: (event: MouseEvent) => void) => () => void;
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
* 绑定DOM事件,并返回一个解绑函数
|
|
@@ -159,7 +159,16 @@ export declare const bindDomEvent: <E extends Event = Event>(element: EventTarge
|
|
|
159
159
|
* @param payload - 事件回调函数
|
|
160
160
|
* @returns 解绑函数
|
|
161
161
|
*/
|
|
162
|
-
export declare const bindDoubleClick: (element: EventTarget | string, payload: (event:
|
|
162
|
+
export declare const bindDoubleClick: (element: EventTarget | string, payload: (event: MouseEvent) => void) => () => void;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 为 input/textarea 绑定支持 IME 的防抖函数
|
|
166
|
+
* @param element - DOM 元素
|
|
167
|
+
* @param callback - 回调,参数为 { value, event }
|
|
168
|
+
* @param delay - 防抖延迟(ms),默认 300
|
|
169
|
+
* @returns { destroy, cancel, flush }
|
|
170
|
+
*/
|
|
171
|
+
export declare const bindInputDebounce: (element: HTMLInputElement | HTMLTextAreaElement, callback: (value: string, event: InputEvent) => void, delay?: number) => (() => void);
|
|
163
172
|
|
|
164
173
|
/**
|
|
165
174
|
* 绑定键盘按键按下事件,并返回一个解绑函数
|
|
@@ -167,7 +176,7 @@ export declare const bindDoubleClick: (element: EventTarget | string, payload: (
|
|
|
167
176
|
* @param payload - 事件回调函数
|
|
168
177
|
* @returns 解绑函数
|
|
169
178
|
*/
|
|
170
|
-
export declare const bindKeyDown: (element: EventTarget | string, payload: (event:
|
|
179
|
+
export declare const bindKeyDown: (element: EventTarget | string, payload: (event: KeyboardEvent) => void) => () => void;
|
|
171
180
|
|
|
172
181
|
/**
|
|
173
182
|
* 绑定键盘按键抬起事件,并返回一个解绑函数
|
|
@@ -175,7 +184,7 @@ export declare const bindKeyDown: (element: EventTarget | string, payload: (even
|
|
|
175
184
|
* @param payload - 事件回调函数
|
|
176
185
|
* @returns 解绑函数
|
|
177
186
|
*/
|
|
178
|
-
export declare const bindKeyUp: (element: EventTarget | string, payload: (event:
|
|
187
|
+
export declare const bindKeyUp: (element: EventTarget | string, payload: (event: KeyboardEvent) => void) => () => void;
|
|
179
188
|
|
|
180
189
|
/**
|
|
181
190
|
* 绑定对象移动事件
|
|
@@ -191,7 +200,7 @@ export declare function bindNodeMove(element: HTMLElement | string, handle?: HTM
|
|
|
191
200
|
* @example
|
|
192
201
|
* blobToBase64(blob).then(base64 => console.log(base64))
|
|
193
202
|
*/
|
|
194
|
-
export declare const blobToBase64: (blob: Blob) => Promise<
|
|
203
|
+
export declare const blobToBase64: (blob: Blob) => Promise<string>;
|
|
195
204
|
|
|
196
205
|
/**
|
|
197
206
|
* 将 Blob 转换为 Data URI
|
|
@@ -265,7 +274,7 @@ export declare function capitalize(str: string): string;
|
|
|
265
274
|
* @example
|
|
266
275
|
* cleanNull({a: 1, b: null, c: {d: null}}, true) // {a: 1, c: {}}
|
|
267
276
|
*/
|
|
268
|
-
export declare const cleanNull: (obj:
|
|
277
|
+
export declare const cleanNull: <T>(obj: T, recursive?: boolean) => T;
|
|
269
278
|
|
|
270
279
|
export declare const COMMON_DPI = 96;
|
|
271
280
|
|
|
@@ -332,7 +341,7 @@ export declare const DAY_WEDNESDAY = 3;
|
|
|
332
341
|
* @example
|
|
333
342
|
* const debounced = debounce(() => console.log('called'), 1000)
|
|
334
343
|
*/
|
|
335
|
-
export declare const debounce: (fn:
|
|
344
|
+
export declare const debounce: <T extends (...args: any[]) => any>(fn: T, intervalMiSec: number) => T;
|
|
336
345
|
|
|
337
346
|
/**
|
|
338
347
|
* 解码 HTML 实体(包括 script 和 HTML 标签过滤)
|
|
@@ -415,7 +424,7 @@ export declare const disabled: (el: HTMLElement | string, disabledClass?: string
|
|
|
415
424
|
* @param event 事件名称
|
|
416
425
|
* @param detail 事件详情
|
|
417
426
|
*/
|
|
418
|
-
declare const dispatchEvent_2: (event: string | symbol, detail?:
|
|
427
|
+
declare const dispatchEvent_2: <T = any>(event: string | symbol, detail?: T) => void;
|
|
419
428
|
export { dispatchEvent_2 as dispatchEvent }
|
|
420
429
|
|
|
421
430
|
/**
|
|
@@ -443,7 +452,7 @@ export declare const enabled: (el: HTMLElement | string, disabledClass?: string)
|
|
|
443
452
|
* @example
|
|
444
453
|
* enterFullScreen(document.body)
|
|
445
454
|
*/
|
|
446
|
-
export declare const enterFullScreen: (element:
|
|
455
|
+
export declare const enterFullScreen: (element: HTMLElement) => Promise<void>;
|
|
447
456
|
|
|
448
457
|
/**
|
|
449
458
|
* HTML 实体转字符串
|
|
@@ -517,7 +526,7 @@ export declare const fileToBase64DataUri: (file: File | Blob | string) => Promis
|
|
|
517
526
|
* @example
|
|
518
527
|
* findAll('.item', container)
|
|
519
528
|
*/
|
|
520
|
-
export declare const findAll: (selector: string | Element | Element[], parent?: Document | DocumentFragment | Element) => Element[];
|
|
529
|
+
export declare const findAll: (selector: string | Element | Element[] | NodeList | HTMLCollection, parent?: Document | DocumentFragment | Element) => Element[];
|
|
521
530
|
|
|
522
531
|
/**
|
|
523
532
|
* 通过选择器查找单个节点
|
|
@@ -542,7 +551,7 @@ export declare const fixBaseUrl: (url: string, baseUrl: string) => string;
|
|
|
542
551
|
* @param {number} [defaultVal=0] - 转换失败时的默认值
|
|
543
552
|
* @returns {number} 返回转换后的浮点数,如果转换失败则返回默认值
|
|
544
553
|
*/
|
|
545
|
-
export declare const floatVal: (str:
|
|
554
|
+
export declare const floatVal: (str: unknown, defaultVal?: number) => number;
|
|
546
555
|
|
|
547
556
|
/**
|
|
548
557
|
* 格式化日期(以 PHP 方式格式化)
|
|
@@ -805,7 +814,7 @@ export declare const isLandscape: () => boolean;
|
|
|
805
814
|
* isNumberic('-123') // true
|
|
806
815
|
* isNumberic('210mm') // false
|
|
807
816
|
*/
|
|
808
|
-
export declare const isNumberic: (val:
|
|
817
|
+
export declare const isNumberic: (val: unknown) => boolean;
|
|
809
818
|
|
|
810
819
|
/**
|
|
811
820
|
* 检测目标是否为 Object(非数组的对象)
|
|
@@ -1331,7 +1340,7 @@ export declare const objectFromEntries: <T extends Record<string | number | symb
|
|
|
1331
1340
|
* get({ a: { b: { c: 1 } } }, 'a.b.c') // 1
|
|
1332
1341
|
* get({ a: { b: 1 } }, 'a.b.c', 0) // 0
|
|
1333
1342
|
*/
|
|
1334
|
-
export declare function objectGet<T = any>(obj:
|
|
1343
|
+
export declare function objectGet<T = any>(obj: object, path: string, defaultValue?: T): T;
|
|
1335
1344
|
|
|
1336
1345
|
/**
|
|
1337
1346
|
* 根据映射关系替换对象的键
|
|
@@ -1379,7 +1388,7 @@ export declare const objectSwitchKV: (obj: object) => any;
|
|
|
1379
1388
|
* @example
|
|
1380
1389
|
* objToQuery({name: 'John', age: 30}) // 'name=John&age=30'
|
|
1381
1390
|
*/
|
|
1382
|
-
export declare const objToQuery: (data:
|
|
1391
|
+
export declare const objToQuery: (data: any) => string;
|
|
1383
1392
|
|
|
1384
1393
|
/**
|
|
1385
1394
|
* 取消订阅事件,event 可以是字符串或 Symbol,handler 是事件处理函数
|
|
@@ -1617,7 +1626,7 @@ export declare const remove: (dom: HTMLElement | string) => Node | null;
|
|
|
1617
1626
|
* @example
|
|
1618
1627
|
* request('/api/data', null, {method: 'GET'})
|
|
1619
1628
|
*/
|
|
1620
|
-
export declare const request: (url: string, data
|
|
1629
|
+
export declare const request: (url: string, data?: any, requestOption?: RequestOption) => AbortablePromise<Response>;
|
|
1621
1630
|
|
|
1622
1631
|
/**
|
|
1623
1632
|
* 扩展 RequestInit,添加 timeout 和其他自定义属性,timeout 用于设置请求超时时间,其他自定义属性可以直接添加到 headers 中
|
|
@@ -1683,7 +1692,7 @@ export declare const show: (dom: HTMLElement | string) => void;
|
|
|
1683
1692
|
* @example
|
|
1684
1693
|
* srcToBase64('https://example.com/image.png').then(base64 => console.log(base64))
|
|
1685
1694
|
*/
|
|
1686
|
-
export declare const srcToBase64: (url: string, cache?: boolean) => Promise<
|
|
1695
|
+
export declare const srcToBase64: (url: string, cache?: boolean) => Promise<string>;
|
|
1687
1696
|
|
|
1688
1697
|
export declare const STAND_DPI = 96;
|
|
1689
1698
|
|
|
@@ -1788,7 +1797,7 @@ export declare const text2Html: (text: string) => string;
|
|
|
1788
1797
|
* @example
|
|
1789
1798
|
* const throttled = throttle(() => console.log('called'), 1000)
|
|
1790
1799
|
*/
|
|
1791
|
-
export declare const throttle: (fn:
|
|
1800
|
+
export declare const throttle: <T extends (...args: any[]) => any>(fn: T, intervalMiSec: number) => T;
|
|
1792
1801
|
|
|
1793
1802
|
/**
|
|
1794
1803
|
* 更有效果的节流函数
|
|
@@ -1800,7 +1809,7 @@ export declare const throttle: (fn: Function, intervalMiSec: number) => Function
|
|
|
1800
1809
|
* @example
|
|
1801
1810
|
* const throttled = throttleEffect(() => console.log('called'), 1000)
|
|
1802
1811
|
*/
|
|
1803
|
-
export declare const throttleEffect: (fn:
|
|
1812
|
+
export declare const throttleEffect: <T extends (...args: any[]) => any>(fn: T, intervalMiSec: number) => T;
|
|
1804
1813
|
|
|
1805
1814
|
/**
|
|
1806
1815
|
* 将时间戳转换为本地时间的日期时间字符串(YYYY-MM-DDTHH:mm),
|
|
@@ -1826,7 +1835,7 @@ export declare const toggleDisabled: (el: HTMLElement | string, disabledClass?:
|
|
|
1826
1835
|
* @example
|
|
1827
1836
|
* toggleFullScreen(document.body)
|
|
1828
1837
|
*/
|
|
1829
|
-
export declare const toggleFullScreen: (element:
|
|
1838
|
+
export declare const toggleFullScreen: (element: HTMLElement) => Promise<unknown>;
|
|
1830
1839
|
|
|
1831
1840
|
/**
|
|
1832
1841
|
* 触发HTML节点事件
|