@pawover/kit 0.0.0-alpha.1 → 0.0.0-alpha.11
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/enums.d.ts +23 -0
- package/dist/enums.js +24 -0
- package/dist/hooks-react.d.ts +63 -0
- package/dist/hooks-react.js +252 -0
- package/dist/index.d.ts +270 -0
- package/dist/index.js +945 -2
- package/dist/zod.d.ts +104 -0
- package/dist/zod.js +137 -0
- package/package.json +21 -27
- package/dist/enums/index.js +0 -20
- package/dist/hooks/react/index.js +0 -5
- package/dist/hooks/react/useCreation.js +0 -11
- package/dist/hooks/react/useLatest.js +0 -6
- package/dist/hooks/react/useMount.js +0 -29
- package/dist/hooks/react/useResponsive.js +0 -59
- package/dist/hooks/react/useUnmount.js +0 -17
- package/dist/types/enums/index.d.ts +0 -20
- package/dist/types/hooks/react/index.d.ts +0 -5
- package/dist/types/hooks/react/useCreation.d.ts +0 -2
- package/dist/types/hooks/react/useLatest.d.ts +0 -1
- package/dist/types/hooks/react/useMount.d.ts +0 -11
- package/dist/types/hooks/react/useResponsive.d.ts +0 -16
- package/dist/types/hooks/react/useUnmount.d.ts +0 -6
- package/dist/types/index.d.ts +0 -2
- package/dist/types/utils/array.d.ts +0 -76
- package/dist/types/utils/index.d.ts +0 -6
- package/dist/types/utils/object.d.ts +0 -53
- package/dist/types/utils/string.d.ts +0 -13
- package/dist/types/utils/to.d.ts +0 -5
- package/dist/types/utils/tree/index.d.ts +0 -6
- package/dist/types/utils/tree/rowsToTree.d.ts +0 -10
- package/dist/types/utils/tree/treeFilter.d.ts +0 -6
- package/dist/types/utils/tree/treeFind.d.ts +0 -8
- package/dist/types/utils/tree/treeForEach.d.ts +0 -5
- package/dist/types/utils/tree/treeMap.d.ts +0 -6
- package/dist/types/utils/tree/treeToRows.d.ts +0 -9
- package/dist/types/utils/tree/types.d.ts +0 -24
- package/dist/types/utils/typeof.d.ts +0 -29
- package/dist/utils/array.js +0 -196
- package/dist/utils/index.js +0 -6
- package/dist/utils/object.js +0 -138
- package/dist/utils/string.js +0 -70
- package/dist/utils/to.js +0 -16
- package/dist/utils/tree/index.js +0 -6
- package/dist/utils/tree/rowsToTree.js +0 -35
- package/dist/utils/tree/treeFilter.js +0 -92
- package/dist/utils/tree/treeFind.js +0 -82
- package/dist/utils/tree/treeForEach.js +0 -60
- package/dist/utils/tree/treeMap.js +0 -79
- package/dist/utils/tree/treeToRows.js +0 -13
- package/dist/utils/tree/types.js +0 -10
- package/dist/utils/typeof.js +0 -114
package/dist/enums.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/enums/index.d.ts
|
|
2
|
+
/** 屏幕响应断点 token 配置 */
|
|
3
|
+
declare const BREAK_POINT_TOKENS: {
|
|
4
|
+
readonly XS: 576;
|
|
5
|
+
readonly XSMin: 576;
|
|
6
|
+
readonly XSMax: 767;
|
|
7
|
+
readonly SM: 768;
|
|
8
|
+
readonly SMMin: 768;
|
|
9
|
+
readonly SMMax: 991;
|
|
10
|
+
readonly MD: 992;
|
|
11
|
+
readonly MDMin: 992;
|
|
12
|
+
readonly MDMax: 1199;
|
|
13
|
+
readonly LG: 1200;
|
|
14
|
+
readonly LGMin: 1200;
|
|
15
|
+
readonly LGMax: 1599;
|
|
16
|
+
readonly XL: 1600;
|
|
17
|
+
readonly XLMin: 1600;
|
|
18
|
+
readonly XLMax: 1919;
|
|
19
|
+
readonly XXL: 1920;
|
|
20
|
+
readonly XXLMin: 1920;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { BREAK_POINT_TOKENS };
|
package/dist/enums.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/enums/index.ts
|
|
2
|
+
/** 屏幕响应断点 token 配置 */
|
|
3
|
+
const BREAK_POINT_TOKENS = {
|
|
4
|
+
XS: 576,
|
|
5
|
+
XSMin: 576,
|
|
6
|
+
XSMax: 767,
|
|
7
|
+
SM: 768,
|
|
8
|
+
SMMin: 768,
|
|
9
|
+
SMMax: 991,
|
|
10
|
+
MD: 992,
|
|
11
|
+
MDMin: 992,
|
|
12
|
+
MDMax: 1199,
|
|
13
|
+
LG: 1200,
|
|
14
|
+
LGMin: 1200,
|
|
15
|
+
LGMax: 1599,
|
|
16
|
+
XL: 1600,
|
|
17
|
+
XLMin: 1600,
|
|
18
|
+
XLMax: 1919,
|
|
19
|
+
XXL: 1920,
|
|
20
|
+
XXLMin: 1920
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { BREAK_POINT_TOKENS };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as react0 from "react";
|
|
2
|
+
import { DependencyList, EffectCallback } from "react";
|
|
3
|
+
import { Breakpoint } from "@pawover/types";
|
|
4
|
+
|
|
5
|
+
//#region src/hooks/react/useCreation.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* useCreation
|
|
9
|
+
* @reference https://ahooks.js.org/zh-CN/hooks/use-creation
|
|
10
|
+
*
|
|
11
|
+
* @template T
|
|
12
|
+
* @param {() => T} factory
|
|
13
|
+
* @param {DependencyList} deps
|
|
14
|
+
*/
|
|
15
|
+
declare function useCreation<T>(factory: () => T, deps: DependencyList): T;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/hooks/react/useLatest.d.ts
|
|
18
|
+
/**
|
|
19
|
+
* 返回当前最新值的 Hook
|
|
20
|
+
* @reference https://ahooks.js.org/zh-CN/hooks/use-latest
|
|
21
|
+
*
|
|
22
|
+
* @template T
|
|
23
|
+
* @param {T} value
|
|
24
|
+
*/
|
|
25
|
+
declare function useLatest<T>(value: T): react0.RefObject<T>;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/hooks/react/useMount.d.ts
|
|
28
|
+
type MountCallback = EffectCallback | AsyncFunc;
|
|
29
|
+
/**
|
|
30
|
+
* 在组件初始化时执行的 Hook
|
|
31
|
+
* - 即使在严格模式下也只执行一次
|
|
32
|
+
* @reference https://ahooks.js.org/hooks/use-mount
|
|
33
|
+
*
|
|
34
|
+
* @param {MountCallback} effect 副作用函数
|
|
35
|
+
*/
|
|
36
|
+
declare function useMount(effect: MountCallback): void;
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/hooks/react/useResponsive.d.ts
|
|
39
|
+
type ResponsiveValues = Record<Breakpoint, boolean>;
|
|
40
|
+
interface ResponsiveHookOptions {
|
|
41
|
+
/**
|
|
42
|
+
* 紧凑布局断点
|
|
43
|
+
* - 低于此断点时使用紧凑布局
|
|
44
|
+
* @default "xl"
|
|
45
|
+
*/
|
|
46
|
+
compactBreakPoint?: Breakpoint;
|
|
47
|
+
}
|
|
48
|
+
declare function useResponsive(options?: ResponsiveHookOptions): {
|
|
49
|
+
responsive: ResponsiveValues;
|
|
50
|
+
current: Breakpoint;
|
|
51
|
+
isCompact: boolean;
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/hooks/react/useUnmount.d.ts
|
|
55
|
+
/**
|
|
56
|
+
* 在组件卸载时执行的 Hook
|
|
57
|
+
* @reference https://ahooks.js.org/zh-CN/hooks/use-unmount
|
|
58
|
+
*
|
|
59
|
+
* @param {Func} effect 副作用函数
|
|
60
|
+
*/
|
|
61
|
+
declare function useUnmount(effect: Func): void;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { useCreation, useLatest, useMount, useResponsive, useUnmount };
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/typeof.ts
|
|
4
|
+
const prototypes = {
|
|
5
|
+
string: "[object String]",
|
|
6
|
+
number: "[object Number]",
|
|
7
|
+
boolean: "[object Boolean]",
|
|
8
|
+
object: "[object Object]",
|
|
9
|
+
array: "[object Array]",
|
|
10
|
+
bigInt: "[object BigInt]",
|
|
11
|
+
symbol: "[object Symbol]",
|
|
12
|
+
function: "[object Function]",
|
|
13
|
+
generatorFunction: "[object GeneratorFunction]",
|
|
14
|
+
asyncFunction: "[object AsyncFunction]",
|
|
15
|
+
promise: "[object Promise]",
|
|
16
|
+
null: "[object Null]",
|
|
17
|
+
undefined: "[object Undefined]",
|
|
18
|
+
date: "[object Date]",
|
|
19
|
+
regExp: "[object RegExp]",
|
|
20
|
+
error: "[object Error]",
|
|
21
|
+
file: "[object File]",
|
|
22
|
+
map: "[object Map]",
|
|
23
|
+
weakMap: "[object WeakMap]",
|
|
24
|
+
set: "[object Set]",
|
|
25
|
+
weakSet: "[object WeakSet]",
|
|
26
|
+
window: "[object Window]",
|
|
27
|
+
webSocket: "[object WebSocket]",
|
|
28
|
+
URLSearchParams: "[object URLSearchParams]"
|
|
29
|
+
};
|
|
30
|
+
function resolvePrototypeString(value) {
|
|
31
|
+
return Object.prototype.toString.call(value);
|
|
32
|
+
}
|
|
33
|
+
function isObject(value) {
|
|
34
|
+
return resolvePrototypeString(value) === prototypes.object;
|
|
35
|
+
}
|
|
36
|
+
function isFunction(value) {
|
|
37
|
+
return [
|
|
38
|
+
prototypes.function,
|
|
39
|
+
prototypes.generatorFunction,
|
|
40
|
+
prototypes.asyncFunction
|
|
41
|
+
].includes(resolvePrototypeString(value));
|
|
42
|
+
}
|
|
43
|
+
function isPromise(value) {
|
|
44
|
+
return resolvePrototypeString(value) === prototypes.promise;
|
|
45
|
+
}
|
|
46
|
+
function isPromiseLike(value) {
|
|
47
|
+
return isPromise(value) || isObject(value) && isFunction(value["then"]);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 判断给定的值是否相等
|
|
51
|
+
* @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
|
|
52
|
+
*
|
|
53
|
+
* @param {T} x
|
|
54
|
+
* @param {T} y
|
|
55
|
+
*/
|
|
56
|
+
function isEqual(x, y) {
|
|
57
|
+
if (Object.is(x, y)) return true;
|
|
58
|
+
if (x instanceof Date && y instanceof Date) return x.getTime() === y.getTime();
|
|
59
|
+
if (x instanceof RegExp && y instanceof RegExp) return x.toString() === y.toString();
|
|
60
|
+
if (typeof x !== "object" || x === null || typeof y !== "object" || y === null) return false;
|
|
61
|
+
const keysX = Reflect.ownKeys(x);
|
|
62
|
+
const keysY = Reflect.ownKeys(y);
|
|
63
|
+
if (keysX.length !== keysY.length) return false;
|
|
64
|
+
for (const key of keysX) {
|
|
65
|
+
if (!Reflect.has(y, key)) return false;
|
|
66
|
+
if (!isEqual(x[key], y[key])) return false;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/utils/object.ts
|
|
73
|
+
/**
|
|
74
|
+
* 返回对象的可枚举属性和方法的名称
|
|
75
|
+
* - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型
|
|
76
|
+
*
|
|
77
|
+
* @param obj 对象
|
|
78
|
+
* @returns 对象所有可枚举的属性的键名
|
|
79
|
+
*/
|
|
80
|
+
function objectKeys(obj) {
|
|
81
|
+
return Object.keys(obj);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/hooks/react/useCreation.ts
|
|
86
|
+
/**
|
|
87
|
+
* useCreation
|
|
88
|
+
* @reference https://ahooks.js.org/zh-CN/hooks/use-creation
|
|
89
|
+
*
|
|
90
|
+
* @template T
|
|
91
|
+
* @param {() => T} factory
|
|
92
|
+
* @param {DependencyList} deps
|
|
93
|
+
*/
|
|
94
|
+
function useCreation(factory, deps) {
|
|
95
|
+
const { current } = useRef({
|
|
96
|
+
deps,
|
|
97
|
+
result: void 0,
|
|
98
|
+
isInitialized: false
|
|
99
|
+
});
|
|
100
|
+
if (current.isInitialized === false || !isEqual(current.deps, deps)) {
|
|
101
|
+
current.deps = deps;
|
|
102
|
+
current.result = factory();
|
|
103
|
+
current.isInitialized = true;
|
|
104
|
+
}
|
|
105
|
+
return current.result;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/hooks/react/useLatest.ts
|
|
110
|
+
/**
|
|
111
|
+
* 返回当前最新值的 Hook
|
|
112
|
+
* @reference https://ahooks.js.org/zh-CN/hooks/use-latest
|
|
113
|
+
*
|
|
114
|
+
* @template T
|
|
115
|
+
* @param {T} value
|
|
116
|
+
*/
|
|
117
|
+
function useLatest(value) {
|
|
118
|
+
const ref = useRef(value);
|
|
119
|
+
ref.current = value;
|
|
120
|
+
return ref;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/hooks/react/useMount.ts
|
|
125
|
+
/**
|
|
126
|
+
* 在组件初始化时执行的 Hook
|
|
127
|
+
* - 即使在严格模式下也只执行一次
|
|
128
|
+
* @reference https://ahooks.js.org/hooks/use-mount
|
|
129
|
+
*
|
|
130
|
+
* @param {MountCallback} effect 副作用函数
|
|
131
|
+
*/
|
|
132
|
+
function useMount(effect) {
|
|
133
|
+
if (!isFunction(effect)) console.error(`useMount expected parameter is a function, but got ${typeof effect}`);
|
|
134
|
+
const isMountedRef = useRef(false);
|
|
135
|
+
const effectRef = useLatest(effect);
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (isMountedRef.current) return;
|
|
138
|
+
isMountedRef.current = true;
|
|
139
|
+
const result = effectRef.current?.();
|
|
140
|
+
if (isPromiseLike(result)) return;
|
|
141
|
+
return result;
|
|
142
|
+
}, []);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/enums/index.ts
|
|
147
|
+
/** 屏幕响应断点 token 配置 */
|
|
148
|
+
const BREAK_POINT_TOKENS = {
|
|
149
|
+
XS: 576,
|
|
150
|
+
XSMin: 576,
|
|
151
|
+
XSMax: 767,
|
|
152
|
+
SM: 768,
|
|
153
|
+
SMMin: 768,
|
|
154
|
+
SMMax: 991,
|
|
155
|
+
MD: 992,
|
|
156
|
+
MDMin: 992,
|
|
157
|
+
MDMax: 1199,
|
|
158
|
+
LG: 1200,
|
|
159
|
+
LGMin: 1200,
|
|
160
|
+
LGMax: 1599,
|
|
161
|
+
XL: 1600,
|
|
162
|
+
XLMin: 1600,
|
|
163
|
+
XLMax: 1919,
|
|
164
|
+
XXL: 1920,
|
|
165
|
+
XXLMin: 1920
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/hooks/react/useResponsive.ts
|
|
170
|
+
const subscriberList = /* @__PURE__ */ new Set();
|
|
171
|
+
const { XS, SM, MD, LG, XL, XXL } = BREAK_POINT_TOKENS;
|
|
172
|
+
const defaultResponsiveValues = {
|
|
173
|
+
xxl: false,
|
|
174
|
+
xl: false,
|
|
175
|
+
lg: false,
|
|
176
|
+
md: false,
|
|
177
|
+
sm: false,
|
|
178
|
+
xs: false
|
|
179
|
+
};
|
|
180
|
+
const responsiveConfig = Object.freeze({
|
|
181
|
+
xxl: XXL,
|
|
182
|
+
xl: XL,
|
|
183
|
+
lg: LG,
|
|
184
|
+
md: MD,
|
|
185
|
+
sm: SM,
|
|
186
|
+
xs: XS
|
|
187
|
+
});
|
|
188
|
+
let responsiveValues = { ...defaultResponsiveValues };
|
|
189
|
+
function useResponsive(options) {
|
|
190
|
+
const { compactBreakPoint = "xl" } = options || {};
|
|
191
|
+
calculate();
|
|
192
|
+
const [responsive, setResponsive] = useState(responsiveValues);
|
|
193
|
+
const isCompact = !responsive[compactBreakPoint];
|
|
194
|
+
const current = objectKeys(defaultResponsiveValues).find((key) => responsive[key] === true) || "xs";
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
addListener();
|
|
197
|
+
const subscriber = () => {
|
|
198
|
+
setResponsive(responsiveValues);
|
|
199
|
+
};
|
|
200
|
+
subscriberList.add(subscriber);
|
|
201
|
+
return () => {
|
|
202
|
+
subscriberList.delete(subscriber);
|
|
203
|
+
if (subscriberList.size === 0) removeListener();
|
|
204
|
+
};
|
|
205
|
+
}, []);
|
|
206
|
+
return {
|
|
207
|
+
responsive,
|
|
208
|
+
current,
|
|
209
|
+
isCompact
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function resizeListener() {
|
|
213
|
+
const oldInfo = responsiveValues;
|
|
214
|
+
calculate();
|
|
215
|
+
if (oldInfo === responsiveValues) return;
|
|
216
|
+
for (const subscriber of subscriberList) subscriber();
|
|
217
|
+
}
|
|
218
|
+
function addListener() {
|
|
219
|
+
window.addEventListener("resize", resizeListener);
|
|
220
|
+
}
|
|
221
|
+
function removeListener() {
|
|
222
|
+
window.removeEventListener("resize", resizeListener);
|
|
223
|
+
}
|
|
224
|
+
function calculate() {
|
|
225
|
+
const width = window.innerWidth;
|
|
226
|
+
const newValues = { ...defaultResponsiveValues };
|
|
227
|
+
let shouldUpdate = false;
|
|
228
|
+
for (const key of objectKeys(responsiveConfig)) {
|
|
229
|
+
newValues[key] = width >= responsiveConfig[key];
|
|
230
|
+
if (newValues[key] !== responsiveValues[key]) shouldUpdate = true;
|
|
231
|
+
}
|
|
232
|
+
if (shouldUpdate) responsiveValues = newValues;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/hooks/react/useUnmount.ts
|
|
237
|
+
/**
|
|
238
|
+
* 在组件卸载时执行的 Hook
|
|
239
|
+
* @reference https://ahooks.js.org/zh-CN/hooks/use-unmount
|
|
240
|
+
*
|
|
241
|
+
* @param {Func} effect 副作用函数
|
|
242
|
+
*/
|
|
243
|
+
function useUnmount(effect) {
|
|
244
|
+
if (!isFunction(effect)) console.error(`useUnmount expected parameter is a function, got ${typeof effect}`);
|
|
245
|
+
const effectRef = useLatest(effect);
|
|
246
|
+
useEffect(() => () => {
|
|
247
|
+
effectRef.current?.();
|
|
248
|
+
}, []);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
export { useCreation, useLatest, useMount, useResponsive, useUnmount };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { Class, NonEmptyObject, Replace, SetOptional, UnionToTuple, ValueOf } from "type-fest";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/tree/types.d.ts
|
|
4
|
+
type RowKey = "id";
|
|
5
|
+
type ParentIdKey = "parentId";
|
|
6
|
+
type ChildrenKey = "children";
|
|
7
|
+
type Strategy = "pre" | "post" | "breadth";
|
|
8
|
+
interface BaseCallbackMeta<T> {
|
|
9
|
+
depth: number;
|
|
10
|
+
parents?: T[];
|
|
11
|
+
}
|
|
12
|
+
interface BaseOptions<T, CK extends string> {
|
|
13
|
+
childrenKey?: CK;
|
|
14
|
+
strategy?: Strategy;
|
|
15
|
+
getChildrenKey?: (row: T, meta: BaseCallbackMeta<T>) => CK | undefined;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/utils/tree/treeFilter.d.ts
|
|
19
|
+
type TreeFilterOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
|
|
20
|
+
type TreeFilterCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => boolean;
|
|
21
|
+
declare function treeFilter<T extends AnyObject, CK extends string = ChildrenKey>(tree: T[], callback: TreeFilterCallback<T>, options?: TreeFilterOptions<T, CK>): T[];
|
|
22
|
+
declare function treeFilter<T extends AnyObject, CK extends string = ChildrenKey>(tree: T, callback: TreeFilterCallback<T>, options?: TreeFilterOptions<T, CK>): T;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/utils/tree/treeFind.d.ts
|
|
25
|
+
type TreeFindOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
|
|
26
|
+
type TreeFindCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* 查找树节点,找到第一个返回非空值的节点
|
|
29
|
+
*/
|
|
30
|
+
declare function treeFind<T extends AnyObject, CK extends string = ChildrenKey>(tree: T | T[], callback: TreeFindCallback<T>, options?: TreeFindOptions<T, CK>): T | undefined;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/utils/tree/treeForEach.d.ts
|
|
33
|
+
type TreeForeachOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
|
|
34
|
+
type TreeForeachCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => void;
|
|
35
|
+
declare function treeForEach<T extends AnyObject, CK extends string = ChildrenKey>(tree: T | T[], callback: TreeForeachCallback<T>, options?: TreeForeachOptions<T, CK>): void;
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/utils/tree/treeMap.d.ts
|
|
38
|
+
type TreeMapOptions<T extends AnyObject, CK extends string> = BaseOptions<T, CK>;
|
|
39
|
+
type TreeMapCallback<R extends AnyObject, T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => R;
|
|
40
|
+
declare function treeMap<R extends AnyObject, T extends AnyObject, CK extends string = ChildrenKey>(tree: T[], callback: TreeMapCallback<R, T>, options?: TreeMapOptions<T, CK>): TreeLike<R, CK>[];
|
|
41
|
+
declare function treeMap<R extends AnyObject, T extends AnyObject, CK extends string = ChildrenKey>(tree: T, callback: TreeMapCallback<R, T>, options?: TreeMapOptions<T, CK>): TreeLike<R, CK>;
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/utils/tree/rowsToTree.d.ts
|
|
44
|
+
interface RowsToTreeOptions<RK extends string = RowKey, PK extends string = ParentIdKey, CK extends string = ChildrenKey> {
|
|
45
|
+
rowKey?: RK;
|
|
46
|
+
parentIdKey?: PK;
|
|
47
|
+
childrenKey?: CK;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 行结构 转 树结构
|
|
51
|
+
*/
|
|
52
|
+
declare function rowsToTree<T extends AnyObject = AnyObject, CK extends string = ChildrenKey, R = TreeLike<T, CK>, RK extends string = RowKey, PK extends string = ParentIdKey>(rows: T[], options?: RowsToTreeOptions<RK, PK, CK> | undefined): R[];
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/utils/tree/treeToRows.d.ts
|
|
55
|
+
type TreeToRowsOptions<T extends AnyObject, CK extends string = ChildrenKey> = TreeForeachOptions<T, CK>;
|
|
56
|
+
/**
|
|
57
|
+
* 树结构 转 行结构
|
|
58
|
+
*/
|
|
59
|
+
declare function treeToRows<T extends AnyObject, CK extends string = ChildrenKey, R extends AnyObject = SetOptional<T, CK>>(tree: T | T[], options?: TreeToRowsOptions<T, CK>): R[];
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/utils/array.d.ts
|
|
62
|
+
declare function toArray<T>(candidate?: T | T[] | false): T[];
|
|
63
|
+
/**
|
|
64
|
+
* 获取数组第一项
|
|
65
|
+
*
|
|
66
|
+
* @param initialList 初始数组
|
|
67
|
+
* @param saveValue 安全值
|
|
68
|
+
*/
|
|
69
|
+
declare function arrayFirst<T>(initialList: readonly T[], saveValue?: T): T | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* 获取数组最后一项
|
|
72
|
+
*
|
|
73
|
+
* @param initialList 初始数组
|
|
74
|
+
* @param saveValue 安全值
|
|
75
|
+
*/
|
|
76
|
+
declare function arrayLast<T>(initialList: readonly T[], saveValue?: T): T | undefined;
|
|
77
|
+
declare function arrayDiff<T>(initialList: readonly T[], diffList: readonly T[], match: (row: T) => PropertyKey): T[];
|
|
78
|
+
/**
|
|
79
|
+
* 数组竞争
|
|
80
|
+
* - 返回在匹配函数的比较条件中获胜的最终项目,适用于更复杂的最小值/最大值计算
|
|
81
|
+
*
|
|
82
|
+
* @param initialList 数组
|
|
83
|
+
* @param match 匹配函数
|
|
84
|
+
*/
|
|
85
|
+
declare function arrayCompete<T>(initialList: readonly T[], match: (a: T, b: T) => T): T | null;
|
|
86
|
+
/**
|
|
87
|
+
* 统计数组的项目出现次数
|
|
88
|
+
* - 通过给定的标识符匹配函数,返回一个对象,其中键是回调函数返回的 key 值,每个值是一个整数,表示该 key 出现的次数
|
|
89
|
+
*
|
|
90
|
+
* @param initialList 初始数组
|
|
91
|
+
* @param match 标识符匹配函数
|
|
92
|
+
*/
|
|
93
|
+
declare function arrayCounting<T, K extends PropertyKey>(initialList: readonly T[], match: (row: T) => K): Record<string, number>;
|
|
94
|
+
/**
|
|
95
|
+
* 数组项替换
|
|
96
|
+
* - 在给定的数组中,替换符合匹配函数结果的项目。只替换第一个匹配项。始终返回原始数组的副本。
|
|
97
|
+
*
|
|
98
|
+
* @param initialList 初始数组
|
|
99
|
+
* @param newItem 替换项
|
|
100
|
+
* @param match 匹配函数
|
|
101
|
+
*/
|
|
102
|
+
declare function arrayReplace<T>(initialList: readonly T[], newItem: T, match: (row: T, index: number) => boolean): T[];
|
|
103
|
+
/**
|
|
104
|
+
* 数组选择
|
|
105
|
+
* - 一次性应用 `filter` 和 `map` 操作
|
|
106
|
+
*
|
|
107
|
+
* @param initialList 初始数组
|
|
108
|
+
* @param filter filter 函数
|
|
109
|
+
* @param mapper map 函数
|
|
110
|
+
*/
|
|
111
|
+
declare function arrayPick<T, K = T>(initialList: readonly T[], filter: (row: T, index: number) => boolean, mapper?: ((row: T, index: number) => K) | undefined): (readonly T[] & unknown[]) | K[];
|
|
112
|
+
/**
|
|
113
|
+
* 数组切分
|
|
114
|
+
* - 将数组以指定的长度切分后,组合在高维数组中
|
|
115
|
+
*
|
|
116
|
+
* @param initialList 初始数组
|
|
117
|
+
* @param size 分割尺寸,默认 `10`
|
|
118
|
+
*/
|
|
119
|
+
declare function arraySplit<T>(initialList: readonly T[], size?: number): T[][];
|
|
120
|
+
/**
|
|
121
|
+
* 数组迭代
|
|
122
|
+
* - 运行一个函数 n 次以生成一个值,迭代函数将作为还原器运行无数次,然后返回累积值
|
|
123
|
+
*
|
|
124
|
+
* @param count 迭代次数
|
|
125
|
+
* @param iterate 迭代函数
|
|
126
|
+
* @param initialValue 初始值
|
|
127
|
+
*/
|
|
128
|
+
declare function arrayIterate<T>(count: number, iterate: (currentValue: T, iteration: number) => T, initialValue: T): T;
|
|
129
|
+
/**
|
|
130
|
+
* 数组合并
|
|
131
|
+
* - 通过给定的标识符匹配函数,用第二个数组中的匹配项替换第一个数组中匹配项的所有内容
|
|
132
|
+
*
|
|
133
|
+
* @param initialList 初始数组
|
|
134
|
+
* @param mergeList 待合并数组
|
|
135
|
+
* @param match 标识符匹配函数
|
|
136
|
+
*/
|
|
137
|
+
declare function arrayMerge<T>(initialList: readonly T[], mergeList: readonly T[], match: (item: T) => unknown): readonly T[] & unknown[];
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/utils/clone.d.ts
|
|
140
|
+
interface CloningStrategy {
|
|
141
|
+
cloneMap: <K, V>(parent: Map<K, V>, track: (newParent: Map<K, V>) => Map<K, V>, clone: <T>(value: T) => T) => Map<K, V> | null;
|
|
142
|
+
cloneSet: <T>(parent: Set<T>, track: (newParent: Set<T>) => Set<T>, clone: <T>(value: T) => T) => Set<T> | null;
|
|
143
|
+
cloneArray: <T>(parent: readonly T[], track: (newParent: T[]) => T[], clone: <T>(value: T) => T) => T[] | null;
|
|
144
|
+
cloneObject: <T extends AnyObject>(parent: T, track: (newParent: T) => T, clone: <T>(value: T) => T) => T | null;
|
|
145
|
+
cloneOther: <T>(parent: T, track: (newParent: T) => T, clone: <T>(value: T) => T) => T | null;
|
|
146
|
+
}
|
|
147
|
+
declare const DefaultCloningStrategy: CloningStrategy;
|
|
148
|
+
/**
|
|
149
|
+
* cloneDeep
|
|
150
|
+
* @reference https://github.com/radashi-org/radashi/blob/main/src/object/cloneDeep.ts
|
|
151
|
+
*/
|
|
152
|
+
declare function cloneDeep<T extends AnyObject>(root: T, customStrategy?: Partial<CloningStrategy>): T;
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/utils/object.d.ts
|
|
155
|
+
/**
|
|
156
|
+
* 返回对象的可枚举属性和方法的名称
|
|
157
|
+
* - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型
|
|
158
|
+
*
|
|
159
|
+
* @param obj 对象
|
|
160
|
+
* @returns 对象所有可枚举的属性的键名
|
|
161
|
+
*/
|
|
162
|
+
declare function objectKeys<O extends AnyObject>(obj: O): (keyof O)[];
|
|
163
|
+
/**
|
|
164
|
+
* 返回对象的可枚举属性的值数组
|
|
165
|
+
*
|
|
166
|
+
* @param obj 对象
|
|
167
|
+
*/
|
|
168
|
+
declare function objectValues<O extends AnyObject>(obj: O): UnionToTuple<ValueOf<O>>;
|
|
169
|
+
/**
|
|
170
|
+
* 返回对象的可枚举属性的键/值数组
|
|
171
|
+
*
|
|
172
|
+
* @param obj 对象
|
|
173
|
+
*/
|
|
174
|
+
declare function objectEntries<O extends AnyObject>(obj: O): [string & keyof O, O[keyof O]][];
|
|
175
|
+
/**
|
|
176
|
+
* 对象反转
|
|
177
|
+
* - 返回交换了对象的可枚举属性的值/键对象
|
|
178
|
+
*
|
|
179
|
+
* @param obj 对象
|
|
180
|
+
*/
|
|
181
|
+
declare function objectSwitch<O extends AnyObject>(obj: NonEmptyObject<O>): Record<O[keyof O], keyof O>;
|
|
182
|
+
/**
|
|
183
|
+
* 对象合并
|
|
184
|
+
* - 将两个对象递归合并为一个新对象,从右到左依次使用数值
|
|
185
|
+
* - 递归只适用于子对象属性
|
|
186
|
+
*/
|
|
187
|
+
declare function objectAssign<O extends AnyObject>(obj: O, overrideObj: O): O;
|
|
188
|
+
declare function objectPick<O extends AnyObject, K extends keyof O>(obj: O, keys: readonly K[]): Pick<O, K>;
|
|
189
|
+
/**
|
|
190
|
+
* 获取枚举所有属性的键
|
|
191
|
+
*
|
|
192
|
+
* @param enumeration 枚举
|
|
193
|
+
*/
|
|
194
|
+
declare function enumKeys<E extends AnyObject>(enumeration: NonEmptyObject<E>): [keyof E, ...(keyof E)[]];
|
|
195
|
+
/**
|
|
196
|
+
* 获取枚举所有属性的值
|
|
197
|
+
*
|
|
198
|
+
* @param enumeration 枚举
|
|
199
|
+
*/
|
|
200
|
+
declare function enumValues<E extends AnyObject>(enumeration: NonEmptyObject<E>): UnionToTuple<ValueOf<E>>;
|
|
201
|
+
/**
|
|
202
|
+
* 返回枚举的属性的键/值数组
|
|
203
|
+
*
|
|
204
|
+
* @param enumeration 枚举
|
|
205
|
+
*/
|
|
206
|
+
declare function enumEntries<E extends AnyObject>(enumeration: NonEmptyObject<E>): [keyof E, E[keyof E]][];
|
|
207
|
+
declare function mapEntries<TKey extends PropertyKey, TValue, TNewKey extends PropertyKey, TNewValue>(obj: UnknownObject<TKey, TValue>, toEntry: (key: TKey, value: TValue) => [TNewKey, TNewValue]): UnknownObject<TNewKey, TNewValue>;
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/utils/string.d.ts
|
|
210
|
+
/**
|
|
211
|
+
* 转义特殊字符
|
|
212
|
+
*
|
|
213
|
+
* @link https://github.com/sindresorhus/escape-string-regexp
|
|
214
|
+
* @param value 字符串
|
|
215
|
+
*/
|
|
216
|
+
declare function escapeStringRegexp(value: string): string;
|
|
217
|
+
/**
|
|
218
|
+
* 首字母大小写
|
|
219
|
+
*/
|
|
220
|
+
declare function stringInitialCase(value: string, type: "lower" | "upper"): string;
|
|
221
|
+
declare function stringToJson<R extends AnyObject = AnyObject, D extends R = R>(data: string | null | undefined, safeValue: D): R;
|
|
222
|
+
declare function stringToValues<T extends number | string = number>(data: string | null | undefined, valueType?: "number" | "string"): T[];
|
|
223
|
+
declare function stringReplace<I extends string, S extends string, R extends string>(input: I, search: S, replacement: R): Replace<I, S, R>;
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/utils/to.d.ts
|
|
226
|
+
/**
|
|
227
|
+
* @param promise
|
|
228
|
+
* @param errorExt - 可以传递给err对象的其他信息
|
|
229
|
+
*/
|
|
230
|
+
declare function to<T, U = Error>(promise: Readonly<Promise<T>>, errorExt?: UnknownObject): Promise<[U, undefined] | [null, T]>;
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/utils/typeof.d.ts
|
|
233
|
+
declare function isString<T extends string>(value: unknown): value is T;
|
|
234
|
+
declare function isNumber<T extends number>(value: unknown): value is T;
|
|
235
|
+
declare function isBoolean<T extends boolean>(value: unknown): value is T;
|
|
236
|
+
declare function isObject<T extends Record<PropertyKey, unknown>>(value: unknown): value is T;
|
|
237
|
+
declare function isArray<T extends unknown[]>(value: unknown): value is T;
|
|
238
|
+
declare function isBigInt<T extends bigint>(value: unknown): value is T;
|
|
239
|
+
declare function isSymbol<T extends symbol>(value: unknown): value is T;
|
|
240
|
+
declare function isFunction<T extends Func>(value: unknown): value is T;
|
|
241
|
+
declare function isGeneratorFunction<T extends Func>(value: unknown): value is T;
|
|
242
|
+
declare function isAsyncFunction<T extends AsyncFunc>(value: unknown): value is T;
|
|
243
|
+
declare function isPromise<T extends Promise<unknown>>(value: unknown): value is T;
|
|
244
|
+
declare function isPromiseLike<T extends PromiseLike<unknown>>(value: unknown): value is T;
|
|
245
|
+
declare function isNull<T extends null>(value: unknown): value is T;
|
|
246
|
+
declare function isUndefined<T extends undefined>(value: unknown): value is T;
|
|
247
|
+
declare function isDate<T extends Date>(value: unknown): value is T;
|
|
248
|
+
declare function isRegExp<T extends RegExp>(value: unknown): value is T;
|
|
249
|
+
declare function isError<T extends Error>(value: unknown): value is T;
|
|
250
|
+
declare function isFile<T extends File>(value: unknown): value is T;
|
|
251
|
+
declare function isMap<T extends Map<unknown, unknown>>(value: unknown): value is T;
|
|
252
|
+
declare function isWeakMap<T extends WeakMap<AnyObject, unknown>>(value: unknown): value is T;
|
|
253
|
+
declare function isSet<T extends Set<unknown>>(value: unknown): value is T;
|
|
254
|
+
declare function isWeakSet<T extends WeakSet<AnyObject>>(value: unknown): value is T;
|
|
255
|
+
declare function isWindow<T extends Window>(value: unknown): value is T;
|
|
256
|
+
declare function isWebSocket<T extends WebSocket>(value: unknown): value is T;
|
|
257
|
+
declare function isURLSearchParams<T extends Window>(value: unknown): value is T;
|
|
258
|
+
declare function isClass<T extends Class<AnyObject>>(value: unknown): value is T;
|
|
259
|
+
declare function isInteger<T extends number>(value: unknown): value is T;
|
|
260
|
+
declare function isIterable<T extends Iterable<unknown>>(value: unknown): value is T;
|
|
261
|
+
/**
|
|
262
|
+
* 判断给定的值是否相等
|
|
263
|
+
* @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
|
|
264
|
+
*
|
|
265
|
+
* @param {T} x
|
|
266
|
+
* @param {T} y
|
|
267
|
+
*/
|
|
268
|
+
declare function isEqual<T>(x: T, y: T): boolean;
|
|
269
|
+
//#endregion
|
|
270
|
+
export { CloningStrategy, DefaultCloningStrategy, arrayCompete, arrayCounting, arrayDiff, arrayFirst, arrayIterate, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumValues, escapeStringRegexp, isArray, isAsyncFunction, isBigInt, isBoolean, isClass, isDate, isEqual, isError, isFile, isFunction, isGeneratorFunction, isInteger, isIterable, isMap, isNull, isNumber, isObject, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, rowsToTree, stringInitialCase, stringReplace, stringToJson, stringToValues, to, toArray, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
|