@pawover/kit 0.0.0-alpha.1

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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/enums/index.js +20 -0
  4. package/dist/hooks/react/index.js +5 -0
  5. package/dist/hooks/react/useCreation.js +11 -0
  6. package/dist/hooks/react/useLatest.js +6 -0
  7. package/dist/hooks/react/useMount.js +29 -0
  8. package/dist/hooks/react/useResponsive.js +59 -0
  9. package/dist/hooks/react/useUnmount.js +17 -0
  10. package/dist/index.js +2 -0
  11. package/dist/types/enums/index.d.ts +20 -0
  12. package/dist/types/hooks/react/index.d.ts +5 -0
  13. package/dist/types/hooks/react/useCreation.d.ts +2 -0
  14. package/dist/types/hooks/react/useLatest.d.ts +1 -0
  15. package/dist/types/hooks/react/useMount.d.ts +11 -0
  16. package/dist/types/hooks/react/useResponsive.d.ts +16 -0
  17. package/dist/types/hooks/react/useUnmount.d.ts +6 -0
  18. package/dist/types/index.d.ts +2 -0
  19. package/dist/types/utils/array.d.ts +76 -0
  20. package/dist/types/utils/index.d.ts +6 -0
  21. package/dist/types/utils/object.d.ts +53 -0
  22. package/dist/types/utils/string.d.ts +13 -0
  23. package/dist/types/utils/to.d.ts +5 -0
  24. package/dist/types/utils/tree/index.d.ts +6 -0
  25. package/dist/types/utils/tree/rowsToTree.d.ts +10 -0
  26. package/dist/types/utils/tree/treeFilter.d.ts +6 -0
  27. package/dist/types/utils/tree/treeFind.d.ts +8 -0
  28. package/dist/types/utils/tree/treeForEach.d.ts +5 -0
  29. package/dist/types/utils/tree/treeMap.d.ts +6 -0
  30. package/dist/types/utils/tree/treeToRows.d.ts +9 -0
  31. package/dist/types/utils/tree/types.d.ts +24 -0
  32. package/dist/types/utils/typeof.d.ts +29 -0
  33. package/dist/utils/array.js +196 -0
  34. package/dist/utils/index.js +6 -0
  35. package/dist/utils/object.js +138 -0
  36. package/dist/utils/string.js +70 -0
  37. package/dist/utils/to.js +16 -0
  38. package/dist/utils/tree/index.js +6 -0
  39. package/dist/utils/tree/rowsToTree.js +35 -0
  40. package/dist/utils/tree/treeFilter.js +92 -0
  41. package/dist/utils/tree/treeFind.js +82 -0
  42. package/dist/utils/tree/treeForEach.js +60 -0
  43. package/dist/utils/tree/treeMap.js +79 -0
  44. package/dist/utils/tree/treeToRows.js +13 -0
  45. package/dist/utils/tree/types.js +10 -0
  46. package/dist/utils/typeof.js +114 -0
  47. package/package.json +90 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 猫爪在上
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # pawover-kit
@@ -0,0 +1,20 @@
1
+ /** 屏幕响应断点 token 配置 */
2
+ export const BREAK_POINT_TOKENS = {
3
+ XS: 576,
4
+ XSMin: 576,
5
+ XSMax: 767,
6
+ SM: 768,
7
+ SMMin: 768,
8
+ SMMax: 991,
9
+ MD: 992,
10
+ MDMin: 992,
11
+ MDMax: 1199,
12
+ LG: 1200,
13
+ LGMin: 1200,
14
+ LGMax: 1599,
15
+ XL: 1600,
16
+ XLMin: 1600,
17
+ XLMax: 1919,
18
+ XXL: 1920,
19
+ XXLMin: 1920,
20
+ };
@@ -0,0 +1,5 @@
1
+ export * from "./useCreation";
2
+ export * from "./useLatest";
3
+ export * from "./useMount";
4
+ export * from "./useResponsive";
5
+ export * from "./useUnmount";
@@ -0,0 +1,11 @@
1
+ import { isEqual } from "radashi";
2
+ import { useRef } from "react";
3
+ export function useCreation(factory, deps) {
4
+ const { current } = useRef({ deps, result: undefined, isInitialized: false });
5
+ if (current.isInitialized === false || !isEqual(current.deps, deps)) {
6
+ current.deps = deps;
7
+ current.result = factory();
8
+ current.isInitialized = true;
9
+ }
10
+ return current.result;
11
+ }
@@ -0,0 +1,6 @@
1
+ import { useRef } from "react";
2
+ export function useLatest(value) {
3
+ const ref = useRef(value);
4
+ ref.current = value;
5
+ return ref;
6
+ }
@@ -0,0 +1,29 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { isFunction, isPromiseLike } from "src/utils";
3
+ import { useLatest } from "./useLatest";
4
+ /**
5
+ * 在组件初始化时执行的 Hook
6
+ * - 即使在严格模式下也只执行一次
7
+ * @reference https://ahooks.js.org/hooks/use-mount
8
+ *
9
+ * @param {MountCallback} effect 副作用函数
10
+ */
11
+ export function useMount(effect) {
12
+ if (!isFunction(effect)) {
13
+ console.error(`useMount expected parameter is a function, but got ${typeof effect}`);
14
+ }
15
+ const isMountedRef = useRef(false);
16
+ const effectRef = useLatest(effect);
17
+ useEffect(() => {
18
+ if (isMountedRef.current) {
19
+ return;
20
+ }
21
+ isMountedRef.current = true;
22
+ const result = effectRef.current?.();
23
+ // If fn returns a Promise, don't return it as cleanup function
24
+ if (isPromiseLike(result)) {
25
+ return;
26
+ }
27
+ return result;
28
+ }, []);
29
+ }
@@ -0,0 +1,59 @@
1
+ import { useEffect, useState } from "react";
2
+ import { BREAK_POINT_TOKENS } from "src/enums";
3
+ import { objectKeys } from "src/utils";
4
+ const subscriberList = new Set();
5
+ const { XS, SM, MD, LG, XL, XXL } = BREAK_POINT_TOKENS;
6
+ const defaultResponsiveValues = { xxl: false, xl: false, lg: false, md: false, sm: false, xs: false };
7
+ const responsiveConfig = Object.freeze({ xs: XS, sm: SM, md: MD, lg: LG, xl: XL, xxl: XXL });
8
+ let responsiveValues = { ...defaultResponsiveValues };
9
+ export function useResponsive(options) {
10
+ const { compactBreakPoint = "xl" } = options || {};
11
+ calculate();
12
+ const [responsive, setResponsive] = useState(responsiveValues);
13
+ const isCompact = !responsive[compactBreakPoint];
14
+ const current = objectKeys(defaultResponsiveValues).find((key) => responsive[key] === true) || "xs";
15
+ useEffect(() => {
16
+ addListener();
17
+ const subscriber = () => {
18
+ setResponsive(responsiveValues);
19
+ };
20
+ subscriberList.add(subscriber);
21
+ return () => {
22
+ subscriberList.delete(subscriber);
23
+ if (subscriberList.size === 0) {
24
+ removeListener();
25
+ }
26
+ };
27
+ }, []);
28
+ return { responsive, current, isCompact };
29
+ }
30
+ function resizeListener() {
31
+ const oldInfo = responsiveValues;
32
+ calculate();
33
+ if (oldInfo === responsiveValues) {
34
+ return;
35
+ }
36
+ for (const subscriber of subscriberList) {
37
+ subscriber();
38
+ }
39
+ }
40
+ function addListener() {
41
+ window.addEventListener("resize", resizeListener);
42
+ }
43
+ function removeListener() {
44
+ window.removeEventListener("resize", resizeListener);
45
+ }
46
+ function calculate() {
47
+ const width = window.innerWidth;
48
+ const newValues = { ...defaultResponsiveValues };
49
+ let shouldUpdate = false;
50
+ for (const key of objectKeys(responsiveConfig)) {
51
+ newValues[key] = width >= responsiveConfig[key];
52
+ if (newValues[key] !== responsiveValues[key]) {
53
+ shouldUpdate = true;
54
+ }
55
+ }
56
+ if (shouldUpdate) {
57
+ responsiveValues = newValues;
58
+ }
59
+ }
@@ -0,0 +1,17 @@
1
+ import { useEffect } from "react";
2
+ import { isFunction } from "src/utils";
3
+ import { useLatest } from "./useLatest";
4
+ /**
5
+ * 在组件卸载时执行的 Hook
6
+ *
7
+ * @param {Func} effect 副作用函数
8
+ */
9
+ export function useUnmount(effect) {
10
+ if (!isFunction(effect)) {
11
+ console.error(`useUnmount expected parameter is a function, got ${typeof effect}`);
12
+ }
13
+ const effectRef = useLatest(effect);
14
+ useEffect(() => () => {
15
+ effectRef.current?.();
16
+ }, []);
17
+ }
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./enums";
2
+ export * from "./utils";
@@ -0,0 +1,20 @@
1
+ /** 屏幕响应断点 token 配置 */
2
+ export declare const BREAK_POINT_TOKENS: {
3
+ readonly XS: 576;
4
+ readonly XSMin: 576;
5
+ readonly XSMax: 767;
6
+ readonly SM: 768;
7
+ readonly SMMin: 768;
8
+ readonly SMMax: 991;
9
+ readonly MD: 992;
10
+ readonly MDMin: 992;
11
+ readonly MDMax: 1199;
12
+ readonly LG: 1200;
13
+ readonly LGMin: 1200;
14
+ readonly LGMax: 1599;
15
+ readonly XL: 1600;
16
+ readonly XLMin: 1600;
17
+ readonly XLMax: 1919;
18
+ readonly XXL: 1920;
19
+ readonly XXLMin: 1920;
20
+ };
@@ -0,0 +1,5 @@
1
+ export * from "./useCreation";
2
+ export * from "./useLatest";
3
+ export * from "./useMount";
4
+ export * from "./useResponsive";
5
+ export * from "./useUnmount";
@@ -0,0 +1,2 @@
1
+ import { type DependencyList } from "react";
2
+ export declare function useCreation<T>(factory: () => T, deps: DependencyList): T;
@@ -0,0 +1 @@
1
+ export declare function useLatest<T>(value: T): import("react").RefObject<T>;
@@ -0,0 +1,11 @@
1
+ import { type EffectCallback } from "react";
2
+ type MountCallback = EffectCallback | AsyncFunc;
3
+ /**
4
+ * 在组件初始化时执行的 Hook
5
+ * - 即使在严格模式下也只执行一次
6
+ * @reference https://ahooks.js.org/hooks/use-mount
7
+ *
8
+ * @param {MountCallback} effect 副作用函数
9
+ */
10
+ export declare function useMount(effect: MountCallback): void;
11
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { Breakpoint } from "@pawover/types";
2
+ type ResponsiveValues = Record<Breakpoint, boolean>;
3
+ interface ResponsiveHookOptions {
4
+ /**
5
+ * 紧凑布局断点
6
+ * - 低于此断点时使用紧凑布局
7
+ * @default "xl"
8
+ */
9
+ compactBreakPoint?: Breakpoint;
10
+ }
11
+ export declare function useResponsive(options?: ResponsiveHookOptions): {
12
+ responsive: ResponsiveValues;
13
+ current: Breakpoint;
14
+ isCompact: boolean;
15
+ };
16
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 在组件卸载时执行的 Hook
3
+ *
4
+ * @param {Func} effect 副作用函数
5
+ */
6
+ export declare function useUnmount(effect: Func): void;
@@ -0,0 +1,2 @@
1
+ export * from "./enums";
2
+ export * from "./utils";
@@ -0,0 +1,76 @@
1
+ export declare function toArray<T>(candidate?: T | T[] | false): T[];
2
+ /**
3
+ * 获取数组第一项
4
+ *
5
+ * @param initialList 初始数组
6
+ * @param saveValue 安全值
7
+ */
8
+ export declare function arrayFirst<T>(initialList: readonly T[], saveValue?: T): T | undefined;
9
+ /**
10
+ * 获取数组最后一项
11
+ *
12
+ * @param initialList 初始数组
13
+ * @param saveValue 安全值
14
+ */
15
+ export declare function arrayLast<T>(initialList: readonly T[], saveValue?: T): T | undefined;
16
+ export declare function arrayDiff<T>(initialList: readonly T[], diffList: readonly T[], match: (row: T) => PropertyKey): T[];
17
+ /**
18
+ * 数组竞争
19
+ * - 返回在匹配函数的比较条件中获胜的最终项目,适用于更复杂的最小值/最大值计算
20
+ *
21
+ * @param initialList 数组
22
+ * @param match 匹配函数
23
+ */
24
+ export declare function arrayCompete<T>(initialList: readonly T[], match: (a: T, b: T) => T): T | null;
25
+ /**
26
+ * 统计数组的项目出现次数
27
+ * - 通过给定的标识符匹配函数,返回一个对象,其中键是回调函数返回的 key 值,每个值是一个整数,表示该 key 出现的次数
28
+ *
29
+ * @param initialList 初始数组
30
+ * @param match 标识符匹配函数
31
+ */
32
+ export declare function arrayCounting<T, K extends PropertyKey>(initialList: readonly T[], match: (row: T) => K): Record<string, number>;
33
+ /**
34
+ * 数组项替换
35
+ * - 在给定的数组中,替换符合匹配函数结果的项目。只替换第一个匹配项。始终返回原始数组的副本。
36
+ *
37
+ * @param initialList 初始数组
38
+ * @param newItem 替换项
39
+ * @param match 匹配函数
40
+ */
41
+ export declare function arrayReplace<T>(initialList: readonly T[], newItem: T, match: (row: T, index: number) => boolean): T[];
42
+ /**
43
+ * 数组选择
44
+ * - 一次性应用 `filter` 和 `map` 操作
45
+ *
46
+ * @param initialList 初始数组
47
+ * @param filter filter 函数
48
+ * @param mapper map 函数
49
+ */
50
+ export 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[];
51
+ /**
52
+ * 数组切分
53
+ * - 将数组以指定的长度切分后,组合在高维数组中
54
+ *
55
+ * @param initialList 初始数组
56
+ * @param size 分割尺寸,默认 `10`
57
+ */
58
+ export declare function arraySplit<T>(initialList: readonly T[], size?: number): T[][];
59
+ /**
60
+ * 数组迭代
61
+ * - 运行一个函数 n 次以生成一个值,迭代函数将作为还原器运行无数次,然后返回累积值
62
+ *
63
+ * @param count 迭代次数
64
+ * @param iterate 迭代函数
65
+ * @param initialValue 初始值
66
+ */
67
+ export declare function arrayIterate<T>(count: number, iterate: (currentValue: T, iteration: number) => T, initialValue: T): T;
68
+ /**
69
+ * 数组合并
70
+ * - 通过给定的标识符匹配函数,用第二个数组中的匹配项替换第一个数组中匹配项的所有内容
71
+ *
72
+ * @param initialList 初始数组
73
+ * @param mergeList 待合并数组
74
+ * @param match 标识符匹配函数
75
+ */
76
+ export declare function arrayMerge<T>(initialList: readonly T[], mergeList: readonly T[], match: (item: T) => unknown): readonly T[] & unknown[];
@@ -0,0 +1,6 @@
1
+ export * from "./array";
2
+ export * from "./object";
3
+ export * from "./string";
4
+ export * from "./to";
5
+ export * from "./tree";
6
+ export * from "./typeof";
@@ -0,0 +1,53 @@
1
+ import type { NonEmptyObject, UnionToTuple, ValueOf } from "type-fest";
2
+ /**
3
+ * 返回对象的可枚举属性和方法的名称
4
+ * - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型
5
+ *
6
+ * @param obj 对象
7
+ * @returns 对象所有可枚举的属性的键名
8
+ */
9
+ export declare function objectKeys<O extends AnyObject>(obj: O): (keyof O)[];
10
+ /**
11
+ * 返回对象的可枚举属性的值数组
12
+ *
13
+ * @param obj 对象
14
+ */
15
+ export declare function objectValues<O extends AnyObject>(obj: O): UnionToTuple<ValueOf<O>>;
16
+ /**
17
+ * 返回对象的可枚举属性的键/值数组
18
+ *
19
+ * @param obj 对象
20
+ */
21
+ export declare function objectEntries<O extends AnyObject>(obj: O): [string & keyof O, O[keyof O]][];
22
+ /**
23
+ * 对象反转
24
+ * - 返回交换了对象的可枚举属性的值/键对象
25
+ *
26
+ * @param obj 对象
27
+ */
28
+ export declare function objectSwitch<O extends AnyObject>(obj: NonEmptyObject<O>): Record<O[keyof O], keyof O>;
29
+ /**
30
+ * 对象合并
31
+ * - 将两个对象递归合并为一个新对象,从右到左依次使用数值
32
+ * - 递归只适用于子对象属性
33
+ */
34
+ export declare function objectAssign<O extends AnyObject>(obj: O, overrideObj: O): O;
35
+ export declare function objectPick<O extends AnyObject, K extends keyof O>(obj: O, keys: readonly K[]): Pick<O, K>;
36
+ /**
37
+ * 获取枚举所有属性的键
38
+ *
39
+ * @param enumeration 枚举
40
+ */
41
+ export declare function enumKeys<E extends AnyObject>(enumeration: NonEmptyObject<E>): [keyof E, ...(keyof E)[]];
42
+ /**
43
+ * 获取枚举所有属性的值
44
+ *
45
+ * @param enumeration 枚举
46
+ */
47
+ export declare function enumValues<E extends AnyObject>(enumeration: NonEmptyObject<E>): UnionToTuple<ValueOf<E>>;
48
+ /**
49
+ * 返回枚举的属性的键/值数组
50
+ *
51
+ * @param enumeration 枚举
52
+ */
53
+ export declare function enumEntries<E extends AnyObject>(enumeration: NonEmptyObject<E>): [keyof E, E[keyof E]][];
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 转义特殊字符
3
+ *
4
+ * @link https://github.com/sindresorhus/escape-string-regexp
5
+ * @param value 字符串
6
+ */
7
+ export declare function escapeStringRegexp(value: string): string;
8
+ /**
9
+ * 首字母大小写
10
+ */
11
+ export declare function stringInitialCase(value: string, type: "lower" | "upper"): string;
12
+ export declare function stringToJson<R extends AnyObject = AnyObject, D extends R = R>(data: string | null | undefined, safeValue: D): R;
13
+ export declare function stringToValues<T extends number | string = number>(data: string | null | undefined, valueType?: "number" | "string"): T[];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @param promise
3
+ * @param errorExt - 可以传递给err对象的其他信息
4
+ */
5
+ export declare function to<T, U = Error>(promise: Readonly<Promise<T>>, errorExt?: UnknownObject): Promise<[U, undefined] | [null, T]>;
@@ -0,0 +1,6 @@
1
+ export { treeFilter } from "./treeFilter";
2
+ export { treeFind } from "./treeFind";
3
+ export { treeForEach } from "./treeForEach";
4
+ export { treeMap } from "./treeMap";
5
+ export { rowsToTree } from "./rowsToTree";
6
+ export { treeToRows } from "./treeToRows";
@@ -0,0 +1,10 @@
1
+ import type { ChildrenKey, ParentIdKey, RowKey } from "./types";
2
+ export interface RowsToTreeOptions<RK extends string = RowKey, PK extends string = ParentIdKey, CK extends string = ChildrenKey> {
3
+ rowKey?: RK;
4
+ parentIdKey?: PK;
5
+ childrenKey?: CK;
6
+ }
7
+ /**
8
+ * 行结构 转 树结构
9
+ */
10
+ export 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[];
@@ -0,0 +1,6 @@
1
+ import { type BaseCallbackMeta, type BaseInnerOptions, type BaseOptions, type ChildrenKey } from "./types";
2
+ export type TreeFilterOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
3
+ export type TreeFilterInnerOption<T extends AnyObject, CK extends string = ChildrenKey> = BaseInnerOptions<T, CK>;
4
+ export type TreeFilterCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => boolean;
5
+ export declare function treeFilter<T extends AnyObject, CK extends string = ChildrenKey>(tree: T[], callback: TreeFilterCallback<T>, options?: TreeFilterOptions<T, CK>): T[];
6
+ export declare function treeFilter<T extends AnyObject, CK extends string = ChildrenKey>(tree: T, callback: TreeFilterCallback<T>, options?: TreeFilterOptions<T, CK>): T;
@@ -0,0 +1,8 @@
1
+ import { type BaseCallbackMeta, type BaseInnerOptions, type BaseOptions, type ChildrenKey } from "./types";
2
+ export type TreeFindOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
3
+ export type TreeFindInnerOption<T extends AnyObject, CK extends string = ChildrenKey> = BaseInnerOptions<T, CK>;
4
+ export type TreeFindCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => boolean;
5
+ /**
6
+ * 查找树节点,找到第一个返回非空值的节点
7
+ */
8
+ export declare function treeFind<T extends AnyObject, CK extends string = ChildrenKey>(tree: T | T[], callback: TreeFindCallback<T>, options?: TreeFindOptions<T, CK>): T | undefined;
@@ -0,0 +1,5 @@
1
+ import { type BaseCallbackMeta, type BaseInnerOptions, type BaseOptions, type ChildrenKey } from "./types";
2
+ export type TreeForeachOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
3
+ export type TreeForeachInnerOption<T extends AnyObject, CK extends string = ChildrenKey> = BaseInnerOptions<T, CK>;
4
+ export type TreeForeachCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => void;
5
+ export declare function treeForEach<T extends AnyObject, CK extends string = ChildrenKey>(tree: T | T[], callback: TreeForeachCallback<T>, options?: TreeForeachOptions<T, CK>): void;
@@ -0,0 +1,6 @@
1
+ import { type BaseCallbackMeta, type BaseInnerOptions, type BaseOptions, type ChildrenKey } from "./types";
2
+ export type TreeMapOptions<T extends AnyObject, CK extends string> = BaseOptions<T, CK>;
3
+ export type TreeMapInnerOption<T extends AnyObject, CK extends string> = BaseInnerOptions<T, CK>;
4
+ export type TreeMapCallback<R extends AnyObject, T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => R;
5
+ export 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>[];
6
+ export 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>;
@@ -0,0 +1,9 @@
1
+ import type { SetOptional } from "type-fest";
2
+ import { type TreeForeachOptions } from "./treeForEach";
3
+ import type { ChildrenKey } from "./types";
4
+ type TreeToRowsOptions<T extends AnyObject, CK extends string = ChildrenKey> = TreeForeachOptions<T, CK>;
5
+ /**
6
+ * 树结构 转 行结构
7
+ */
8
+ export declare function treeToRows<T extends AnyObject, CK extends string = ChildrenKey, R extends AnyObject = SetOptional<T, CK>>(tree: T | T[], options?: TreeToRowsOptions<T, CK>): R[];
9
+ export {};
@@ -0,0 +1,24 @@
1
+ export type RowKey = "id";
2
+ export type ParentIdKey = "parentId";
3
+ export type ChildrenKey = "children";
4
+ export type Strategy = "pre" | "post" | "breadth";
5
+ export interface BaseCallbackMeta<T> {
6
+ depth: number;
7
+ parents?: T[];
8
+ }
9
+ export interface BaseOptions<T, CK extends string> {
10
+ childrenKey?: CK;
11
+ strategy?: Strategy;
12
+ getChildrenKey?: (row: T, meta: BaseCallbackMeta<T>) => CK | undefined;
13
+ }
14
+ export interface BaseInnerOptions<T, CK extends string> {
15
+ childrenKey: CK;
16
+ parents: T[];
17
+ depth: number;
18
+ getChildrenKey?: (row: T, meta: BaseCallbackMeta<T>) => CK | undefined;
19
+ }
20
+ export interface QueueItem<T, CK extends string> {
21
+ queueRow: T;
22
+ queueOptions: BaseInnerOptions<T, CK>;
23
+ }
24
+ export declare function getFinalChildrenKey<T, CK extends string>(tree: T, meta: BaseCallbackMeta<T>, options: BaseInnerOptions<T, CK>): CK;
@@ -0,0 +1,29 @@
1
+ import type { Class } from "type-fest";
2
+ export declare function isString<T extends string>(value: unknown): value is T;
3
+ export declare function isNumber<T extends number>(value: unknown): value is T;
4
+ export declare function isBoolean<T extends boolean>(value: unknown): value is T;
5
+ export declare function isObject<T extends Record<PropertyKey, unknown>>(value: unknown): value is T;
6
+ export declare function isArray<T extends unknown[]>(value: unknown): value is T;
7
+ export declare function isBigInt<T extends bigint>(value: unknown): value is T;
8
+ export declare function isSymbol<T extends symbol>(value: unknown): value is T;
9
+ export declare function isFunction<T extends Func>(value: unknown): value is T;
10
+ export declare function isGeneratorFunction<T extends Func>(value: unknown): value is T;
11
+ export declare function isAsyncFunction<T extends AsyncFunc>(value: unknown): value is T;
12
+ export declare function isPromise<T extends Promise<unknown>>(value: unknown): value is T;
13
+ export declare function isPromiseLike<T extends PromiseLike<unknown>>(value: unknown): value is T;
14
+ export declare function isNull<T extends null>(value: unknown): value is T;
15
+ export declare function isUndefined<T extends undefined>(value: unknown): value is T;
16
+ export declare function isDate<T extends Date>(value: unknown): value is T;
17
+ export declare function isRegExp<T extends RegExp>(value: unknown): value is T;
18
+ export declare function isError<T extends Error>(value: unknown): value is T;
19
+ export declare function isFile<T extends File>(value: unknown): value is T;
20
+ export declare function isMap<T extends Map<unknown, unknown>>(value: unknown): value is T;
21
+ export declare function isWeakMap<T extends WeakMap<AnyObject, unknown>>(value: unknown): value is T;
22
+ export declare function isSet<T extends Set<unknown>>(value: unknown): value is T;
23
+ export declare function isWeakSet<T extends WeakSet<AnyObject>>(value: unknown): value is T;
24
+ export declare function isWindow<T extends Window>(value: unknown): value is T;
25
+ export declare function isWebSocket<T extends WebSocket>(value: unknown): value is T;
26
+ export declare function isURLSearchParams<T extends Window>(value: unknown): value is T;
27
+ export declare function isClass<T extends Class<AnyObject>>(value: unknown): value is T;
28
+ export declare function isInteger<T extends number>(value: unknown): value is T;
29
+ export declare function isIterable<T extends Iterable<unknown>>(value: unknown): value is T;