@pawover/kit 0.2.0 → 0.2.2
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/package.json +15 -15
- package/packages/hooks/dist/alova.d.ts +7 -4
- package/packages/hooks/dist/alova.js +13 -27
- package/packages/hooks/dist/react.d.ts +2 -4
- package/packages/hooks/dist/react.js +52 -35
- package/packages/utils/dist/index.d.ts +432 -347
- package/packages/utils/dist/index.js +3 -4
- package/packages/utils/dist/math.d.ts +0 -1
- package/packages/utils/dist/math.js +1 -1
- package/packages/utils/dist/{stringUtil-CaY_wCS-.js → stringUtil-DbYpnL4l.js} +17 -0
- package/packages/utils/dist/vite.d.ts +0 -1
- package/packages/zod/dist/index.d.ts +0 -1
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"url": "https://github.com/pawover"
|
|
7
7
|
},
|
|
8
8
|
"description": "一个基于 TypeScript 的开发工具包",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.2",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=22.20.0"
|
|
@@ -51,34 +51,34 @@
|
|
|
51
51
|
"./zod/*": "./packages/zod/dist/*"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@commitlint/cli": "^21.1
|
|
55
|
-
"@commitlint/config-conventional": "^21.
|
|
56
|
-
"@eslint-react/eslint-plugin": "^5.
|
|
57
|
-
"@pawover/eslint-rules": "^0.2.
|
|
54
|
+
"@commitlint/cli": "^21.2.1",
|
|
55
|
+
"@commitlint/config-conventional": "^21.2.0",
|
|
56
|
+
"@eslint-react/eslint-plugin": "^5.14.6",
|
|
57
|
+
"@pawover/eslint-rules": "^0.2.2",
|
|
58
58
|
"@playwright/test": "^1.61.1",
|
|
59
|
-
"@stylistic/eslint-plugin": "^
|
|
59
|
+
"@stylistic/eslint-plugin": "^6.0.0-beta.5",
|
|
60
60
|
"@types/fs-extra": "^11.0.4",
|
|
61
|
-
"@types/node": "^26.
|
|
61
|
+
"@types/node": "^26.1.1",
|
|
62
62
|
"@vitejs/plugin-react": "^6.0.3",
|
|
63
|
-
"@vitest/browser-playwright": "^4.1.
|
|
63
|
+
"@vitest/browser-playwright": "^4.1.10",
|
|
64
64
|
"commitizen": "^4.3.2",
|
|
65
65
|
"cz-customizable": "^7.5.4",
|
|
66
|
-
"eslint": "^10.
|
|
66
|
+
"eslint": "^10.7.0",
|
|
67
67
|
"eslint-plugin-antfu": "^3.2.3",
|
|
68
68
|
"eslint-plugin-import-lite": "^0.6.0",
|
|
69
69
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
70
|
-
"fs-extra": "^11.3.
|
|
70
|
+
"fs-extra": "^11.3.6",
|
|
71
71
|
"husky": "^9.1.7",
|
|
72
72
|
"jsdom": "^29.1.1",
|
|
73
73
|
"lint-staged": "^17.0.8",
|
|
74
|
-
"prettier": "^3.9.
|
|
74
|
+
"prettier": "^3.9.5",
|
|
75
75
|
"rimraf": "^6.1.3",
|
|
76
76
|
"taze": "^19.14.1",
|
|
77
|
-
"tsdown": "^0.22.
|
|
78
|
-
"turbo": "^2.10.
|
|
77
|
+
"tsdown": "^0.22.7",
|
|
78
|
+
"turbo": "^2.10.4",
|
|
79
79
|
"typescript": "^6.0.3",
|
|
80
|
-
"typescript-eslint": "^8.
|
|
81
|
-
"vitest": "^4.1.
|
|
80
|
+
"typescript-eslint": "^8.63.0",
|
|
81
|
+
"vitest": "^4.1.10"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
84
|
"alova": "^3.3.0",
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { AlovaFrontMiddlewareContext, AlovaMethodHandler, CompleteHandler, ErrorHandler, PaginationHookConfig, RequestHookConfig, SuccessHandler, WatcherHookConfig } from "alova/client";
|
|
2
2
|
import { AlovaGenerics, Method } from "alova";
|
|
3
|
-
|
|
4
3
|
//#region src/alova/useAlovaPagination.d.ts
|
|
5
4
|
interface HookOptions$2<AG extends AlovaGenerics, L extends any[], Args extends any[]> extends PaginationHookConfig<AG, L> {
|
|
6
|
-
onBeforeRequest?:
|
|
5
|
+
onBeforeRequest?: BeforeRequestHandler<AG, any[]> | undefined;
|
|
7
6
|
onSuccess?: SuccessHandler<AG, Args> | undefined;
|
|
8
7
|
onError?: ErrorHandler<AG, Args> | undefined;
|
|
9
8
|
onComplete?: CompleteHandler<AG, Args> | undefined;
|
|
@@ -12,7 +11,7 @@ declare function useAlovaPagination<AG extends AlovaGenerics, L extends any[], A
|
|
|
12
11
|
//#endregion
|
|
13
12
|
//#region src/alova/useAlovaRequest.d.ts
|
|
14
13
|
interface HookOptions$1<AG extends AlovaGenerics, Args extends any[]> extends RequestHookConfig<AG, Args> {
|
|
15
|
-
onBeforeRequest?:
|
|
14
|
+
onBeforeRequest?: BeforeRequestHandler<AG, Args> | undefined;
|
|
16
15
|
onSuccess?: SuccessHandler<AG, Args> | undefined;
|
|
17
16
|
onError?: ErrorHandler<AG, Args> | undefined;
|
|
18
17
|
onComplete?: CompleteHandler<AG, Args> | undefined;
|
|
@@ -21,10 +20,14 @@ declare function useAlovaRequest<AG extends AlovaGenerics, Args extends any[] =
|
|
|
21
20
|
//#endregion
|
|
22
21
|
//#region src/alova/useAlovaWatcher.d.ts
|
|
23
22
|
interface HookOptions<AG extends AlovaGenerics, Args extends any[]> extends WatcherHookConfig<AG, Args> {
|
|
23
|
+
onBeforeRequest?: BeforeRequestHandler<AG, Args> | undefined;
|
|
24
24
|
onSuccess?: SuccessHandler<AG, Args> | undefined;
|
|
25
25
|
onError?: ErrorHandler<AG, Args> | undefined;
|
|
26
26
|
onComplete?: CompleteHandler<AG, Args> | undefined;
|
|
27
27
|
}
|
|
28
28
|
declare function useAlovaWatcher<AG extends AlovaGenerics, Args extends any[] = any[]>(methodHandler: Method<AG> | AlovaMethodHandler<AG, Args>, watchingStates: AG["StatesExport"]["Watched"][], hookOptions?: HookOptions<AG, Args>): import("alova/client").UseHookExposure<AG, Args, unknown>;
|
|
29
29
|
//#endregion
|
|
30
|
-
|
|
30
|
+
//#region src/alova/index.d.ts
|
|
31
|
+
type BeforeRequestHandler<AG extends AlovaGenerics, Args extends any[] = any[]> = (context: AlovaFrontMiddlewareContext<AG, Args>) => void;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { BeforeRequestHandler, useAlovaPagination, useAlovaRequest, useAlovaWatcher };
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { usePagination, useRequest, useWatcher } from "alova/client";
|
|
2
|
+
//#region src/alova/createBeforeRequestMiddleware.ts
|
|
3
|
+
function createBeforeRequestMiddleware(middleware, onBeforeRequest) {
|
|
4
|
+
return async (context, next) => {
|
|
5
|
+
onBeforeRequest?.(context);
|
|
6
|
+
if (middleware) return middleware(context, next);
|
|
7
|
+
return next();
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
2
11
|
//#region src/alova/useAlovaPagination.ts
|
|
3
12
|
function useAlovaPagination(methodHandler, hookOptions) {
|
|
4
13
|
const options = {
|
|
5
14
|
...hookOptions,
|
|
6
15
|
immediate: hookOptions?.immediate ?? true
|
|
7
16
|
};
|
|
8
|
-
|
|
9
|
-
let isMiddlewareExecuted = false;
|
|
10
|
-
if (options.onBeforeRequest) {
|
|
11
|
-
const middleware = options.middleware;
|
|
12
|
-
options.middleware = async (context, next) => {
|
|
13
|
-
!isBeforeExecuted && options.onBeforeRequest?.(context);
|
|
14
|
-
isBeforeExecuted = true;
|
|
15
|
-
if (middleware && !isMiddlewareExecuted) {
|
|
16
|
-
isMiddlewareExecuted = true;
|
|
17
|
-
await middleware?.(context, next);
|
|
18
|
-
} else await next();
|
|
19
|
-
};
|
|
20
|
-
}
|
|
17
|
+
if (options.onBeforeRequest) options.middleware = createBeforeRequestMiddleware(options.middleware, options.onBeforeRequest);
|
|
21
18
|
const exposure = usePagination(methodHandler, options);
|
|
22
19
|
if (options.onSuccess) exposure.onSuccess(options.onSuccess);
|
|
23
20
|
if (options.onError) exposure.onError(options.onError);
|
|
@@ -31,19 +28,7 @@ function useAlovaRequest(methodHandler, hookOptions) {
|
|
|
31
28
|
...hookOptions,
|
|
32
29
|
immediate: hookOptions?.immediate ?? true
|
|
33
30
|
};
|
|
34
|
-
|
|
35
|
-
let isMiddlewareExecuted = false;
|
|
36
|
-
if (options.onBeforeRequest) {
|
|
37
|
-
const middleware = options.middleware;
|
|
38
|
-
options.middleware = async (context, next) => {
|
|
39
|
-
!isBeforeExecuted && options.onBeforeRequest?.(context);
|
|
40
|
-
isBeforeExecuted = true;
|
|
41
|
-
if (middleware && !isMiddlewareExecuted) {
|
|
42
|
-
isMiddlewareExecuted = true;
|
|
43
|
-
await middleware?.(context, next);
|
|
44
|
-
} else await next();
|
|
45
|
-
};
|
|
46
|
-
}
|
|
31
|
+
if (options.onBeforeRequest) options.middleware = createBeforeRequestMiddleware(options.middleware, options.onBeforeRequest);
|
|
47
32
|
const exposure = useRequest(methodHandler, options);
|
|
48
33
|
if (options.onSuccess) exposure.onSuccess(options.onSuccess);
|
|
49
34
|
if (options.onError) exposure.onError(options.onError);
|
|
@@ -53,7 +38,8 @@ function useAlovaRequest(methodHandler, hookOptions) {
|
|
|
53
38
|
//#endregion
|
|
54
39
|
//#region src/alova/useAlovaWatcher.ts
|
|
55
40
|
function useAlovaWatcher(methodHandler, watchingStates, hookOptions = {}) {
|
|
56
|
-
const options = hookOptions
|
|
41
|
+
const options = { ...hookOptions };
|
|
42
|
+
if (options.onBeforeRequest) options.middleware = createBeforeRequestMiddleware(options.middleware, options.onBeforeRequest);
|
|
57
43
|
const exposure = useWatcher(methodHandler, watchingStates, options);
|
|
58
44
|
if (options.onSuccess) exposure.onSuccess(options.onSuccess);
|
|
59
45
|
if (options.onError) exposure.onError(options.onError);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EffectCallback, RefObject } from "react";
|
|
2
|
-
|
|
3
2
|
//#region src/react/useLatest.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* 返回当前最新值的 Hook
|
|
@@ -8,12 +7,11 @@ import { EffectCallback, RefObject } from "react";
|
|
|
8
7
|
*/
|
|
9
8
|
declare function useLatest<T>(value: T): RefObject<T>;
|
|
10
9
|
//#endregion
|
|
11
|
-
//#region ../../node_modules/.pnpm/@pawover+types@0.0.
|
|
10
|
+
//#region ../../node_modules/.pnpm/@pawover+types@0.0.4_@types+react@19.2.15_typescript@6.0.3/node_modules/@pawover/types/dist/index.d.ts
|
|
12
11
|
/** 描述函数类型 */
|
|
13
12
|
type AnyFunction<P extends any[] = any[], R = any> = (...arg: P) => R;
|
|
14
13
|
/** 描述异步函数类型 */
|
|
15
14
|
type AnyAsyncFunction<P extends any[] = any[], R = any> = (...args: P) => Promise<R>;
|
|
16
|
-
/** 描述生成器函数类型 */
|
|
17
15
|
//#endregion
|
|
18
16
|
//#region src/react/useMount.d.ts
|
|
19
17
|
/**
|
|
@@ -36,7 +34,7 @@ type AnyAsyncFunction<P extends any[] = any[], R = any> = (...args: P) => Promis
|
|
|
36
34
|
*/
|
|
37
35
|
declare function useMount(effect: EffectCallback | AnyAsyncFunction): void;
|
|
38
36
|
//#endregion
|
|
39
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
37
|
+
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/tuple-to-union.d.ts
|
|
40
38
|
/**
|
|
41
39
|
Convert a tuple/array into a union type of its elements.
|
|
42
40
|
|
|
@@ -11,7 +11,7 @@ function useLatest(value) {
|
|
|
11
11
|
return ref;
|
|
12
12
|
}
|
|
13
13
|
//#endregion
|
|
14
|
-
//#region ../utils/dist/stringUtil-
|
|
14
|
+
//#region ../utils/dist/stringUtil-DbYpnL4l.js
|
|
15
15
|
/**
|
|
16
16
|
* 类型工具类
|
|
17
17
|
*/
|
|
@@ -368,6 +368,23 @@ var TypeUtil = class {
|
|
|
368
368
|
return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;
|
|
369
369
|
}
|
|
370
370
|
/**
|
|
371
|
+
* 判断是否为广义对象类型
|
|
372
|
+
*
|
|
373
|
+
* @param value 待检查值
|
|
374
|
+
* @returns 是否为对象
|
|
375
|
+
* @example
|
|
376
|
+
* ```ts
|
|
377
|
+
* TypeUtil.isObject({}); // true
|
|
378
|
+
* TypeUtil.isObject([]); // true
|
|
379
|
+
* TypeUtil.isObject(new Date()); // true
|
|
380
|
+
* TypeUtil.isObject(null); // false
|
|
381
|
+
* TypeUtil.isObject("string"); // false
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
static isObject(value) {
|
|
385
|
+
return typeof value === "object" && value !== null;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
371
388
|
* 判断一个对象是否为有效的枚举
|
|
372
389
|
* - 枚举成员不能为空
|
|
373
390
|
* - 枚举成员的键不能具有数值名
|
|
@@ -1649,6 +1666,23 @@ function useMount(effect) {
|
|
|
1649
1666
|
}, [effectRef]);
|
|
1650
1667
|
}
|
|
1651
1668
|
//#endregion
|
|
1669
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/_internal/globalThis.mjs
|
|
1670
|
+
const globalThis_ = typeof globalThis === "object" && globalThis || typeof window === "object" && window || typeof self === "object" && self || typeof global === "object" && global || (function() {
|
|
1671
|
+
return this;
|
|
1672
|
+
})();
|
|
1673
|
+
//#endregion
|
|
1674
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/function/noop.mjs
|
|
1675
|
+
/**
|
|
1676
|
+
* A no-operation function that does nothing.
|
|
1677
|
+
* This can be used as a placeholder or default function.
|
|
1678
|
+
*
|
|
1679
|
+
* @example
|
|
1680
|
+
* noop(); // Does nothing
|
|
1681
|
+
*
|
|
1682
|
+
* @returns This function does not return anything.
|
|
1683
|
+
*/
|
|
1684
|
+
function noop() {}
|
|
1685
|
+
//#endregion
|
|
1652
1686
|
//#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
|
|
1653
1687
|
/**
|
|
1654
1688
|
* Checks whether a value is a JavaScript primitive.
|
|
@@ -1753,17 +1787,28 @@ function clone(obj) {
|
|
|
1753
1787
|
return obj;
|
|
1754
1788
|
}
|
|
1755
1789
|
//#endregion
|
|
1756
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/
|
|
1790
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isBuffer.mjs
|
|
1757
1791
|
/**
|
|
1758
|
-
*
|
|
1759
|
-
*
|
|
1792
|
+
* Checks if the given value is a Buffer instance.
|
|
1793
|
+
*
|
|
1794
|
+
* This function tests whether the provided value is an instance of Buffer.
|
|
1795
|
+
* It returns `true` if the value is a Buffer, and `false` otherwise.
|
|
1796
|
+
*
|
|
1797
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Buffer`.
|
|
1798
|
+
*
|
|
1799
|
+
* @param x - The value to check if it is a Buffer.
|
|
1800
|
+
* @returns Returns `true` if `x` is a Buffer, else `false`.
|
|
1760
1801
|
*
|
|
1761
1802
|
* @example
|
|
1762
|
-
*
|
|
1803
|
+
* const buffer = Buffer.from("test");
|
|
1804
|
+
* console.log(isBuffer(buffer)); // true
|
|
1763
1805
|
*
|
|
1764
|
-
*
|
|
1806
|
+
* const notBuffer = "not a buffer";
|
|
1807
|
+
* console.log(isBuffer(notBuffer)); // false
|
|
1765
1808
|
*/
|
|
1766
|
-
function
|
|
1809
|
+
function isBuffer(x) {
|
|
1810
|
+
return typeof globalThis_.Buffer !== "undefined" && globalThis_.Buffer.isBuffer(x);
|
|
1811
|
+
}
|
|
1767
1812
|
//#endregion
|
|
1768
1813
|
//#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/compat/_internal/getSymbols.mjs
|
|
1769
1814
|
function getSymbols(object) {
|
|
@@ -1810,34 +1855,6 @@ const bigInt64ArrayTag = "[object BigInt64Array]";
|
|
|
1810
1855
|
const float32ArrayTag = "[object Float32Array]";
|
|
1811
1856
|
const float64ArrayTag = "[object Float64Array]";
|
|
1812
1857
|
//#endregion
|
|
1813
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/_internal/globalThis.mjs
|
|
1814
|
-
const globalThis_ = typeof globalThis === "object" && globalThis || typeof window === "object" && window || typeof self === "object" && self || typeof global === "object" && global || (function() {
|
|
1815
|
-
return this;
|
|
1816
|
-
})();
|
|
1817
|
-
//#endregion
|
|
1818
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isBuffer.mjs
|
|
1819
|
-
/**
|
|
1820
|
-
* Checks if the given value is a Buffer instance.
|
|
1821
|
-
*
|
|
1822
|
-
* This function tests whether the provided value is an instance of Buffer.
|
|
1823
|
-
* It returns `true` if the value is a Buffer, and `false` otherwise.
|
|
1824
|
-
*
|
|
1825
|
-
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Buffer`.
|
|
1826
|
-
*
|
|
1827
|
-
* @param x - The value to check if it is a Buffer.
|
|
1828
|
-
* @returns Returns `true` if `x` is a Buffer, else `false`.
|
|
1829
|
-
*
|
|
1830
|
-
* @example
|
|
1831
|
-
* const buffer = Buffer.from("test");
|
|
1832
|
-
* console.log(isBuffer(buffer)); // true
|
|
1833
|
-
*
|
|
1834
|
-
* const notBuffer = "not a buffer";
|
|
1835
|
-
* console.log(isBuffer(notBuffer)); // false
|
|
1836
|
-
*/
|
|
1837
|
-
function isBuffer(x) {
|
|
1838
|
-
return typeof globalThis_.Buffer !== "undefined" && globalThis_.Buffer.isBuffer(x);
|
|
1839
|
-
}
|
|
1840
|
-
//#endregion
|
|
1841
1858
|
//#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
|
|
1842
1859
|
/**
|
|
1843
1860
|
* Checks if a given value is a plain object.
|