minutool 1.0.24 → 1.0.25
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 +24 -24
- package/dist/minutool.js +857 -839
- 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,7 @@ 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
163
|
|
|
164
164
|
/**
|
|
165
165
|
* 绑定键盘按键按下事件,并返回一个解绑函数
|
|
@@ -167,7 +167,7 @@ export declare const bindDoubleClick: (element: EventTarget | string, payload: (
|
|
|
167
167
|
* @param payload - 事件回调函数
|
|
168
168
|
* @returns 解绑函数
|
|
169
169
|
*/
|
|
170
|
-
export declare const bindKeyDown: (element: EventTarget | string, payload: (event:
|
|
170
|
+
export declare const bindKeyDown: (element: EventTarget | string, payload: (event: KeyboardEvent) => void) => () => void;
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
173
|
* 绑定键盘按键抬起事件,并返回一个解绑函数
|
|
@@ -175,7 +175,7 @@ export declare const bindKeyDown: (element: EventTarget | string, payload: (even
|
|
|
175
175
|
* @param payload - 事件回调函数
|
|
176
176
|
* @returns 解绑函数
|
|
177
177
|
*/
|
|
178
|
-
export declare const bindKeyUp: (element: EventTarget | string, payload: (event:
|
|
178
|
+
export declare const bindKeyUp: (element: EventTarget | string, payload: (event: KeyboardEvent) => void) => () => void;
|
|
179
179
|
|
|
180
180
|
/**
|
|
181
181
|
* 绑定对象移动事件
|
|
@@ -191,7 +191,7 @@ export declare function bindNodeMove(element: HTMLElement | string, handle?: HTM
|
|
|
191
191
|
* @example
|
|
192
192
|
* blobToBase64(blob).then(base64 => console.log(base64))
|
|
193
193
|
*/
|
|
194
|
-
export declare const blobToBase64: (blob: Blob) => Promise<
|
|
194
|
+
export declare const blobToBase64: (blob: Blob) => Promise<string>;
|
|
195
195
|
|
|
196
196
|
/**
|
|
197
197
|
* 将 Blob 转换为 Data URI
|
|
@@ -265,7 +265,7 @@ export declare function capitalize(str: string): string;
|
|
|
265
265
|
* @example
|
|
266
266
|
* cleanNull({a: 1, b: null, c: {d: null}}, true) // {a: 1, c: {}}
|
|
267
267
|
*/
|
|
268
|
-
export declare const cleanNull: (obj:
|
|
268
|
+
export declare const cleanNull: <T>(obj: T, recursive?: boolean) => T;
|
|
269
269
|
|
|
270
270
|
export declare const COMMON_DPI = 96;
|
|
271
271
|
|
|
@@ -332,7 +332,7 @@ export declare const DAY_WEDNESDAY = 3;
|
|
|
332
332
|
* @example
|
|
333
333
|
* const debounced = debounce(() => console.log('called'), 1000)
|
|
334
334
|
*/
|
|
335
|
-
export declare const debounce: (fn:
|
|
335
|
+
export declare const debounce: <T extends (...args: any[]) => any>(fn: T, intervalMiSec: number) => T;
|
|
336
336
|
|
|
337
337
|
/**
|
|
338
338
|
* 解码 HTML 实体(包括 script 和 HTML 标签过滤)
|
|
@@ -415,7 +415,7 @@ export declare const disabled: (el: HTMLElement | string, disabledClass?: string
|
|
|
415
415
|
* @param event 事件名称
|
|
416
416
|
* @param detail 事件详情
|
|
417
417
|
*/
|
|
418
|
-
declare const dispatchEvent_2: (event: string | symbol, detail?:
|
|
418
|
+
declare const dispatchEvent_2: <T = any>(event: string | symbol, detail?: T) => void;
|
|
419
419
|
export { dispatchEvent_2 as dispatchEvent }
|
|
420
420
|
|
|
421
421
|
/**
|
|
@@ -443,7 +443,7 @@ export declare const enabled: (el: HTMLElement | string, disabledClass?: string)
|
|
|
443
443
|
* @example
|
|
444
444
|
* enterFullScreen(document.body)
|
|
445
445
|
*/
|
|
446
|
-
export declare const enterFullScreen: (element:
|
|
446
|
+
export declare const enterFullScreen: (element: HTMLElement) => Promise<void>;
|
|
447
447
|
|
|
448
448
|
/**
|
|
449
449
|
* HTML 实体转字符串
|
|
@@ -517,7 +517,7 @@ export declare const fileToBase64DataUri: (file: File | Blob | string) => Promis
|
|
|
517
517
|
* @example
|
|
518
518
|
* findAll('.item', container)
|
|
519
519
|
*/
|
|
520
|
-
export declare const findAll: (selector: string | Element | Element[], parent?: Document | DocumentFragment | Element) => Element[];
|
|
520
|
+
export declare const findAll: (selector: string | Element | Element[] | NodeList | HTMLCollection, parent?: Document | DocumentFragment | Element) => Element[];
|
|
521
521
|
|
|
522
522
|
/**
|
|
523
523
|
* 通过选择器查找单个节点
|
|
@@ -542,7 +542,7 @@ export declare const fixBaseUrl: (url: string, baseUrl: string) => string;
|
|
|
542
542
|
* @param {number} [defaultVal=0] - 转换失败时的默认值
|
|
543
543
|
* @returns {number} 返回转换后的浮点数,如果转换失败则返回默认值
|
|
544
544
|
*/
|
|
545
|
-
export declare const floatVal: (str:
|
|
545
|
+
export declare const floatVal: (str: unknown, defaultVal?: number) => number;
|
|
546
546
|
|
|
547
547
|
/**
|
|
548
548
|
* 格式化日期(以 PHP 方式格式化)
|
|
@@ -805,7 +805,7 @@ export declare const isLandscape: () => boolean;
|
|
|
805
805
|
* isNumberic('-123') // true
|
|
806
806
|
* isNumberic('210mm') // false
|
|
807
807
|
*/
|
|
808
|
-
export declare const isNumberic: (val:
|
|
808
|
+
export declare const isNumberic: (val: unknown) => boolean;
|
|
809
809
|
|
|
810
810
|
/**
|
|
811
811
|
* 检测目标是否为 Object(非数组的对象)
|
|
@@ -1331,7 +1331,7 @@ export declare const objectFromEntries: <T extends Record<string | number | symb
|
|
|
1331
1331
|
* get({ a: { b: { c: 1 } } }, 'a.b.c') // 1
|
|
1332
1332
|
* get({ a: { b: 1 } }, 'a.b.c', 0) // 0
|
|
1333
1333
|
*/
|
|
1334
|
-
export declare function objectGet<T = any>(obj:
|
|
1334
|
+
export declare function objectGet<T = any>(obj: object, path: string, defaultValue?: T): T;
|
|
1335
1335
|
|
|
1336
1336
|
/**
|
|
1337
1337
|
* 根据映射关系替换对象的键
|
|
@@ -1379,7 +1379,7 @@ export declare const objectSwitchKV: (obj: object) => any;
|
|
|
1379
1379
|
* @example
|
|
1380
1380
|
* objToQuery({name: 'John', age: 30}) // 'name=John&age=30'
|
|
1381
1381
|
*/
|
|
1382
|
-
export declare const objToQuery: (data:
|
|
1382
|
+
export declare const objToQuery: (data: any) => string;
|
|
1383
1383
|
|
|
1384
1384
|
/**
|
|
1385
1385
|
* 取消订阅事件,event 可以是字符串或 Symbol,handler 是事件处理函数
|
|
@@ -1617,7 +1617,7 @@ export declare const remove: (dom: HTMLElement | string) => Node | null;
|
|
|
1617
1617
|
* @example
|
|
1618
1618
|
* request('/api/data', null, {method: 'GET'})
|
|
1619
1619
|
*/
|
|
1620
|
-
export declare const request: (url: string, data
|
|
1620
|
+
export declare const request: (url: string, data?: any, requestOption?: RequestOption) => AbortablePromise<Response>;
|
|
1621
1621
|
|
|
1622
1622
|
/**
|
|
1623
1623
|
* 扩展 RequestInit,添加 timeout 和其他自定义属性,timeout 用于设置请求超时时间,其他自定义属性可以直接添加到 headers 中
|
|
@@ -1683,7 +1683,7 @@ export declare const show: (dom: HTMLElement | string) => void;
|
|
|
1683
1683
|
* @example
|
|
1684
1684
|
* srcToBase64('https://example.com/image.png').then(base64 => console.log(base64))
|
|
1685
1685
|
*/
|
|
1686
|
-
export declare const srcToBase64: (url: string, cache?: boolean) => Promise<
|
|
1686
|
+
export declare const srcToBase64: (url: string, cache?: boolean) => Promise<string>;
|
|
1687
1687
|
|
|
1688
1688
|
export declare const STAND_DPI = 96;
|
|
1689
1689
|
|
|
@@ -1788,7 +1788,7 @@ export declare const text2Html: (text: string) => string;
|
|
|
1788
1788
|
* @example
|
|
1789
1789
|
* const throttled = throttle(() => console.log('called'), 1000)
|
|
1790
1790
|
*/
|
|
1791
|
-
export declare const throttle: (fn:
|
|
1791
|
+
export declare const throttle: <T extends (...args: any[]) => any>(fn: T, intervalMiSec: number) => T;
|
|
1792
1792
|
|
|
1793
1793
|
/**
|
|
1794
1794
|
* 更有效果的节流函数
|
|
@@ -1800,7 +1800,7 @@ export declare const throttle: (fn: Function, intervalMiSec: number) => Function
|
|
|
1800
1800
|
* @example
|
|
1801
1801
|
* const throttled = throttleEffect(() => console.log('called'), 1000)
|
|
1802
1802
|
*/
|
|
1803
|
-
export declare const throttleEffect: (fn:
|
|
1803
|
+
export declare const throttleEffect: <T extends (...args: any[]) => any>(fn: T, intervalMiSec: number) => T;
|
|
1804
1804
|
|
|
1805
1805
|
/**
|
|
1806
1806
|
* 将时间戳转换为本地时间的日期时间字符串(YYYY-MM-DDTHH:mm),
|
|
@@ -1826,7 +1826,7 @@ export declare const toggleDisabled: (el: HTMLElement | string, disabledClass?:
|
|
|
1826
1826
|
* @example
|
|
1827
1827
|
* toggleFullScreen(document.body)
|
|
1828
1828
|
*/
|
|
1829
|
-
export declare const toggleFullScreen: (element:
|
|
1829
|
+
export declare const toggleFullScreen: (element: HTMLElement) => Promise<unknown>;
|
|
1830
1830
|
|
|
1831
1831
|
/**
|
|
1832
1832
|
* 触发HTML节点事件
|