UNPKG

3.01 kBTypeScriptView Raw
1/**
2 * data transforms
3 *
4 * @packageDocumentation
5 */
6
7
8/**
9 * @beta
10 */
11export declare interface Action {
12 type: ActionType;
13 field: string | null;
14 as: string | null;
15 options?: FillNullOptions;
16}
17
18/**
19 * @beta
20 */
21export declare type ActionType = AggregationType | ConversionType | FillType;
22
23/**
24 *
25 * @param rows - 数据
26 * @param options - 参数
27 *
28 * @public
29 */
30export declare function aggregate(rows: RowData[], options: AggregateParams): RowData[];
31
32/**
33 * @public
34 */
35export declare interface AggregateParams {
36 as: string[];
37 fields?: string[];
38 groupBy?: string | string[];
39 op: Operations[];
40}
41
42/**
43 * @beta
44 */
45export declare const AGGREGATION: ["sum", "max", "min", "average", "avg", "median", "count", "distinct", "countd"];
46
47/**
48 * @beta
49 */
50export declare type AggregationType = typeof AGGREGATION[number];
51
52/**
53 * @beta
54 */
55export declare function autoSchema(data: RowData[], renameOption?: RenameOption): TransformSchema[];
56
57/**
58 * @beta
59 */
60export declare function autoTransform(data: RowData[], renameOption?: RenameOption): AutoTransformResult;
61
62/**
63 * @beta
64 */
65export declare interface AutoTransformResult {
66 result: RowData;
67 schemas: TransformSchema[];
68}
69
70/**
71 * @beta
72 */
73export declare const CONVERSION: ["toString", "toFloat", "toInt"];
74
75/**
76 * @beta
77 */
78export declare type ConversionType = typeof CONVERSION[number];
79
80/**
81 * @beta
82 */
83export declare const FILL: ["fillNull", "removeNull"];
84
85/**
86 * @beta
87 */
88export declare type FillNullOptions = FillNullOptionsBySmart | FillNullOptionsByAgg | FillNullOptionsByValue;
89
90/**
91 * @beta
92 */
93export declare interface FillNullOptionsByAgg {
94 type: Extract<FillNullType, 'byAgg'>;
95 cfg: {
96 agg: AggregationType;
97 };
98}
99
100/**
101 * @beta
102 */
103export declare interface FillNullOptionsBySmart {
104 type: Extract<FillNullType, 'bySmart'>;
105}
106
107/**
108 * @beta
109 */
110export declare interface FillNullOptionsByValue {
111 type: Extract<FillNullType, 'byValue'>;
112 cfg: {
113 value: string | number;
114 };
115}
116
117/**
118 * @beta
119 */
120export declare type FillNullType = 'bySmart' | 'byAgg' | 'byValue';
121
122/**
123 * @beta
124 */
125export declare type FillType = typeof FILL[number];
126
127/**
128 * aggregate operation
129 * @public
130 */
131export declare type Operations = 'sum' | 'average' | 'avg' | 'mean' | 'min' | 'max' | 'median' | 'variance' | 'stdevp' | 'stdev' | 'mode' | 'product' | 'count' | 'distinct' | 'countd' | 'valid';
132
133/**
134 * @beta
135 */
136export declare function parse(data: RowData[], schemas: TransformSchema | TransformSchema[]): RowData[];
137
138/**
139 * @beta
140 */
141export declare type RenameOption = boolean | 'origin' | 'brackets' | 'underline' | Function;
142
143/**
144 * 数据行
145 * @public
146 */
147export declare type RowData = Record<string, any>;
148
149/**
150 * @beta
151 */
152export declare interface TransformSchema {
153 groupBy?: string[];
154 actions: Action[];
155}
156
157export { }