@vef-framework/shared 2.0.11 → 2.1.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/dist/cjs/_internal/_rolldown/runtime.cjs +1 -0
- package/dist/cjs/color/color-ops.cjs +1 -1
- package/dist/cjs/color/index.cjs +1 -1
- package/dist/cjs/color/name.cjs +1 -1
- package/dist/cjs/color/palette.cjs +1 -1
- package/dist/cjs/constants/color-names.cjs +1 -1
- package/dist/cjs/constants/color-palettes.cjs +1 -1
- package/dist/cjs/constants/index.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/types/color.cjs +0 -1
- package/dist/cjs/types/common.cjs +0 -1
- package/dist/cjs/types/deep-keys.cjs +0 -1
- package/dist/cjs/types/index.cjs +0 -1
- package/dist/cjs/utils/chrono.cjs +1 -1
- package/dist/cjs/utils/equal.cjs +1 -1
- package/dist/cjs/utils/error.cjs +2 -3
- package/dist/cjs/utils/event.cjs +1 -1
- package/dist/cjs/utils/format.cjs +1 -1
- package/dist/cjs/utils/function.cjs +1 -1
- package/dist/cjs/utils/id.cjs +1 -1
- package/dist/cjs/utils/index.cjs +1 -1
- package/dist/cjs/utils/key.cjs +1 -1
- package/dist/cjs/utils/lib.cjs +1 -1
- package/dist/cjs/utils/object.cjs +1 -1
- package/dist/cjs/utils/path.cjs +1 -1
- package/dist/cjs/utils/pinyin.cjs +1 -1
- package/dist/cjs/utils/security.cjs +1 -1
- package/dist/cjs/utils/string.cjs +1 -1
- package/dist/cjs/utils/table.cjs +1 -1
- package/dist/cjs/utils/task.cjs +1 -1
- package/dist/cjs/utils/tree.cjs +1 -1
- package/dist/cjs/utils/zod.cjs +1 -1
- package/dist/es/color/color-ops.js +55 -68
- package/dist/es/color/index.js +4 -18
- package/dist/es/color/name.js +25 -27
- package/dist/es/color/palette.js +70 -82
- package/dist/es/constants/color-names.js +1572 -1572
- package/dist/es/constants/color-palettes.js +1085 -360
- package/dist/es/constants/index.js +3 -8
- package/dist/es/index.js +25 -167
- package/dist/es/types/color.js +1 -1
- package/dist/es/types/common.js +1 -1
- package/dist/es/types/deep-keys.js +1 -1
- package/dist/es/types/index.js +1 -3
- package/dist/es/utils/chrono.js +77 -92
- package/dist/es/utils/equal.js +83 -118
- package/dist/es/utils/error.js +27 -29
- package/dist/es/utils/event.js +27 -51
- package/dist/es/utils/format.js +27 -18
- package/dist/es/utils/function.js +26 -36
- package/dist/es/utils/id.js +21 -21
- package/dist/es/utils/index.js +18 -81
- package/dist/es/utils/key.js +17 -23
- package/dist/es/utils/lib.js +8 -64
- package/dist/es/utils/object.js +12 -12
- package/dist/es/utils/path.js +37 -58
- package/dist/es/utils/pinyin.js +41 -43
- package/dist/es/utils/security.js +73 -31
- package/dist/es/utils/string.js +19 -7
- package/dist/es/utils/table.js +13 -13
- package/dist/es/utils/task.js +6 -7
- package/dist/es/utils/tree.js +159 -181
- package/dist/es/utils/zod.js +7 -7
- package/dist/types/constants/color-names.d.ts +2 -2
- package/dist/types/constants/color-palettes.d.ts +2 -2
- package/dist/types/src/color/color-ops.d.ts +84 -0
- package/dist/types/src/color/index.d.ts +3 -0
- package/dist/types/src/color/name.d.ts +7 -0
- package/dist/types/src/color/palette.d.ts +8 -0
- package/dist/types/src/constants/color-names.d.ts +11 -0
- package/dist/types/src/constants/color-palettes.d.ts +823 -0
- package/dist/types/src/constants/index.d.ts +2 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/types/color.d.ts +25 -0
- package/dist/types/src/types/common.d.ts +29 -0
- package/dist/types/src/types/deep-keys.d.ts +37 -0
- package/dist/types/src/types/index.d.ts +3 -0
- package/dist/types/src/utils/chrono.d.ts +152 -0
- package/dist/types/src/utils/equal.d.ts +16 -0
- package/dist/types/src/utils/error.d.ts +22 -0
- package/dist/types/src/utils/event.d.ts +46 -0
- package/dist/types/src/utils/format.d.ts +31 -0
- package/dist/types/src/utils/function.d.ts +27 -0
- package/dist/types/src/utils/id.d.ts +6 -0
- package/dist/types/src/utils/index.d.ts +18 -0
- package/dist/types/src/utils/key.d.ts +5 -0
- package/dist/types/src/utils/lib.d.ts +5 -0
- package/dist/types/src/utils/object.d.ts +9 -0
- package/dist/types/src/utils/path.d.ts +13 -0
- package/dist/types/src/utils/pinyin.d.ts +40 -0
- package/dist/types/src/utils/security.d.ts +60 -0
- package/dist/types/src/utils/string.d.ts +15 -0
- package/dist/types/src/utils/table.d.ts +25 -0
- package/dist/types/src/utils/task.d.ts +4 -0
- package/dist/types/src/utils/tree.d.ts +216 -0
- package/dist/types/src/utils/zod.d.ts +2 -0
- package/dist/types/types/color.d.ts +1 -49
- package/dist/types/types/common.d.ts +7 -3
- package/dist/types/types/deep-keys.d.ts +28 -0
- package/dist/types/utils/chrono.d.ts +3 -13
- package/dist/types/utils/error.d.ts +5 -21
- package/dist/types/utils/event.d.ts +9 -31
- package/dist/types/utils/format.d.ts +0 -2
- package/dist/types/utils/function.d.ts +4 -36
- package/dist/types/utils/id.d.ts +2 -2
- package/dist/types/utils/key.d.ts +2 -4
- package/dist/types/utils/path.d.ts +7 -70
- package/dist/types/utils/pinyin.d.ts +2 -3
- package/dist/types/utils/security.d.ts +44 -2
- package/dist/types/utils/string.d.ts +8 -0
- package/dist/types/utils/table.d.ts +1 -0
- package/dist/types/utils/task.d.ts +1 -3
- package/dist/types/utils/tree.d.ts +8 -0
- package/dist/types/utils/zod.d.ts +1 -0
- package/package.json +13 -13
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { AnyObject, Except, MaybeUndefined, SetRequired } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Options for flattening tree data
|
|
4
|
+
*/
|
|
5
|
+
export interface FlattenTreeOptions<TNode extends AnyObject = AnyObject, TTransformedNode = FlattenedNode<TNode>> {
|
|
6
|
+
/**
|
|
7
|
+
* The key name for children property
|
|
8
|
+
*
|
|
9
|
+
* @default 'children'
|
|
10
|
+
*/
|
|
11
|
+
childrenKey?: keyof TNode;
|
|
12
|
+
/**
|
|
13
|
+
* Whether to include parent node reference
|
|
14
|
+
*
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
includeParent?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to include level information
|
|
20
|
+
*
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
includeLevel?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Transform function to convert or filter nodes during flattening
|
|
26
|
+
*/
|
|
27
|
+
transform?: (node: TNode, context: {
|
|
28
|
+
parent?: TNode;
|
|
29
|
+
level: number;
|
|
30
|
+
}) => TTransformedNode;
|
|
31
|
+
/**
|
|
32
|
+
* Filter function to skip nodes (will still traverse children)
|
|
33
|
+
*/
|
|
34
|
+
filter?: (node: TNode, context: {
|
|
35
|
+
parent?: TNode;
|
|
36
|
+
level: number;
|
|
37
|
+
}) => boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Flattened node data (used when transform is not provided)
|
|
41
|
+
*/
|
|
42
|
+
export interface FlattenedNode<TNode extends AnyObject = AnyObject> {
|
|
43
|
+
/**
|
|
44
|
+
* Original node data
|
|
45
|
+
*/
|
|
46
|
+
data: TNode;
|
|
47
|
+
/**
|
|
48
|
+
* Parent node (only exists when includeParent is true)
|
|
49
|
+
*/
|
|
50
|
+
parent?: TNode;
|
|
51
|
+
/**
|
|
52
|
+
* Level depth, starting from 0 (only exists when includeLevel is true)
|
|
53
|
+
*/
|
|
54
|
+
level?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Flatten tree data into a one-dimensional array
|
|
58
|
+
*
|
|
59
|
+
* @param tree - Tree data array
|
|
60
|
+
* @param options - Configuration options
|
|
61
|
+
* @returns Flattened array
|
|
62
|
+
*/
|
|
63
|
+
export declare function flattenTree<TNode extends AnyObject = AnyObject, TTransformedNode = FlattenedNode<NoInfer<TNode>>>(tree: TNode[], options: SetRequired<FlattenTreeOptions<NoInfer<TNode>, TTransformedNode>, "includeParent"> | SetRequired<FlattenTreeOptions<NoInfer<TNode>, TTransformedNode>, "includeLevel">): Array<NoInfer<TTransformedNode>>;
|
|
64
|
+
/**
|
|
65
|
+
* Flatten tree data into a one-dimensional array
|
|
66
|
+
*
|
|
67
|
+
* @param tree - Tree data array
|
|
68
|
+
* @param options - Configuration options
|
|
69
|
+
* @returns Flattened array
|
|
70
|
+
*/
|
|
71
|
+
export declare function flattenTree<TNode extends AnyObject = AnyObject, TTransformedNode = NoInfer<TNode>>(tree: TNode[], options?: Except<FlattenTreeOptions<NoInfer<TNode>, TTransformedNode>, "includeParent" | "includeLevel">): Array<NoInfer<TTransformedNode>>;
|
|
72
|
+
/**
|
|
73
|
+
* Key accessor - can be a property name or a getter function
|
|
74
|
+
*/
|
|
75
|
+
export type KeyAccessor<T extends AnyObject> = keyof T | ((node: T) => unknown);
|
|
76
|
+
/**
|
|
77
|
+
* Options for building tree from flat array
|
|
78
|
+
*/
|
|
79
|
+
export interface BuildTreeOptions<TNode extends AnyObject = AnyObject, TTransformedNode extends AnyObject = TNode, TChildrenKey extends string = "children"> {
|
|
80
|
+
/**
|
|
81
|
+
* Accessor for node id
|
|
82
|
+
* Can be a property name or a getter function
|
|
83
|
+
*
|
|
84
|
+
* @default 'id'
|
|
85
|
+
*/
|
|
86
|
+
idKey?: KeyAccessor<TNode>;
|
|
87
|
+
/**
|
|
88
|
+
* Accessor for parent id
|
|
89
|
+
* Can be a property name or a getter function
|
|
90
|
+
*
|
|
91
|
+
* @default 'parentId'
|
|
92
|
+
*/
|
|
93
|
+
parentIdKey?: KeyAccessor<TNode>;
|
|
94
|
+
/**
|
|
95
|
+
* The key name for children property
|
|
96
|
+
*
|
|
97
|
+
* @default 'children'
|
|
98
|
+
*/
|
|
99
|
+
childrenKey?: TChildrenKey;
|
|
100
|
+
/**
|
|
101
|
+
* Root node condition
|
|
102
|
+
* Can be a value to match against parentId, or a function to determine if a node is root
|
|
103
|
+
*/
|
|
104
|
+
rootValue?: TNode[keyof TNode] | ((node: TNode) => boolean);
|
|
105
|
+
/**
|
|
106
|
+
* Transform function to convert nodes during building
|
|
107
|
+
*/
|
|
108
|
+
transform?: (node: TNode, context: {
|
|
109
|
+
children?: TNode[];
|
|
110
|
+
level: number;
|
|
111
|
+
}) => TTransformedNode;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Result node type for buildTree
|
|
115
|
+
*/
|
|
116
|
+
export type BuildTreeResultNode<TNode extends AnyObject, TChildrenKey extends string> = TNode & {
|
|
117
|
+
[Key in TChildrenKey]?: Array<BuildTreeResultNode<TNode, TChildrenKey>>;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Build tree structure from flat array
|
|
121
|
+
*
|
|
122
|
+
* @param nodes - Flat array of items
|
|
123
|
+
* @param options - Configuration options
|
|
124
|
+
* @returns Tree structure array
|
|
125
|
+
*/
|
|
126
|
+
export declare function buildTree<TNode extends AnyObject = AnyObject, TTransformedNode extends AnyObject = NoInfer<TNode>, const TChildrenKey extends string = "children">(nodes: TNode[], options?: BuildTreeOptions<NoInfer<TNode>, TTransformedNode, TChildrenKey>): Array<BuildTreeResultNode<TTransformedNode, TChildrenKey>>;
|
|
127
|
+
/**
|
|
128
|
+
* Find a node in tree data
|
|
129
|
+
*
|
|
130
|
+
* @param tree - Tree data array
|
|
131
|
+
* @param predicate - Predicate function to find the node
|
|
132
|
+
* @param childrenKey - The key name for children property
|
|
133
|
+
* @returns Found node, or undefined if not found
|
|
134
|
+
*/
|
|
135
|
+
export declare function findNodeInTree<TNode extends AnyObject = AnyObject>(tree: TNode[], predicate: (node: NoInfer<TNode>, context: {
|
|
136
|
+
parent?: NoInfer<TNode>;
|
|
137
|
+
level: number;
|
|
138
|
+
}) => boolean, childrenKey?: keyof NoInfer<TNode>): MaybeUndefined<NoInfer<TNode>>;
|
|
139
|
+
/**
|
|
140
|
+
* Options for traversing tree data
|
|
141
|
+
*/
|
|
142
|
+
export interface TraverseTreeOptions<TNode extends AnyObject> {
|
|
143
|
+
/**
|
|
144
|
+
* Traversal strategy
|
|
145
|
+
* - 'dfs': Depth-First Search - visit nodes depth-wise (parent -> children -> siblings)
|
|
146
|
+
* - 'bfs': Breadth-First Search - visit nodes level-wise (all nodes at level N before level N+1)
|
|
147
|
+
*
|
|
148
|
+
* @default 'dfs'
|
|
149
|
+
*/
|
|
150
|
+
strategy?: "dfs" | "bfs";
|
|
151
|
+
/**
|
|
152
|
+
* The key name for children property
|
|
153
|
+
*
|
|
154
|
+
* @default 'children'
|
|
155
|
+
*/
|
|
156
|
+
childrenKey?: keyof TNode;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Traverse tree data with depth-first or breadth-first strategy
|
|
160
|
+
*
|
|
161
|
+
* @param tree - Tree data array
|
|
162
|
+
* @param callback - Callback function for each node
|
|
163
|
+
* @param options - Traversal options or children key string (for backward compatibility)
|
|
164
|
+
*/
|
|
165
|
+
export declare function traverseTree<TNode extends AnyObject = AnyObject>(tree: TNode[], callback: (node: NoInfer<TNode>, context: {
|
|
166
|
+
parent?: NoInfer<TNode>;
|
|
167
|
+
level: number;
|
|
168
|
+
index: number;
|
|
169
|
+
}) => void, options?: TraverseTreeOptions<NoInfer<TNode>>): void;
|
|
170
|
+
/**
|
|
171
|
+
* Map tree data
|
|
172
|
+
*
|
|
173
|
+
* @param tree - Tree data array
|
|
174
|
+
* @param callback - Mapping callback function
|
|
175
|
+
* @param childrenKey - The key name for children property
|
|
176
|
+
* @returns Mapped tree data
|
|
177
|
+
*/
|
|
178
|
+
export declare function mapTree<TNode extends AnyObject = AnyObject, TMappedNode extends AnyObject = AnyObject>(tree: TNode[], callback: (node: NoInfer<TNode>, context: {
|
|
179
|
+
parent?: NoInfer<TNode>;
|
|
180
|
+
level: number;
|
|
181
|
+
index: number;
|
|
182
|
+
}) => TMappedNode, childrenKey?: keyof NoInfer<TNode>): Array<NoInfer<TMappedNode>>;
|
|
183
|
+
/**
|
|
184
|
+
* Filter tree data
|
|
185
|
+
*
|
|
186
|
+
* @param tree - Tree data array
|
|
187
|
+
* @param predicate - Filter predicate function
|
|
188
|
+
* @param childrenKey - The key name for children property
|
|
189
|
+
* @returns Filtered tree data
|
|
190
|
+
*/
|
|
191
|
+
export declare function filterTree<TNode extends AnyObject = AnyObject>(tree: TNode[], predicate: (node: NoInfer<TNode>, context: {
|
|
192
|
+
parent?: NoInfer<TNode>;
|
|
193
|
+
level: number;
|
|
194
|
+
index: number;
|
|
195
|
+
}) => boolean, childrenKey?: keyof NoInfer<TNode>): Array<NoInfer<TNode>>;
|
|
196
|
+
/**
|
|
197
|
+
* Filter tree data while preserving ancestor nodes
|
|
198
|
+
*
|
|
199
|
+
* Unlike filterTree, this function keeps all ancestor nodes of matching nodes,
|
|
200
|
+
* even if the ancestors themselves don't match the predicate.
|
|
201
|
+
* This is useful for search/filter scenarios where you want to show the full path to matching nodes.
|
|
202
|
+
*
|
|
203
|
+
* Key behavior:
|
|
204
|
+
* - Non-matching nodes are kept only if they have matching descendants
|
|
205
|
+
* - If a matching node has no matching children, its children are removed
|
|
206
|
+
*
|
|
207
|
+
* @param tree - Tree data array
|
|
208
|
+
* @param predicate - Filter predicate function
|
|
209
|
+
* @param childrenKey - The key name for children property
|
|
210
|
+
* @returns Filtered tree data with preserved ancestor paths
|
|
211
|
+
*/
|
|
212
|
+
export declare function filterTreeWithAncestors<TNode extends AnyObject = AnyObject>(tree: TNode[], predicate: (node: NoInfer<TNode>, context: {
|
|
213
|
+
parent?: NoInfer<TNode>;
|
|
214
|
+
level: number;
|
|
215
|
+
index: number;
|
|
216
|
+
}) => boolean, childrenKey?: keyof NoInfer<TNode>): Array<NoInfer<TNode>>;
|
|
@@ -1,73 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The color entry
|
|
3
|
-
*/
|
|
4
1
|
export type ColorEntry = [hex: string, name: string];
|
|
5
|
-
/**
|
|
6
|
-
* The color number
|
|
7
|
-
*/
|
|
8
2
|
export type ColorNumber = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
|
|
9
|
-
/**
|
|
10
|
-
* The color swatch
|
|
11
|
-
*/
|
|
12
3
|
export interface ColorSwatch {
|
|
13
|
-
/**
|
|
14
|
-
* The color number
|
|
15
|
-
*/
|
|
16
4
|
number: ColorNumber;
|
|
17
|
-
/**
|
|
18
|
-
* The color hex code
|
|
19
|
-
*/
|
|
20
5
|
hex: string;
|
|
21
6
|
}
|
|
22
|
-
/**
|
|
23
|
-
* The color palette
|
|
24
|
-
*/
|
|
25
7
|
export interface ColorPalette {
|
|
26
|
-
/**
|
|
27
|
-
* The color name
|
|
28
|
-
*/
|
|
29
8
|
name: string;
|
|
30
|
-
/**
|
|
31
|
-
* The color swatches
|
|
32
|
-
*/
|
|
33
9
|
swatches: ColorSwatch[];
|
|
34
10
|
}
|
|
35
|
-
/**
|
|
36
|
-
* The color swatch with delta
|
|
37
|
-
*/
|
|
38
11
|
export interface ColorSwatchWithDelta extends ColorSwatch {
|
|
39
|
-
/**
|
|
40
|
-
* The color delta
|
|
41
|
-
*/
|
|
42
12
|
delta: number;
|
|
43
13
|
}
|
|
44
|
-
/**
|
|
45
|
-
* The nearest color palette
|
|
46
|
-
*/
|
|
47
14
|
export interface NearestColorPalette extends ColorPalette {
|
|
48
|
-
/**
|
|
49
|
-
* The nearest swatch
|
|
50
|
-
*/
|
|
51
15
|
nearestSwatch: ColorSwatchWithDelta;
|
|
52
|
-
/**
|
|
53
|
-
* The nearest lightness swatch
|
|
54
|
-
*/
|
|
55
16
|
nearestLightnessSwatch: ColorSwatchWithDelta;
|
|
56
17
|
}
|
|
57
|
-
/**
|
|
58
|
-
* The matched color palette
|
|
59
|
-
*/
|
|
60
18
|
export interface MatchedColorPalette extends ColorPalette {
|
|
61
|
-
/**
|
|
62
|
-
* The color map of the palette
|
|
63
|
-
*/
|
|
64
19
|
colorMap: Map<ColorNumber, string>;
|
|
65
20
|
/**
|
|
66
|
-
* The main color swatch
|
|
21
|
+
* The main color swatch with number 500
|
|
67
22
|
*/
|
|
68
23
|
main: ColorSwatch;
|
|
69
|
-
/**
|
|
70
|
-
* The matched color swatch of the palette
|
|
71
|
-
*/
|
|
72
24
|
matched: ColorSwatch;
|
|
73
25
|
}
|
|
@@ -6,9 +6,13 @@ export type MaybeArray<T> = T | T[];
|
|
|
6
6
|
export type MaybeNullish<T> = T | null | undefined;
|
|
7
7
|
export type MaybeUndefined<T> = T | undefined;
|
|
8
8
|
export type MaybeNull<T> = T | null;
|
|
9
|
-
export type Expand<T> = T extends T ? T : never;
|
|
10
|
-
export type Not<A extends boolean> = A extends true ? false : A extends false ? true : never;
|
|
11
9
|
export type IsString<T> = T extends string ? true : false;
|
|
10
|
+
/**
|
|
11
|
+
* Inverts a boolean type.
|
|
12
|
+
*
|
|
13
|
+
* @example Not<true> = false, Not<false> = true
|
|
14
|
+
*/
|
|
15
|
+
export type Not<A extends boolean> = A extends true ? false : A extends false ? true : never;
|
|
12
16
|
export interface EmptyObject {
|
|
13
17
|
}
|
|
14
18
|
export type AnyObject = Record<keyof any, any>;
|
|
@@ -22,4 +26,4 @@ export type NonFunctionGuard<T> = T extends Function ? never : T;
|
|
|
22
26
|
export type OmitSymbol<T> = {
|
|
23
27
|
[K in keyof T as K extends symbol ? never : K]: T[K];
|
|
24
28
|
};
|
|
25
|
-
export type { And, Except, HasOptionalKeys, HasRequiredKeys, If, IsAny, IsBooleanLiteral, IsEqual, IsFloat, IsInteger, IsLiteral, IsNever, IsNull, IsNullable, IsNumericLiteral, IsOptional, IsOptionalKeyOf, IsReadonlyKeyOf, IsRequiredKeyOf, IsStringLiteral, IsSymbolLiteral, IsTuple, IsUndefined, IsUnknown, IsWritableKeyOf, IterableElement, KebabCase, LiteralUnion, NonEmptyObject, NonEmptyString, NonEmptyTuple, OptionalKeysOf, Or, OverrideProperties, PartialDeep,
|
|
29
|
+
export type { And, Except, HasOptionalKeys, HasRequiredKeys, If, IsAny, IsBooleanLiteral, IsEqual, IsFloat, IsInteger, IsLiteral, IsNever, IsNull, IsNullable, IsNumericLiteral, IsOptional, IsOptionalKeyOf, IsReadonlyKeyOf, IsRequiredKeyOf, IsStringLiteral, IsSymbolLiteral, IsTuple, IsUndefined, IsUnknown, IsWritableKeyOf, IterableElement, KebabCase, LiteralUnion, NonEmptyObject, NonEmptyString, NonEmptyTuple, OptionalKeysOf, Or, OverrideProperties, PartialDeep, Primitive, RequiredDeep, RequiredKeysOf, SetFieldType, SetOptional, SetParameterType, SetReadonly, SetRequired, SetReturnType, Simplify, SimplifyDeep } from 'type-fest';
|
|
@@ -1,9 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a range of numbers from 0 to N-1 as a tuple type.
|
|
3
|
+
* Used to create a union of valid array indices.
|
|
4
|
+
*/
|
|
1
5
|
type ComputeRange<N extends number, Result extends unknown[] = []> = Result["length"] extends N ? Result : ComputeRange<N, [...Result, Result["length"]]>;
|
|
6
|
+
/**
|
|
7
|
+
* Union type of numbers from 0 to 39.
|
|
8
|
+
* Limits tuple index depth to prevent excessive type recursion.
|
|
9
|
+
*/
|
|
2
10
|
type Index40 = ComputeRange<40>[number];
|
|
11
|
+
/**
|
|
12
|
+
* Checks if a type is a tuple (fixed-length array) with length <= 40.
|
|
13
|
+
* Returns the tuple type if valid, never otherwise.
|
|
14
|
+
*/
|
|
3
15
|
type IsTuple<T> = T extends readonly any[] & {
|
|
4
16
|
length: infer Length;
|
|
5
17
|
} ? Length extends Index40 ? T : never : never;
|
|
18
|
+
/**
|
|
19
|
+
* Extracts all valid numeric indices from a tuple type.
|
|
20
|
+
* For [string, number, boolean], returns 0 | 1 | 2.
|
|
21
|
+
*/
|
|
6
22
|
type AllowedIndexes<Tuple extends readonly any[], Keys extends number = never> = Tuple extends readonly [] ? Keys : Tuple extends readonly [infer _, ...infer Tail] ? AllowedIndexes<Tail, Keys | Tail["length"]> : Keys;
|
|
23
|
+
/**
|
|
24
|
+
* Creates dot-notation paths for nested properties.
|
|
25
|
+
* Converts TPrefix.NestedKey into string literal types.
|
|
26
|
+
*/
|
|
7
27
|
type DeepKeysPrefix<T, TPrefix, TDepth extends any[]> = TPrefix extends keyof T & (number | string) ? `${TPrefix}.${DeepKeys<T[TPrefix], [...TDepth, any]> & string}` : never;
|
|
28
|
+
/**
|
|
29
|
+
* Extracts all possible deep property paths from an object type as dot-notation strings.
|
|
30
|
+
* Supports nested objects, tuples, and arrays up to 5 levels deep.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* type User = { name: string; address: { city: string; zip: number } };
|
|
34
|
+
* type Paths = DeepKeys<User>; // "name" | "address" | "address.city" | "address.zip"
|
|
35
|
+
*/
|
|
8
36
|
export type DeepKeys<T, TDepth extends any[] = []> = TDepth["length"] extends 5 ? never : unknown extends T ? string : T extends readonly any[] & IsTuple<T> ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>, TDepth> : T extends any[] ? DeepKeys<T[number], [...TDepth, any]> : T extends Date ? never : T extends object ? (keyof T & string) | DeepKeysPrefix<T, keyof T, TDepth> : never;
|
|
9
37
|
export {};
|
|
@@ -13,12 +13,11 @@ export declare const DEFAULT_DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
|
|
13
13
|
export declare const LOCALIZED_DATETIME_FORMAT = "LLLL";
|
|
14
14
|
export declare const LOCALIZED_DATE_FORMAT = "LLdddd";
|
|
15
15
|
/**
|
|
16
|
-
* Format duration
|
|
16
|
+
* Format duration to human readable string.
|
|
17
17
|
*
|
|
18
|
-
* @param
|
|
18
|
+
* @param value - Duration value
|
|
19
19
|
* @param unit - The unit of the duration (default: "seconds")
|
|
20
20
|
* @returns Formatted duration string
|
|
21
|
-
*
|
|
22
21
|
* @example
|
|
23
22
|
* ```ts
|
|
24
23
|
* formatDuration(60) // "1分钟"
|
|
@@ -27,14 +26,13 @@ export declare const LOCALIZED_DATE_FORMAT = "LLdddd";
|
|
|
27
26
|
* formatDuration(90061) // "1天1小时1分钟"
|
|
28
27
|
* ```
|
|
29
28
|
*/
|
|
30
|
-
export declare function formatDuration(
|
|
29
|
+
export declare function formatDuration(value: number, unit?: DurationUnitType): string;
|
|
31
30
|
/**
|
|
32
31
|
* Parses a date string into a dayjs instance with optional format.
|
|
33
32
|
*
|
|
34
33
|
* @param date - The date string or Date object to parse
|
|
35
34
|
* @param format - The format string to use for parsing (optional, ignored for Date objects)
|
|
36
35
|
* @returns A dayjs instance
|
|
37
|
-
*
|
|
38
36
|
* @example
|
|
39
37
|
* ```ts
|
|
40
38
|
* parseDate("2025-11-10") // dayjs instance
|
|
@@ -51,7 +49,6 @@ export declare function parseDate(date: string | Date, format?: MaybeNull<string
|
|
|
51
49
|
*
|
|
52
50
|
* @param date - The date string to parse
|
|
53
51
|
* @returns A dayjs instance if parsing succeeds, null otherwise
|
|
54
|
-
*
|
|
55
52
|
* @example
|
|
56
53
|
* ```ts
|
|
57
54
|
* tryParseDate("2025-11-10 16:30:45") // dayjs instance
|
|
@@ -67,7 +64,6 @@ export declare function tryParseDate(date: string): MaybeNull<Dayjs>;
|
|
|
67
64
|
* @param date - The dayjs instance to format
|
|
68
65
|
* @param format - The format string (defaults to "YYYY-MM-DD HH:mm:ss")
|
|
69
66
|
* @returns The formatted date string
|
|
70
|
-
*
|
|
71
67
|
* @example
|
|
72
68
|
* ```ts
|
|
73
69
|
* formatDate(dayjs()) // "2025-11-10 16:30:45"
|
|
@@ -80,7 +76,6 @@ export declare function formatDate(date: Dayjs, format?: string): string;
|
|
|
80
76
|
* Gets the current time as a dayjs instance.
|
|
81
77
|
*
|
|
82
78
|
* @returns The current time as a dayjs instance
|
|
83
|
-
*
|
|
84
79
|
* @example
|
|
85
80
|
* ```ts
|
|
86
81
|
* const now = getNow() // dayjs instance
|
|
@@ -92,7 +87,6 @@ export declare function getNow(): Dayjs;
|
|
|
92
87
|
* Gets the current date string in "YYYY-MM-DD" format.
|
|
93
88
|
*
|
|
94
89
|
* @returns The current date string
|
|
95
|
-
*
|
|
96
90
|
* @example
|
|
97
91
|
* ```ts
|
|
98
92
|
* getNowDateString() // "2025-11-10"
|
|
@@ -103,7 +97,6 @@ export declare function getNowDateString(): string;
|
|
|
103
97
|
* Gets the current time string in "HH:mm:ss" format.
|
|
104
98
|
*
|
|
105
99
|
* @returns The current time string
|
|
106
|
-
*
|
|
107
100
|
* @example
|
|
108
101
|
* ```ts
|
|
109
102
|
* getNowTimeString() // "16:30:45"
|
|
@@ -114,7 +107,6 @@ export declare function getNowTimeString(): string;
|
|
|
114
107
|
* Gets the current date time string in "YYYY-MM-DD HH:mm:ss" format.
|
|
115
108
|
*
|
|
116
109
|
* @returns The current date time string
|
|
117
|
-
*
|
|
118
110
|
* @example
|
|
119
111
|
* ```ts
|
|
120
112
|
* getNowDateTimeString() // "2025-11-10 16:30:45"
|
|
@@ -125,7 +117,6 @@ export declare function getNowDateTimeString(): string;
|
|
|
125
117
|
* Gets the current date time in a localized full format.
|
|
126
118
|
*
|
|
127
119
|
* @returns The localized date time string
|
|
128
|
-
*
|
|
129
120
|
* @example
|
|
130
121
|
* ```ts
|
|
131
122
|
* // With zh-cn locale
|
|
@@ -150,7 +141,6 @@ declare const FORMAT_MAP: {
|
|
|
150
141
|
*
|
|
151
142
|
* @param mode - The temporal picker mode
|
|
152
143
|
* @returns An array of format strings for the specified mode
|
|
153
|
-
*
|
|
154
144
|
* @example
|
|
155
145
|
* ```ts
|
|
156
146
|
* getTemporalFormats("date") // ["YYYY-MM-DD", "YYYY/MM/DD", ...]
|
|
@@ -1,38 +1,22 @@
|
|
|
1
1
|
import * as stackTrace from "stacktrace-js";
|
|
2
2
|
export type StackFrame = stackTrace.StackFrame;
|
|
3
3
|
/**
|
|
4
|
-
* Parse
|
|
5
|
-
*
|
|
6
|
-
* @param error The error to parse
|
|
7
|
-
* @param filter The filter function to filter the stack frames
|
|
8
|
-
* @returns The parsed stack frames
|
|
4
|
+
* Parse error stack and optionally filter frames.
|
|
9
5
|
*/
|
|
10
6
|
export declare function parseErrorStack(error: Error, filter?: (frame: StackFrame) => boolean): Promise<StackFrame[]>;
|
|
11
7
|
/**
|
|
12
|
-
* Filter
|
|
13
|
-
*
|
|
14
|
-
* @param stackFrame The stack frame to filter
|
|
15
|
-
* @returns The filtered stack frame
|
|
8
|
+
* Filter to exclude node_modules frames (user code only).
|
|
16
9
|
*/
|
|
17
10
|
export declare function filterUserFrame(stackFrame: StackFrame): boolean;
|
|
18
11
|
/**
|
|
19
|
-
* Get
|
|
20
|
-
*
|
|
21
|
-
* @param error The error to sanitize
|
|
22
|
-
* @returns The sanitized error stack
|
|
12
|
+
* Get sanitized error stack with user frames only.
|
|
23
13
|
*/
|
|
24
14
|
export declare function getSanitizedErrorStack(error: Error): Promise<string>;
|
|
25
15
|
/**
|
|
26
|
-
* Get
|
|
27
|
-
*
|
|
28
|
-
* @param filter The filter function to filter the stack frames
|
|
29
|
-
* @returns The current stack
|
|
16
|
+
* Get current call stack.
|
|
30
17
|
*/
|
|
31
18
|
export declare function getCurrentStack(filter?: (frame: StackFrame) => boolean): Promise<StackFrame[]>;
|
|
32
19
|
/**
|
|
33
|
-
* Get
|
|
34
|
-
*
|
|
35
|
-
* @param filter The filter function to filter the stack frames
|
|
36
|
-
* @returns The current stack
|
|
20
|
+
* Get current call stack synchronously.
|
|
37
21
|
*/
|
|
38
22
|
export declare function getCurrentStackSync(filter?: (frame: StackFrame) => boolean): StackFrame[];
|
|
@@ -1,55 +1,33 @@
|
|
|
1
1
|
import { EventHandlerMap, EventType, Handler } from 'mitt';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Provides a clean API for event subscription, emission, and cleanup.
|
|
5
|
-
*
|
|
6
|
-
* @template TEvents - A record type defining the available events and their payload types
|
|
3
|
+
* Type-safe event emitter wrapper around mitt library.
|
|
7
4
|
*/
|
|
8
|
-
export declare class EventEmitter<TEvents extends Record<EventType, unknown>> {
|
|
5
|
+
export declare class EventEmitter<TEvents extends Record<EventType, any> = Record<EventType, unknown>> {
|
|
9
6
|
#private;
|
|
10
7
|
/**
|
|
11
|
-
* Subscribe to an event
|
|
12
|
-
* Returns an unsubscribe function for easy cleanup.
|
|
13
|
-
*
|
|
14
|
-
* @param eventType - The type of event to listen for
|
|
15
|
-
* @param eventListener - The function to call when the event is emitted
|
|
16
|
-
* @returns A function that removes this specific listener when called
|
|
8
|
+
* Subscribe to an event. Returns unsubscribe function.
|
|
17
9
|
*/
|
|
18
10
|
on<const TEventType extends keyof TEvents>(eventType: TEventType, eventListener: Handler<TEvents[TEventType]>): () => void;
|
|
19
11
|
/**
|
|
20
|
-
* Emit an event with
|
|
21
|
-
* All registered listeners for this event type will be called synchronously.
|
|
22
|
-
*
|
|
23
|
-
* @param eventType - The type of event to emit
|
|
24
|
-
* @param eventPayload - The data to pass to all listeners
|
|
12
|
+
* Emit an event with optional payload.
|
|
25
13
|
*/
|
|
26
14
|
emit<const TEventType extends keyof TEvents>(eventType: undefined extends TEvents[TEventType] ? TEventType : never): void;
|
|
27
15
|
emit<const TEventType extends keyof TEvents>(eventType: TEventType, eventPayload: TEvents[TEventType]): void;
|
|
28
16
|
/**
|
|
29
|
-
* Remove
|
|
30
|
-
* If no listener is provided, removes all listeners for that event type.
|
|
31
|
-
*
|
|
32
|
-
* @param eventType - The type of event to remove listeners from
|
|
33
|
-
* @param eventListener - Optional specific listener to remove
|
|
17
|
+
* Remove listener(s) for an event type.
|
|
34
18
|
*/
|
|
35
19
|
off<const TEventType extends keyof TEvents>(eventType: TEventType, eventListener?: Handler<TEvents[TEventType]>): void;
|
|
36
20
|
/**
|
|
37
|
-
* Remove all
|
|
38
|
-
* Useful for cleanup when the emitter is no longer needed.
|
|
21
|
+
* Remove all listeners from all events.
|
|
39
22
|
*/
|
|
40
23
|
clear(): void;
|
|
41
24
|
/**
|
|
42
|
-
* Get all registered listeners for debugging
|
|
43
|
-
* Returns a Map of event types to their listener arrays.
|
|
25
|
+
* Get all registered listeners (for debugging).
|
|
44
26
|
*/
|
|
45
27
|
getAllListeners(): EventHandlerMap<TEvents>;
|
|
46
28
|
}
|
|
47
29
|
/**
|
|
48
|
-
*
|
|
49
|
-
* Provides a more functional approach to creating event emitters.
|
|
50
|
-
*
|
|
51
|
-
* @template TEvents - A record type defining the available events and their payload types
|
|
52
|
-
* @returns A new EventEmitter instance
|
|
30
|
+
* Create a new EventEmitter instance.
|
|
53
31
|
*
|
|
54
32
|
* @example
|
|
55
33
|
* ```typescript
|
|
@@ -64,5 +42,5 @@ export declare class EventEmitter<TEvents extends Record<EventType, unknown>> {
|
|
|
64
42
|
* });
|
|
65
43
|
* ```
|
|
66
44
|
*/
|
|
67
|
-
export declare function createEventEmitter<TEvents extends Record<EventType, unknown>>(): EventEmitter<TEvents>;
|
|
45
|
+
export declare function createEventEmitter<TEvents extends Record<EventType, any> = Record<EventType, unknown>>(): EventEmitter<TEvents>;
|
|
68
46
|
export { type Handler as EventHandler, type EventType } from 'mitt';
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* @param bytes - Number of bytes
|
|
5
5
|
* @param decimals - Number of decimal places (default: 2)
|
|
6
6
|
* @returns Formatted string with unit (B, KB, MB, GB, TB, PB)
|
|
7
|
-
*
|
|
8
7
|
* @example
|
|
9
8
|
* ```ts
|
|
10
9
|
* formatBytes(1024) // "1 KB"
|
|
@@ -20,7 +19,6 @@ export declare function formatBytes(bytes: number, decimals?: number): string;
|
|
|
20
19
|
* @param num - Number to format
|
|
21
20
|
* @param decimals - Number of decimal places (default: 2)
|
|
22
21
|
* @returns Formatted string with unit (K, M, B, T)
|
|
23
|
-
*
|
|
24
22
|
* @example
|
|
25
23
|
* ```ts
|
|
26
24
|
* formatNumber(1000) // "1 K"
|
|
@@ -1,59 +1,27 @@
|
|
|
1
1
|
import { Awaitable, MaybeUndefined } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Awaitable function invocation options.
|
|
4
|
-
*/
|
|
5
2
|
export interface AwaitableFnInvocationOptions<in TResult, in out TContext = unknown> {
|
|
6
|
-
/**
|
|
7
|
-
* The function to call before invoking the awaitable function.
|
|
8
|
-
*/
|
|
9
3
|
onInvoke?: () => MaybeUndefined<TContext>;
|
|
10
|
-
/**
|
|
11
|
-
* The function to call when the awaitable function succeeds.
|
|
12
|
-
*/
|
|
13
4
|
onSuccess?: (result: TResult, context: MaybeUndefined<TContext>) => void;
|
|
14
|
-
/**
|
|
15
|
-
* The function to call when the awaitable function fails.
|
|
16
|
-
*/
|
|
17
5
|
onError?: (error: unknown, context: MaybeUndefined<TContext>) => void;
|
|
18
|
-
/**
|
|
19
|
-
* The function to call after invoking the awaitable function.
|
|
20
|
-
*/
|
|
21
6
|
onFinally?: (context: MaybeUndefined<TContext>) => void;
|
|
22
7
|
}
|
|
23
8
|
/**
|
|
24
9
|
* Checks if a function is an async function.
|
|
25
|
-
*
|
|
26
|
-
* @param fn - The function to check.
|
|
27
|
-
* @returns `true` if the function is an async function, `false` otherwise.
|
|
28
10
|
*/
|
|
29
11
|
export declare function isAsyncFunction(fn: Function): fn is (...args: any[]) => Promise<any>;
|
|
30
12
|
/**
|
|
31
|
-
* Invokes an awaitable function.
|
|
32
|
-
*
|
|
33
|
-
* @param fn - The awaitable function to invoke.
|
|
34
|
-
* @param args - The arguments to pass to the awaitable function.
|
|
35
|
-
* @param options - The options to pass to the awaitable function.
|
|
36
|
-
* @returns The result of the awaitable function.
|
|
13
|
+
* Invokes an awaitable function with lifecycle hooks.
|
|
37
14
|
*/
|
|
38
15
|
export declare function invokeAwaitableFn<TArgs extends any[] = any[], TResult = unknown, TContext = unknown>(fn: (...args: TArgs) => Awaitable<TResult>, args: NoInfer<TArgs>, options: AwaitableFnInvocationOptions<NoInfer<TResult>, TContext>): Promise<TResult>;
|
|
39
16
|
/**
|
|
40
|
-
* Returns the value itself.
|
|
41
|
-
*
|
|
42
|
-
* @param value - The value to return.
|
|
43
|
-
* @returns The value itself.
|
|
17
|
+
* Returns the value itself (identity function).
|
|
44
18
|
*/
|
|
45
19
|
export declare function identity<T>(value: T): T;
|
|
46
20
|
/**
|
|
47
|
-
* Creates a function that throws
|
|
48
|
-
*
|
|
49
|
-
* @param feature - The feature/function name to include in the error message.
|
|
50
|
-
* @returns A function that throws an error indicating the feature/function is not implemented.
|
|
21
|
+
* Creates a function that throws a not-implemented error.
|
|
51
22
|
*/
|
|
52
23
|
export declare function createThrowNotImplementedFn(feature?: string): () => never;
|
|
53
24
|
/**
|
|
54
|
-
* Throws
|
|
55
|
-
*
|
|
56
|
-
* @param feature - The feature/function name to include in the error message.
|
|
57
|
-
* @throws Always throws an Error to indicate a missing implementation.
|
|
25
|
+
* Throws a not-implemented error.
|
|
58
26
|
*/
|
|
59
27
|
export declare function throwNotImplemented(feature?: string): never;
|
package/dist/types/utils/id.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generate a hash key from
|
|
3
|
-
*
|
|
4
|
-
* @param key - The value to generate a hash key from.
|
|
5
|
-
* @returns The hash key.
|
|
2
|
+
* Generate a stable hash key from any value by serializing to JSON.
|
|
3
|
+
* Objects are normalized with sorted keys for consistent hashing.
|
|
6
4
|
*/
|
|
7
5
|
export declare function hashKey(key: unknown): string;
|