@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
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './index.d.ts'
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { Split, TupleToUnion } from "type-fest";
|
|
2
|
+
//#region src/advancedRecord.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* 高级记录模式
|
|
5
|
+
*
|
|
6
|
+
* 由必选/可选标记(`"?"` | `"!"`)与读写权限标记(`"W"` | `"R"`)组成的二元组,用于控制 `AdvancedRecord` 的字段形态。
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // 必选且可读写
|
|
11
|
+
* const mode: AdvancedRecordMode = ["!", "W"];
|
|
12
|
+
* // 可选且只读
|
|
13
|
+
* const readonlyMode: AdvancedRecordMode = ["?", "R"];
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
type AdvancedRecordMode = ["?" | "!", "W" | "R"];
|
|
17
|
+
/**
|
|
18
|
+
* 高级记录(Advanced Record)
|
|
19
|
+
*
|
|
20
|
+
* 按模式组合生成指定键集合的映射类型,可控制字段的必选/可选与只读/可写。
|
|
21
|
+
*
|
|
22
|
+
* @template K 键集合
|
|
23
|
+
* @template A 值类型
|
|
24
|
+
* @template mode 记录模式(默认必选且可读写)
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* // 默认模式:必选且可读写
|
|
29
|
+
* type A = AdvancedRecord<"id" | "name", string>;
|
|
30
|
+
* // { id: string; name: string }
|
|
31
|
+
*
|
|
32
|
+
* // 可选且只读
|
|
33
|
+
* type B = AdvancedRecord<"id", string, ["?", "R"]>;
|
|
34
|
+
* // { readonly id?: string }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
type AdvancedRecord<K extends PropertyKey, A = unknown, mode extends AdvancedRecordMode = ["!", "W"]> = {
|
|
38
|
+
"!": {
|
|
39
|
+
R: { readonly [P in K]: A; };
|
|
40
|
+
W: { [P in K]: A; };
|
|
41
|
+
};
|
|
42
|
+
"?": {
|
|
43
|
+
R: { readonly [P in K]?: A; };
|
|
44
|
+
W: { [P in K]?: A; };
|
|
45
|
+
};
|
|
46
|
+
}[mode[0]][mode[1]];
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/api.d.ts
|
|
49
|
+
/** 字母表 */
|
|
50
|
+
type ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
51
|
+
/** 单个字母 */
|
|
52
|
+
type Letter = TupleToUnion<Split<ALPHABET, "">>;
|
|
53
|
+
/** 有效字符 */
|
|
54
|
+
type ValidChar = Letter | "_";
|
|
55
|
+
/**
|
|
56
|
+
* API 命名检查
|
|
57
|
+
*
|
|
58
|
+
* 递归校验命名仅包含大写字母与下划线,并剥离尾随下划线;遇到非法字符时返回空字符串。
|
|
59
|
+
*
|
|
60
|
+
* @template N 待检查的命名
|
|
61
|
+
* @template P 内部递归累计结果(由编译器推导,无需传入)
|
|
62
|
+
*
|
|
63
|
+
* @returns 剥离尾随下划线后的合法命名;包含非法字符时为 `""`
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* type A = ApiNameCheck<"GET_USER">; // "GET_USER"
|
|
68
|
+
* type B = ApiNameCheck<"GET_USER_">; // "GET_USER"(尾随下划线被剥离)
|
|
69
|
+
* type C = ApiNameCheck<"getUser">; // ""(小写字符非法)
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
type ApiNameCheck<N extends string, P extends string = ""> = N extends `${infer L extends ValidChar}${infer R}` ? ApiNameCheck<R, `${P}${L}`> : P extends `${infer S}_` ? S : P;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/global.d.ts
|
|
75
|
+
/**
|
|
76
|
+
* 原始类型
|
|
77
|
+
*
|
|
78
|
+
* TypeScript 中的全部原始值类型集合。
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const a: Primitive = "str";
|
|
83
|
+
* const b: Primitive = 42;
|
|
84
|
+
* const c: Primitive = null;
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
88
|
+
/**
|
|
89
|
+
* 任意对象类型
|
|
90
|
+
*
|
|
91
|
+
* 以索引签名描述任意键值对对象,键类型默认为 `PropertyKey`,值类型默认为 `any`。
|
|
92
|
+
*
|
|
93
|
+
* @template K 键类型
|
|
94
|
+
* @template T 值类型
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const obj: AnyObject = { a: 1, b: "2" };
|
|
99
|
+
* const numObj: AnyObject<"id", number> = { id: 1 };
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
type AnyObject<K extends PropertyKey = PropertyKey, T = any> = Record<K, T>;
|
|
103
|
+
/**
|
|
104
|
+
* 普通对象类型
|
|
105
|
+
*
|
|
106
|
+
* 以索引签名描述普通对象,值类型默认为 `unknown`,比 `AnyObject` 更严格。
|
|
107
|
+
*
|
|
108
|
+
* @template K 键类型
|
|
109
|
+
* @template T 值类型
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const obj: PlainObject = { a: 1 };
|
|
114
|
+
* const strMap: PlainObject<string, string> = { key: "value" };
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
type PlainObject<K extends PropertyKey = PropertyKey, T = unknown> = Record<K, T>;
|
|
118
|
+
/**
|
|
119
|
+
* 描述树类型
|
|
120
|
+
*
|
|
121
|
+
* 递归结构:每个节点都包含子树节点数组(子节点键名默认为 `children`)。
|
|
122
|
+
*
|
|
123
|
+
* @template T 节点基础类型(需为对象类型)
|
|
124
|
+
* @template CK 子节点键名
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* interface Node {
|
|
129
|
+
* id: number;
|
|
130
|
+
* name: string;
|
|
131
|
+
* }
|
|
132
|
+
* const tree: TreeLike<Node> = {
|
|
133
|
+
* id: 1,
|
|
134
|
+
* name: "root",
|
|
135
|
+
* children: [{ id: 2, name: "leaf", children: [] }],
|
|
136
|
+
* };
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
type TreeLike<T extends AnyObject, CK extends string = "children"> = T & Record<CK, TreeLike<T, CK>[]>;
|
|
140
|
+
/**
|
|
141
|
+
* 描述可选子节点树类型
|
|
142
|
+
*
|
|
143
|
+
* 递归结构:每个节点都可省略子节点键(子节点键名默认为 `children`)。
|
|
144
|
+
*
|
|
145
|
+
* @template T 节点基础类型(需为对象类型)
|
|
146
|
+
* @template CK 子节点键名
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* interface Node {
|
|
151
|
+
* id: number;
|
|
152
|
+
* name: string;
|
|
153
|
+
* }
|
|
154
|
+
* const leaf: TreeLikeOptionalChildren<Node> = { id: 2, name: "leaf" };
|
|
155
|
+
* const root: TreeLikeOptionalChildren<Node> = {
|
|
156
|
+
* id: 1,
|
|
157
|
+
* name: "root",
|
|
158
|
+
* children: [leaf],
|
|
159
|
+
* };
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
type TreeLikeOptionalChildren<T extends AnyObject, CK extends string = "children"> = T & { [K in CK]?: TreeLikeOptionalChildren<T, CK>[]; };
|
|
163
|
+
/**
|
|
164
|
+
* 描述函数类型
|
|
165
|
+
*
|
|
166
|
+
* 任意参数与任意返回值的函数类型。
|
|
167
|
+
*
|
|
168
|
+
* @template P 参数元组类型
|
|
169
|
+
* @template R 返回值类型
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* const fn: AnyFunction = (a, b) => a + b;
|
|
174
|
+
* const strFn: AnyFunction<[string], string> = (s) => s.toUpperCase();
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
type AnyFunction<P extends any[] = any[], R = any> = (...arg: P) => R;
|
|
178
|
+
/**
|
|
179
|
+
* 描述异步函数类型
|
|
180
|
+
*
|
|
181
|
+
* 任意参数且返回 Promise 的函数类型。
|
|
182
|
+
*
|
|
183
|
+
* @template P 参数元组类型
|
|
184
|
+
* @template R 返回值类型
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* const fn: AnyAsyncFunction = async () => {};
|
|
189
|
+
* const fetchFn: AnyAsyncFunction<[string], number> = async (url) => (await fetch(url)).status;
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
type AnyAsyncFunction<P extends any[] = any[], R = any> = (...args: P) => Promise<R>;
|
|
193
|
+
/**
|
|
194
|
+
* 描述生成器函数类型
|
|
195
|
+
*
|
|
196
|
+
* 任意参数且返回 Generator 的函数类型。
|
|
197
|
+
*
|
|
198
|
+
* @template P 参数元组类型
|
|
199
|
+
* @template T 产出值类型
|
|
200
|
+
* @template R 返回值类型
|
|
201
|
+
* @template N 下一传入值类型
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const fn: AnyGeneratorFunction<[], number> = function* () {
|
|
206
|
+
* yield 1;
|
|
207
|
+
* };
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
type AnyGeneratorFunction<P extends any[] = any[], T = any, R = any, N = any> = (...args: P) => Generator<T, R, N>;
|
|
211
|
+
/**
|
|
212
|
+
* 描述异步生成器函数类型
|
|
213
|
+
*
|
|
214
|
+
* 任意参数且返回 AsyncGenerator 的函数类型。
|
|
215
|
+
*
|
|
216
|
+
* @template P 参数元组类型
|
|
217
|
+
* @template T 产出值类型
|
|
218
|
+
* @template R 返回值类型
|
|
219
|
+
* @template N 下一传入值类型
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* const fn: AnyAsyncGeneratorFunction<[], number> = async function* () {
|
|
224
|
+
* yield 1;
|
|
225
|
+
* };
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
type AnyAsyncGeneratorFunction<P extends any[] = any[], T = any, R = any, N = any> = (...args: P) => AsyncGenerator<T, R, N>;
|
|
229
|
+
/**
|
|
230
|
+
* 描述无返回值函数
|
|
231
|
+
*
|
|
232
|
+
* 不接受参数且返回 `void` 的函数类型。
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* const fn: VoidFunction = () => {
|
|
237
|
+
* console.log("hello");
|
|
238
|
+
* };
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
type VoidFunction = () => void;
|
|
242
|
+
/**
|
|
243
|
+
* 判断是否为原始类型
|
|
244
|
+
*
|
|
245
|
+
* 若 `T` 为原始类型则结果为 `true`,否则为 `false`。
|
|
246
|
+
*
|
|
247
|
+
* @template T 待判断的类型
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* type A = IsPrimitive<string>; // true
|
|
252
|
+
* type B = IsPrimitive<{ a: 1 }>; // false
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
type IsPrimitive<T> = T extends Primitive ? true : false;
|
|
256
|
+
/**
|
|
257
|
+
* 判断是否具有索引签名
|
|
258
|
+
*
|
|
259
|
+
* 若 `T` 可被字符串索引(具有 string 索引签名)则结果为 `true`,否则为 `false`。
|
|
260
|
+
*
|
|
261
|
+
* @template T 待判断的类型
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* type A = HasStringIndex<Record<string, number>>; // true
|
|
266
|
+
* type B = HasStringIndex<{ a: 1 }>; // false
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
type HasStringIndex<T> = string extends keyof T ? true : false;
|
|
270
|
+
//#endregion
|
|
271
|
+
export type { AdvancedRecord, AdvancedRecordMode, AnyAsyncFunction, AnyAsyncGeneratorFunction, AnyFunction, AnyGeneratorFunction, AnyObject, ApiNameCheck, HasStringIndex, IsPrimitive, PlainObject, Primitive, TreeLike, TreeLikeOptionalChildren, VoidFunction };
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './react.d.ts'
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ReactNode, RefObject } from "react";
|
|
2
|
+
//#region src/react.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* 只读 Props 类型
|
|
5
|
+
*
|
|
6
|
+
* 将任意属性集合转换为只读的组件 Props 类型。
|
|
7
|
+
*
|
|
8
|
+
* @template P 属性集合
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* interface MyProps {
|
|
13
|
+
* title: string;
|
|
14
|
+
* }
|
|
15
|
+
* const props: Props<MyProps> = { title: "hello" };
|
|
16
|
+
* // props.title = "x"; // ❌ 只读,无法修改
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
type Props<P = unknown> = Readonly<P>;
|
|
20
|
+
/**
|
|
21
|
+
* 含 children 的只读 Props 类型
|
|
22
|
+
*
|
|
23
|
+
* 在只读 Props 基础上增加可选的 `children` 属性。
|
|
24
|
+
*
|
|
25
|
+
* @template P 属性集合
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* interface MyProps {
|
|
30
|
+
* title: string;
|
|
31
|
+
* }
|
|
32
|
+
* const props: PropsWithChildren<MyProps> = {
|
|
33
|
+
* title: "hello",
|
|
34
|
+
* children: <span>content</span>,
|
|
35
|
+
* };
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
type PropsWithChildren<P = unknown> = Readonly<P> & {
|
|
39
|
+
readonly children?: ReactNode | undefined;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* 含 ref 的只读 Props 类型
|
|
43
|
+
*
|
|
44
|
+
* 在只读 Props 基础上增加可选的 `ref` 属性。
|
|
45
|
+
*
|
|
46
|
+
* @template P 属性集合
|
|
47
|
+
* @template R ref 指向的 DOM 元素类型
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* interface MyProps {
|
|
52
|
+
* title: string;
|
|
53
|
+
* }
|
|
54
|
+
* const props: PropsWithRef<MyProps, HTMLDivElement> = {
|
|
55
|
+
* title: "hello",
|
|
56
|
+
* ref: useRef<HTMLDivElement>(null),
|
|
57
|
+
* };
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
type PropsWithRef<P = unknown, R = unknown> = Readonly<P> & {
|
|
61
|
+
readonly ref?: RefObject<R> | undefined;
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { Props, PropsWithChildren, PropsWithRef };
|
|
File without changes
|