@pawover/kit 0.4.2 → 0.6.0
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 +166 -29
- package/packages/eslint-rules/dist/core.antfu.cjs +78 -0
- package/packages/eslint-rules/dist/core.antfu.d.cts +1 -0
- package/packages/eslint-rules/dist/core.antfu.d.ts +74 -0
- package/packages/eslint-rules/dist/core.antfu.js +79 -0
- package/packages/eslint-rules/dist/core.imports.cjs +59 -0
- package/packages/eslint-rules/dist/core.imports.d.cts +1 -0
- package/packages/eslint-rules/dist/core.imports.d.ts +61 -0
- package/packages/eslint-rules/dist/core.imports.js +59 -0
- package/packages/eslint-rules/dist/core.importsSort.cjs +7 -0
- package/packages/eslint-rules/dist/core.importsSort.d.cts +1 -0
- package/packages/eslint-rules/dist/core.importsSort.d.ts +7 -0
- package/packages/eslint-rules/dist/core.importsSort.js +7 -0
- package/packages/eslint-rules/dist/core.javascript.cjs +1208 -0
- package/packages/eslint-rules/dist/core.javascript.d.cts +1 -0
- package/packages/eslint-rules/dist/core.javascript.d.ts +1216 -0
- package/packages/eslint-rules/dist/core.javascript.js +1208 -0
- package/packages/eslint-rules/dist/core.react.cjs +551 -0
- package/packages/eslint-rules/dist/core.react.d.cts +1 -0
- package/packages/eslint-rules/dist/core.react.d.ts +551 -0
- package/packages/eslint-rules/dist/core.react.js +551 -0
- package/packages/eslint-rules/dist/core.reactHooks.cjs +107 -0
- package/packages/eslint-rules/dist/core.reactHooks.d.cts +1 -0
- package/packages/eslint-rules/dist/core.reactHooks.d.ts +107 -0
- package/packages/eslint-rules/dist/core.reactHooks.js +107 -0
- package/packages/eslint-rules/dist/core.stylistic.cjs +608 -0
- package/packages/eslint-rules/dist/core.stylistic.d.cts +1 -0
- package/packages/eslint-rules/dist/core.stylistic.d.ts +595 -0
- package/packages/eslint-rules/dist/core.stylistic.js +608 -0
- package/packages/eslint-rules/dist/core.typescript.cjs +905 -0
- package/packages/eslint-rules/dist/core.typescript.d.cts +1 -0
- package/packages/eslint-rules/dist/core.typescript.d.ts +917 -0
- package/packages/eslint-rules/dist/core.typescript.js +906 -0
- package/packages/eslint-rules/dist/core.vue.cjs +312 -0
- package/packages/eslint-rules/dist/core.vue.d.cts +1 -0
- package/packages/eslint-rules/dist/core.vue.d.ts +293 -0
- package/packages/eslint-rules/dist/core.vue.js +313 -0
- package/packages/eslint-rules/dist/index.cjs +126 -0
- package/packages/eslint-rules/dist/index.d.cts +1 -0
- package/packages/eslint-rules/dist/index.d.ts +113 -0
- package/packages/eslint-rules/dist/index.js +126 -0
- package/packages/eslint-rules/dist/preset-Bk6lxNP0.cjs +107 -0
- package/packages/eslint-rules/dist/preset-CQJST7pW.js +102 -0
- package/packages/hooks/dist/alova.cjs +53 -0
- package/packages/hooks/dist/alova.d.cts +1 -0
- package/packages/hooks/dist/index.cjs +0 -0
- package/packages/hooks/dist/index.d.cts +1 -0
- package/packages/hooks/dist/react.cjs +169 -0
- package/packages/hooks/dist/react.d.cts +1 -0
- package/packages/hooks/dist/react.d.ts +2 -60
- package/packages/hooks/dist/react.js +2 -2441
- package/packages/types/dist/index.cjs +0 -0
- package/packages/types/dist/index.d.cts +1 -0
- package/packages/types/dist/index.d.ts +271 -0
- package/packages/types/dist/index.js +0 -0
- package/packages/types/dist/react.cjs +0 -0
- package/packages/types/dist/react.d.cts +1 -0
- package/packages/types/dist/react.d.ts +64 -0
- package/packages/types/dist/react.js +0 -0
- package/packages/utils/dist/index.cjs +2300 -0
- package/packages/utils/dist/index.d.cts +1 -0
- package/packages/utils/dist/index.d.ts +156 -2721
- package/packages/utils/dist/index.js +122 -35
- package/packages/utils/dist/math-BznvO4qI.cjs +1029 -0
- package/packages/utils/dist/{math-B5PyWuKn.js → math-DRbCtLQH.js} +31 -27
- package/packages/utils/dist/math.cjs +3 -0
- package/packages/utils/dist/math.d.cts +1 -0
- package/packages/utils/dist/math.d.ts +3 -0
- package/packages/utils/dist/math.js +1 -1
- package/packages/utils/dist/vite.cjs +44 -0
- package/packages/utils/dist/vite.d.cts +1 -0
- package/packages/utils/dist/vite.js +12 -8
- package/packages/zod/dist/index.cjs +91 -0
- package/packages/zod/dist/index.d.cts +1 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//#region src/preset.ts
|
|
2
|
+
/**
|
|
3
|
+
* 预设配置
|
|
4
|
+
*
|
|
5
|
+
* 供各规则组共享的基础预设:缩进大小与 TypeScript 类成员排序规则。
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import preset from "@pawover/kit-eslint-rules/src/preset";
|
|
10
|
+
*
|
|
11
|
+
* console.log(preset.indent); // 2
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
var preset_default = {
|
|
15
|
+
/** 缩进大小 */
|
|
16
|
+
indent: 2,
|
|
17
|
+
/** TypeScript 类成员排序 */
|
|
18
|
+
tsMemberOrder: [
|
|
19
|
+
"signature",
|
|
20
|
+
"call-signature",
|
|
21
|
+
"static-initialization",
|
|
22
|
+
"#private-static-field",
|
|
23
|
+
"private-static-field",
|
|
24
|
+
"protected-static-field",
|
|
25
|
+
"public-static-field",
|
|
26
|
+
"static-field",
|
|
27
|
+
"#private-instance-field",
|
|
28
|
+
"private-instance-field",
|
|
29
|
+
"protected-instance-field",
|
|
30
|
+
"public-instance-field",
|
|
31
|
+
"instance-field",
|
|
32
|
+
"#private-field",
|
|
33
|
+
"private-field",
|
|
34
|
+
"protected-field",
|
|
35
|
+
"public-field",
|
|
36
|
+
"field",
|
|
37
|
+
"private-constructor",
|
|
38
|
+
"protected-constructor",
|
|
39
|
+
"public-constructor",
|
|
40
|
+
"#private-static-get",
|
|
41
|
+
"#private-static-set",
|
|
42
|
+
"private-static-get",
|
|
43
|
+
"private-static-set",
|
|
44
|
+
"protected-static-get",
|
|
45
|
+
"protected-static-set",
|
|
46
|
+
"public-static-get",
|
|
47
|
+
"public-static-set",
|
|
48
|
+
"static-get",
|
|
49
|
+
"static-set",
|
|
50
|
+
"protected-abstract-get",
|
|
51
|
+
"protected-abstract-set",
|
|
52
|
+
"public-abstract-get",
|
|
53
|
+
"public-abstract-set",
|
|
54
|
+
"abstract-get",
|
|
55
|
+
"abstract-set",
|
|
56
|
+
"#private-instance-get",
|
|
57
|
+
"#private-instance-set",
|
|
58
|
+
"private-instance-get",
|
|
59
|
+
"private-instance-set",
|
|
60
|
+
"protected-instance-get",
|
|
61
|
+
"protected-instance-set",
|
|
62
|
+
"public-instance-get",
|
|
63
|
+
"public-instance-set",
|
|
64
|
+
"instance-get",
|
|
65
|
+
"instance-set",
|
|
66
|
+
"private-decorated-get",
|
|
67
|
+
"private-decorated-set",
|
|
68
|
+
"protected-decorated-get",
|
|
69
|
+
"protected-decorated-set",
|
|
70
|
+
"public-decorated-get",
|
|
71
|
+
"public-decorated-set",
|
|
72
|
+
"decorated-get",
|
|
73
|
+
"decorated-set",
|
|
74
|
+
"#private-get",
|
|
75
|
+
"#private-set",
|
|
76
|
+
"private-get",
|
|
77
|
+
"private-set",
|
|
78
|
+
"protected-get",
|
|
79
|
+
"protected-set",
|
|
80
|
+
"public-get",
|
|
81
|
+
"public-set",
|
|
82
|
+
"get",
|
|
83
|
+
"set",
|
|
84
|
+
"#private-static-method",
|
|
85
|
+
"private-static-method",
|
|
86
|
+
"protected-static-method",
|
|
87
|
+
"public-static-method",
|
|
88
|
+
"static-method",
|
|
89
|
+
"#private-instance-method",
|
|
90
|
+
"private-instance-method",
|
|
91
|
+
"protected-instance-method",
|
|
92
|
+
"public-instance-method",
|
|
93
|
+
"instance-method",
|
|
94
|
+
"private-method",
|
|
95
|
+
"protected-method",
|
|
96
|
+
"public-method",
|
|
97
|
+
"#private-method",
|
|
98
|
+
"method"
|
|
99
|
+
]
|
|
100
|
+
};
|
|
101
|
+
//#endregion
|
|
102
|
+
export { preset_default as t };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let alova_client = require("alova/client");
|
|
3
|
+
//#region src/alova/createBeforeRequestMiddleware.ts
|
|
4
|
+
function createBeforeRequestMiddleware(middleware, onBeforeRequest) {
|
|
5
|
+
return async (context, next) => {
|
|
6
|
+
onBeforeRequest?.(context);
|
|
7
|
+
if (middleware) return middleware(context, next);
|
|
8
|
+
return next();
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/alova/useAlovaPagination.ts
|
|
13
|
+
function useAlovaPagination(methodHandler, hookOptions) {
|
|
14
|
+
const options = {
|
|
15
|
+
...hookOptions,
|
|
16
|
+
immediate: hookOptions?.immediate ?? true
|
|
17
|
+
};
|
|
18
|
+
if (options.onBeforeRequest) options.middleware = createBeforeRequestMiddleware(options.middleware, options.onBeforeRequest);
|
|
19
|
+
const exposure = (0, alova_client.usePagination)(methodHandler, options);
|
|
20
|
+
if (options.onSuccess) exposure.onSuccess(options.onSuccess);
|
|
21
|
+
if (options.onError) exposure.onError(options.onError);
|
|
22
|
+
if (options.onComplete) exposure.onComplete(options.onComplete);
|
|
23
|
+
return exposure;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/alova/useAlovaRequest.ts
|
|
27
|
+
function useAlovaRequest(methodHandler, hookOptions) {
|
|
28
|
+
const options = {
|
|
29
|
+
...hookOptions,
|
|
30
|
+
immediate: hookOptions?.immediate ?? true
|
|
31
|
+
};
|
|
32
|
+
if (options.onBeforeRequest) options.middleware = createBeforeRequestMiddleware(options.middleware, options.onBeforeRequest);
|
|
33
|
+
const exposure = (0, alova_client.useRequest)(methodHandler, options);
|
|
34
|
+
if (options.onSuccess) exposure.onSuccess(options.onSuccess);
|
|
35
|
+
if (options.onError) exposure.onError(options.onError);
|
|
36
|
+
if (options.onComplete) exposure.onComplete(options.onComplete);
|
|
37
|
+
return exposure;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/alova/useAlovaWatcher.ts
|
|
41
|
+
function useAlovaWatcher(methodHandler, watchingStates, hookOptions = {}) {
|
|
42
|
+
const options = { ...hookOptions };
|
|
43
|
+
if (options.onBeforeRequest) options.middleware = createBeforeRequestMiddleware(options.middleware, options.onBeforeRequest);
|
|
44
|
+
const exposure = (0, alova_client.useWatcher)(methodHandler, watchingStates, options);
|
|
45
|
+
if (options.onSuccess) exposure.onSuccess(options.onSuccess);
|
|
46
|
+
if (options.onError) exposure.onError(options.onError);
|
|
47
|
+
if (options.onComplete) exposure.onComplete(options.onComplete);
|
|
48
|
+
return exposure;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
exports.useAlovaPagination = useAlovaPagination;
|
|
52
|
+
exports.useAlovaRequest = useAlovaRequest;
|
|
53
|
+
exports.useAlovaWatcher = useAlovaWatcher;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './alova.d.ts'
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './index.d.ts'
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let react = require("react");
|
|
3
|
+
let _pawover_kit_utils = require("@pawover/kit-utils");
|
|
4
|
+
let es_toolkit = require("es-toolkit");
|
|
5
|
+
//#region src/react/useLatest.ts
|
|
6
|
+
/**
|
|
7
|
+
* 返回当前最新值的 Hook
|
|
8
|
+
*
|
|
9
|
+
* @param value
|
|
10
|
+
*/
|
|
11
|
+
function useLatest(value) {
|
|
12
|
+
const ref = (0, react.useRef)(value);
|
|
13
|
+
ref.current = value;
|
|
14
|
+
return ref;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/react/useMount.ts
|
|
18
|
+
/**
|
|
19
|
+
* 在组件初始化时执行的 Hook
|
|
20
|
+
* - 即使在严格模式(React StrictMode)也只执行一次
|
|
21
|
+
* - 自动使用最新版 effect 函数
|
|
22
|
+
*
|
|
23
|
+
* @param effect 副作用函数(必须为同步函数;若为异步函数,清理逻辑需自行处理)
|
|
24
|
+
* @example
|
|
25
|
+
* useMount(() => {
|
|
26
|
+
* console.log('组件挂载');
|
|
27
|
+
* return () => console.log('组件卸载');
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* useMount(async () => {
|
|
31
|
+
* const data = await fetchData();
|
|
32
|
+
* // 清理逻辑需通过 ref/AbortController 自行管理
|
|
33
|
+
* // ❌ 不要 return cleanupFn(async 函数返回 Promise,无法作为清理函数)
|
|
34
|
+
* });
|
|
35
|
+
*/
|
|
36
|
+
function useMount(effect) {
|
|
37
|
+
const isMountedRef = (0, react.useRef)(false);
|
|
38
|
+
const effectRef = useLatest(effect);
|
|
39
|
+
(0, react.useEffect)(() => {
|
|
40
|
+
if (!_pawover_kit_utils.TypeUtil.isFunction(effectRef.current)) {
|
|
41
|
+
console.error(`hook [useMount] Expected parameter to be a function, but got ${typeof effectRef.current}. This effect will not execute.`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (isMountedRef.current) return;
|
|
45
|
+
isMountedRef.current = true;
|
|
46
|
+
const cleanup = effectRef.current?.();
|
|
47
|
+
return _pawover_kit_utils.TypeUtil.isFunction(cleanup) && !_pawover_kit_utils.TypeUtil.isPromise(cleanup) ? cleanup : void 0;
|
|
48
|
+
}, [effectRef]);
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/react/useResponsive.ts
|
|
52
|
+
/** 屏幕响应断点 token 配置 */
|
|
53
|
+
const BREAK_POINT_TOKEN = {
|
|
54
|
+
XS: 480,
|
|
55
|
+
XSMax: 575,
|
|
56
|
+
XSMin: 480,
|
|
57
|
+
SM: 576,
|
|
58
|
+
SMMax: 767,
|
|
59
|
+
SMMin: 576,
|
|
60
|
+
MD: 768,
|
|
61
|
+
MDMax: 991,
|
|
62
|
+
MDMin: 768,
|
|
63
|
+
LG: 992,
|
|
64
|
+
LGMax: 1199,
|
|
65
|
+
LGMin: 992,
|
|
66
|
+
XL: 1200,
|
|
67
|
+
XLMax: 1599,
|
|
68
|
+
XLMin: 1200,
|
|
69
|
+
XXL: 1600,
|
|
70
|
+
XXLMax: 1919,
|
|
71
|
+
XXLMin: 1600,
|
|
72
|
+
XXXL: 1920,
|
|
73
|
+
XXXLMin: 1920
|
|
74
|
+
};
|
|
75
|
+
const SUBSCRIBER_SET = /* @__PURE__ */ new Set();
|
|
76
|
+
const BREAK_POINTS = [
|
|
77
|
+
"xxxl",
|
|
78
|
+
"xxl",
|
|
79
|
+
"xl",
|
|
80
|
+
"lg",
|
|
81
|
+
"md",
|
|
82
|
+
"sm",
|
|
83
|
+
"xs"
|
|
84
|
+
];
|
|
85
|
+
const DEFAULT_VALUES = Object.freeze(_pawover_kit_utils.ArrayUtil.zipToObject(BREAK_POINTS, false));
|
|
86
|
+
let responsiveValues = { ...DEFAULT_VALUES };
|
|
87
|
+
let responsiveTokens = (0, es_toolkit.clone)(BREAK_POINT_TOKEN);
|
|
88
|
+
function useResponsive(options) {
|
|
89
|
+
const { breakPointTokens = {} } = options || {};
|
|
90
|
+
const tokens = (0, react.useMemo)(() => Object.assign(BREAK_POINT_TOKEN, breakPointTokens), [breakPointTokens]);
|
|
91
|
+
const [responsive, setResponsive] = (0, react.useState)(() => calculateResponsive(tokens));
|
|
92
|
+
const current = _pawover_kit_utils.ObjectUtil.keys(DEFAULT_VALUES).find((key) => responsive[key] === true) || "xs";
|
|
93
|
+
(0, react.useLayoutEffect)(() => {
|
|
94
|
+
responsiveTokens = tokens;
|
|
95
|
+
window.addEventListener("resize", resizeListener);
|
|
96
|
+
const subscriber = () => {
|
|
97
|
+
setResponsive(responsiveValues);
|
|
98
|
+
};
|
|
99
|
+
SUBSCRIBER_SET.add(subscriber);
|
|
100
|
+
return () => {
|
|
101
|
+
SUBSCRIBER_SET.delete(subscriber);
|
|
102
|
+
if (!SUBSCRIBER_SET.size) window.removeEventListener("resize", resizeListener);
|
|
103
|
+
};
|
|
104
|
+
}, [tokens]);
|
|
105
|
+
return {
|
|
106
|
+
responsive,
|
|
107
|
+
current,
|
|
108
|
+
breakPointTokens: tokens
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function resizeListener() {
|
|
112
|
+
const newValues = calculateResponsive(responsiveTokens);
|
|
113
|
+
if (!(0, es_toolkit.isEqual)(responsiveValues, newValues)) {
|
|
114
|
+
responsiveValues = newValues;
|
|
115
|
+
for (const subscriber of SUBSCRIBER_SET) subscriber();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function calculateResponsive(tokens) {
|
|
119
|
+
const config = _pawover_kit_utils.ArrayUtil.zipToObject(BREAK_POINTS, BREAK_POINTS.map((t) => tokens[_pawover_kit_utils.StringUtil.toUpperCase(t)]));
|
|
120
|
+
return _pawover_kit_utils.ObjectUtil.entriesMap(DEFAULT_VALUES, (key) => [key, window.innerWidth >= config[key]]);
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/react/useUnmount.ts
|
|
124
|
+
/**
|
|
125
|
+
* 在组件卸载时执行的 Hook
|
|
126
|
+
*
|
|
127
|
+
* @param effect 副作用函数
|
|
128
|
+
*/
|
|
129
|
+
function useUnmount(effect) {
|
|
130
|
+
const effectRef = useLatest(effect);
|
|
131
|
+
(0, react.useEffect)(() => () => {
|
|
132
|
+
if (!_pawover_kit_utils.TypeUtil.isFunction(effectRef.current)) {
|
|
133
|
+
console.error(`hook [useUnmount] Expected parameter to be a function, but got ${typeof effectRef.current}. This effect will not execute.`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
effectRef.current?.();
|
|
137
|
+
}, [effectRef]);
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/react/useTitle.ts
|
|
141
|
+
/**
|
|
142
|
+
* 设置页面标题
|
|
143
|
+
* - 轻量级,适用于无路由库时设置页面标题
|
|
144
|
+
* - 多个 `useTitle` 实例会互相干扰,需在顶层组件使用
|
|
145
|
+
* - 无法处理 `document.title` 固有的竞态问题
|
|
146
|
+
*
|
|
147
|
+
* @param title 页面标题
|
|
148
|
+
* @param options 配置选项
|
|
149
|
+
*/
|
|
150
|
+
function useTitle(title, options) {
|
|
151
|
+
const titleRef = (0, react.useRef)(_pawover_kit_utils.EnvUtil.isBrowser() ? document.title : "");
|
|
152
|
+
(0, react.useEffect)(() => {
|
|
153
|
+
if (!_pawover_kit_utils.TypeUtil.isString(title)) {
|
|
154
|
+
console.error(`hook [useTitle] Expected parameter to be a string, but got ${typeof title}. This effect will not execute.`);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (_pawover_kit_utils.EnvUtil.isBrowser()) document.title = title;
|
|
158
|
+
}, [title]);
|
|
159
|
+
useUnmount(() => {
|
|
160
|
+
if (_pawover_kit_utils.EnvUtil.isBrowser() && options?.isRestoreOnUnmount) document.title = titleRef.current;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
exports.BREAK_POINT_TOKEN = BREAK_POINT_TOKEN;
|
|
165
|
+
exports.useLatest = useLatest;
|
|
166
|
+
exports.useMount = useMount;
|
|
167
|
+
exports.useResponsive = useResponsive;
|
|
168
|
+
exports.useTitle = useTitle;
|
|
169
|
+
exports.useUnmount = useUnmount;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './react.d.ts'
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { EffectCallback, RefObject } from "react";
|
|
2
|
+
import { AnyAsyncFunction, AnyFunction } from "@pawover/kit-types";
|
|
3
|
+
import { TupleToUnion } from "type-fest";
|
|
2
4
|
//#region src/react/useLatest.d.ts
|
|
3
5
|
/**
|
|
4
6
|
* 返回当前最新值的 Hook
|
|
@@ -7,12 +9,6 @@ import { EffectCallback, RefObject } from "react";
|
|
|
7
9
|
*/
|
|
8
10
|
declare function useLatest<T>(value: T): RefObject<T>;
|
|
9
11
|
//#endregion
|
|
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
|
|
11
|
-
/** 描述函数类型 */
|
|
12
|
-
type AnyFunction<P extends any[] = any[], R = any> = (...arg: P) => R;
|
|
13
|
-
/** 描述异步函数类型 */
|
|
14
|
-
type AnyAsyncFunction<P extends any[] = any[], R = any> = (...args: P) => Promise<R>;
|
|
15
|
-
//#endregion
|
|
16
12
|
//#region src/react/useMount.d.ts
|
|
17
13
|
/**
|
|
18
14
|
* 在组件初始化时执行的 Hook
|
|
@@ -34,60 +30,6 @@ type AnyAsyncFunction<P extends any[] = any[], R = any> = (...args: P) => Promis
|
|
|
34
30
|
*/
|
|
35
31
|
declare function useMount(effect: EffectCallback | AnyAsyncFunction): void;
|
|
36
32
|
//#endregion
|
|
37
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/tuple-to-union.d.ts
|
|
38
|
-
/**
|
|
39
|
-
Convert a tuple/array into a union type of its elements.
|
|
40
|
-
|
|
41
|
-
This can be useful when you have a fixed set of allowed values and want a type defining only the allowed values, but do not want to repeat yourself.
|
|
42
|
-
|
|
43
|
-
@example
|
|
44
|
-
```
|
|
45
|
-
import type {TupleToUnion} from 'type-fest';
|
|
46
|
-
|
|
47
|
-
const destinations = ['a', 'b', 'c'] as const;
|
|
48
|
-
|
|
49
|
-
type Destination = TupleToUnion<typeof destinations>;
|
|
50
|
-
//=> 'a' | 'b' | 'c'
|
|
51
|
-
|
|
52
|
-
function verifyDestination(destination: unknown): destination is Destination {
|
|
53
|
-
return destinations.includes(destination as any);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
type RequestBody = {
|
|
57
|
-
deliverTo: Destination;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
function verifyRequestBody(body: unknown): body is RequestBody {
|
|
61
|
-
const {deliverTo} = (body as any);
|
|
62
|
-
return typeof body === 'object' && body !== null && verifyDestination(deliverTo);
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Alternatively, you may use `typeof destinations[number]`. If `destinations` is a tuple, there is no difference. However if `destinations` is a string, the resulting type will the union of the characters in the string. Other types of `destinations` may result in a compile error. In comparison, TupleToUnion will return `never` if a tuple is not provided.
|
|
67
|
-
|
|
68
|
-
@example
|
|
69
|
-
```
|
|
70
|
-
const destinations = ['a', 'b', 'c'] as const;
|
|
71
|
-
|
|
72
|
-
type Destination = typeof destinations[number];
|
|
73
|
-
//=> 'a' | 'b' | 'c'
|
|
74
|
-
|
|
75
|
-
const erroringType = new Set(['a', 'b', 'c']);
|
|
76
|
-
|
|
77
|
-
// @ts-expect-error
|
|
78
|
-
type ErroringType = typeof erroringType[number];
|
|
79
|
-
// Error: Type 'Set<string>' has no matching index signature for type 'number'. ts(2537)
|
|
80
|
-
|
|
81
|
-
const numberBool: {[n: number]: boolean} = {1: true};
|
|
82
|
-
|
|
83
|
-
type NumberBool = typeof numberBool[number];
|
|
84
|
-
//=> boolean
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
@category Array
|
|
88
|
-
*/
|
|
89
|
-
type TupleToUnion<ArrayType> = ArrayType extends readonly unknown[] ? ArrayType[number] : never;
|
|
90
|
-
//#endregion
|
|
91
33
|
//#region src/react/useResponsive.d.ts
|
|
92
34
|
type Breakpoint = TupleToUnion<typeof BREAK_POINTS>;
|
|
93
35
|
type ResponsiveValues = Record<Breakpoint, boolean>;
|