minutool 1.0.1 → 1.0.3
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/README.md +6 -6
- package/dist/index.d.ts +7 -9
- package/dist/minutool.js +341 -316
- package/dist/minutool.js.map +1 -1
- package/dist/minutool.umd.cjs +4 -4
- package/dist/minutool.umd.cjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# minutool
|
|
2
2
|
|
|
3
3
|
A lightweight collection of utility functions for JavaScript/TypeScript projects.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install
|
|
8
|
+
npm install minutool
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
or
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
yarn add
|
|
14
|
+
yarn add minutool
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
|
-
import { formatDate, capitalize, deepClone } from '
|
|
20
|
+
import { formatDate, capitalize, deepClone } from 'minutool'
|
|
21
21
|
|
|
22
22
|
// Time utilities
|
|
23
23
|
const now = new Date()
|
|
@@ -39,7 +39,7 @@ const cloned = deepClone(obj)
|
|
|
39
39
|
- `YEAR_NOW` - Current year
|
|
40
40
|
- `MONTH_NOW` - Current month (1-12)
|
|
41
41
|
- `DATE_NOW` - Current day of month
|
|
42
|
-
- `ONE_MINUTE` - Milliseconds in one
|
|
42
|
+
- `ONE_MINUTE` - Milliseconds in one minutoole
|
|
43
43
|
- `ONE_HOUR` - Milliseconds in one hour
|
|
44
44
|
- `ONE_DAY` - Milliseconds in one day
|
|
45
45
|
- `ONE_WEEK` - Milliseconds in one week
|
|
@@ -62,7 +62,7 @@ const cloned = deepClone(obj)
|
|
|
62
62
|
**Functions:**
|
|
63
63
|
- `formatDate(format: string, date?: Date | number | string | null): string` - Format date
|
|
64
64
|
- `countDown(timeout: number, tickFunc?: Function, onFinish?: Function)` - Countdown timer
|
|
65
|
-
- `msToHMS(ms: number)` - Convert milliseconds to hours/
|
|
65
|
+
- `msToHMS(ms: number)` - Convert milliseconds to hours/minutooles/seconds
|
|
66
66
|
|
|
67
67
|
### String Utilities
|
|
68
68
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 拓展原生 Fetch API 实现可中止的请求,支持超时设置
|
|
3
3
|
* @param {string} url - 请求 URL
|
|
4
|
-
* @param {
|
|
4
|
+
* @param {RequestInit} [fetchOption={}] - fetch请求选项,包括 method、headers、body 等
|
|
5
|
+
* @param {number} [timeout=0] - 超时时间,单位毫秒,0 表示不设置超时
|
|
5
6
|
* @returns {AbortablePromise<any>} 返回可中止的 Promise 对象
|
|
6
7
|
* @example
|
|
7
8
|
* const req = abortableFetch('/api/data');
|
|
8
|
-
* req.abort(); // 中止请求
|
|
9
|
+
* req.abort('cancled'); // 中止请求
|
|
9
10
|
*/
|
|
10
|
-
export declare const abortableFetch: (url: string,
|
|
11
|
+
export declare const abortableFetch: (url: string, fetchOption?: RequestInit, timeout?: number) => AbortablePromise<any>;
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* 可中止的 Fetch 请求
|
|
@@ -1394,12 +1395,9 @@ export declare const remove: (dom: HTMLElement | string) => Node | null;
|
|
|
1394
1395
|
*/
|
|
1395
1396
|
export declare const request: (url: string, data: (BodyInit | null) | undefined, option: RequestOption) => AbortablePromise<Response>;
|
|
1396
1397
|
|
|
1397
|
-
declare interface RequestOption {
|
|
1398
|
-
method?: string;
|
|
1399
|
-
headers?: Record<string, string>;
|
|
1400
|
-
ContentType?: string;
|
|
1401
|
-
Accept?: string;
|
|
1398
|
+
declare interface RequestOption extends RequestInit {
|
|
1402
1399
|
timeout?: number;
|
|
1400
|
+
[key: string]: any;
|
|
1403
1401
|
}
|
|
1404
1402
|
|
|
1405
1403
|
/**
|