minutool 1.0.23 → 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 +28 -30
- package/dist/minutool.js +858 -840
- 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
|
|
|
@@ -281,13 +281,11 @@ export declare const countDown: (timeout: number, tickFunc?: (timeout: number) =
|
|
|
281
281
|
|
|
282
282
|
/**
|
|
283
283
|
* 创建 HTML 节点
|
|
284
|
-
* @param
|
|
285
|
-
* @param
|
|
286
|
-
* @returns
|
|
287
|
-
* @example
|
|
288
|
-
* createDomByHtml('<div>Hello</div>')
|
|
284
|
+
* @param html - HTML 字符串
|
|
285
|
+
* @param [parentNode=null] - 父级节点,如果提供则自动添加到父节点
|
|
286
|
+
* @returns 返回创建的元素,单个或多个
|
|
289
287
|
*/
|
|
290
|
-
export declare const createDomByHtml: (html: string, parentNode?: HTMLElement | null) =>
|
|
288
|
+
export declare const createDomByHtml: <T extends Element = Element>(html: string, parentNode?: HTMLElement | null) => T | T[];
|
|
291
289
|
|
|
292
290
|
/**
|
|
293
291
|
* CSS 选择器转义(处理特殊字符)
|
|
@@ -334,7 +332,7 @@ export declare const DAY_WEDNESDAY = 3;
|
|
|
334
332
|
* @example
|
|
335
333
|
* const debounced = debounce(() => console.log('called'), 1000)
|
|
336
334
|
*/
|
|
337
|
-
export declare const debounce: (fn:
|
|
335
|
+
export declare const debounce: <T extends (...args: any[]) => any>(fn: T, intervalMiSec: number) => T;
|
|
338
336
|
|
|
339
337
|
/**
|
|
340
338
|
* 解码 HTML 实体(包括 script 和 HTML 标签过滤)
|
|
@@ -417,7 +415,7 @@ export declare const disabled: (el: HTMLElement | string, disabledClass?: string
|
|
|
417
415
|
* @param event 事件名称
|
|
418
416
|
* @param detail 事件详情
|
|
419
417
|
*/
|
|
420
|
-
declare const dispatchEvent_2: (event: string | symbol, detail?:
|
|
418
|
+
declare const dispatchEvent_2: <T = any>(event: string | symbol, detail?: T) => void;
|
|
421
419
|
export { dispatchEvent_2 as dispatchEvent }
|
|
422
420
|
|
|
423
421
|
/**
|
|
@@ -445,7 +443,7 @@ export declare const enabled: (el: HTMLElement | string, disabledClass?: string)
|
|
|
445
443
|
* @example
|
|
446
444
|
* enterFullScreen(document.body)
|
|
447
445
|
*/
|
|
448
|
-
export declare const enterFullScreen: (element:
|
|
446
|
+
export declare const enterFullScreen: (element: HTMLElement) => Promise<void>;
|
|
449
447
|
|
|
450
448
|
/**
|
|
451
449
|
* HTML 实体转字符串
|
|
@@ -519,7 +517,7 @@ export declare const fileToBase64DataUri: (file: File | Blob | string) => Promis
|
|
|
519
517
|
* @example
|
|
520
518
|
* findAll('.item', container)
|
|
521
519
|
*/
|
|
522
|
-
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[];
|
|
523
521
|
|
|
524
522
|
/**
|
|
525
523
|
* 通过选择器查找单个节点
|
|
@@ -544,7 +542,7 @@ export declare const fixBaseUrl: (url: string, baseUrl: string) => string;
|
|
|
544
542
|
* @param {number} [defaultVal=0] - 转换失败时的默认值
|
|
545
543
|
* @returns {number} 返回转换后的浮点数,如果转换失败则返回默认值
|
|
546
544
|
*/
|
|
547
|
-
export declare const floatVal: (str:
|
|
545
|
+
export declare const floatVal: (str: unknown, defaultVal?: number) => number;
|
|
548
546
|
|
|
549
547
|
/**
|
|
550
548
|
* 格式化日期(以 PHP 方式格式化)
|
|
@@ -807,7 +805,7 @@ export declare const isLandscape: () => boolean;
|
|
|
807
805
|
* isNumberic('-123') // true
|
|
808
806
|
* isNumberic('210mm') // false
|
|
809
807
|
*/
|
|
810
|
-
export declare const isNumberic: (val:
|
|
808
|
+
export declare const isNumberic: (val: unknown) => boolean;
|
|
811
809
|
|
|
812
810
|
/**
|
|
813
811
|
* 检测目标是否为 Object(非数组的对象)
|
|
@@ -1333,7 +1331,7 @@ export declare const objectFromEntries: <T extends Record<string | number | symb
|
|
|
1333
1331
|
* get({ a: { b: { c: 1 } } }, 'a.b.c') // 1
|
|
1334
1332
|
* get({ a: { b: 1 } }, 'a.b.c', 0) // 0
|
|
1335
1333
|
*/
|
|
1336
|
-
export declare function objectGet<T = any>(obj:
|
|
1334
|
+
export declare function objectGet<T = any>(obj: object, path: string, defaultValue?: T): T;
|
|
1337
1335
|
|
|
1338
1336
|
/**
|
|
1339
1337
|
* 根据映射关系替换对象的键
|
|
@@ -1381,7 +1379,7 @@ export declare const objectSwitchKV: (obj: object) => any;
|
|
|
1381
1379
|
* @example
|
|
1382
1380
|
* objToQuery({name: 'John', age: 30}) // 'name=John&age=30'
|
|
1383
1381
|
*/
|
|
1384
|
-
export declare const objToQuery: (data:
|
|
1382
|
+
export declare const objToQuery: (data: any) => string;
|
|
1385
1383
|
|
|
1386
1384
|
/**
|
|
1387
1385
|
* 取消订阅事件,event 可以是字符串或 Symbol,handler 是事件处理函数
|
|
@@ -1619,7 +1617,7 @@ export declare const remove: (dom: HTMLElement | string) => Node | null;
|
|
|
1619
1617
|
* @example
|
|
1620
1618
|
* request('/api/data', null, {method: 'GET'})
|
|
1621
1619
|
*/
|
|
1622
|
-
export declare const request: (url: string, data
|
|
1620
|
+
export declare const request: (url: string, data?: any, requestOption?: RequestOption) => AbortablePromise<Response>;
|
|
1623
1621
|
|
|
1624
1622
|
/**
|
|
1625
1623
|
* 扩展 RequestInit,添加 timeout 和其他自定义属性,timeout 用于设置请求超时时间,其他自定义属性可以直接添加到 headers 中
|
|
@@ -1685,7 +1683,7 @@ export declare const show: (dom: HTMLElement | string) => void;
|
|
|
1685
1683
|
* @example
|
|
1686
1684
|
* srcToBase64('https://example.com/image.png').then(base64 => console.log(base64))
|
|
1687
1685
|
*/
|
|
1688
|
-
export declare const srcToBase64: (url: string, cache?: boolean) => Promise<
|
|
1686
|
+
export declare const srcToBase64: (url: string, cache?: boolean) => Promise<string>;
|
|
1689
1687
|
|
|
1690
1688
|
export declare const STAND_DPI = 96;
|
|
1691
1689
|
|
|
@@ -1790,7 +1788,7 @@ export declare const text2Html: (text: string) => string;
|
|
|
1790
1788
|
* @example
|
|
1791
1789
|
* const throttled = throttle(() => console.log('called'), 1000)
|
|
1792
1790
|
*/
|
|
1793
|
-
export declare const throttle: (fn:
|
|
1791
|
+
export declare const throttle: <T extends (...args: any[]) => any>(fn: T, intervalMiSec: number) => T;
|
|
1794
1792
|
|
|
1795
1793
|
/**
|
|
1796
1794
|
* 更有效果的节流函数
|
|
@@ -1802,7 +1800,7 @@ export declare const throttle: (fn: Function, intervalMiSec: number) => Function
|
|
|
1802
1800
|
* @example
|
|
1803
1801
|
* const throttled = throttleEffect(() => console.log('called'), 1000)
|
|
1804
1802
|
*/
|
|
1805
|
-
export declare const throttleEffect: (fn:
|
|
1803
|
+
export declare const throttleEffect: <T extends (...args: any[]) => any>(fn: T, intervalMiSec: number) => T;
|
|
1806
1804
|
|
|
1807
1805
|
/**
|
|
1808
1806
|
* 将时间戳转换为本地时间的日期时间字符串(YYYY-MM-DDTHH:mm),
|
|
@@ -1828,7 +1826,7 @@ export declare const toggleDisabled: (el: HTMLElement | string, disabledClass?:
|
|
|
1828
1826
|
* @example
|
|
1829
1827
|
* toggleFullScreen(document.body)
|
|
1830
1828
|
*/
|
|
1831
|
-
export declare const toggleFullScreen: (element:
|
|
1829
|
+
export declare const toggleFullScreen: (element: HTMLElement) => Promise<unknown>;
|
|
1832
1830
|
|
|
1833
1831
|
/**
|
|
1834
1832
|
* 触发HTML节点事件
|