Skip to content

Commit a4a6bf3

Browse files
Merge pull request #141 from vue-pivottable/feature/utilities-ts-migration
feat(helper): utilities TypeScript 마이그레이션
2 parents 4f82915 + c4fad3c commit a4a6bf3

File tree

4 files changed

+1137
-884
lines changed

4 files changed

+1137
-884
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"clean": "rimraf dist",
5555
"clean:all": "rimraf dist packages/*/dist",
5656
"dev": "vite",
57-
"build": "vite build",
57+
"build": "tsc src/helper/utilities.ts --declaration --emitDeclarationOnly --outDir src/helper && vite build",
5858
"preview": "vite preview",
5959
"lint": "eslint",
6060
"build:all": "pnpm clean && pnpm build && pnpm -r --filter './packages/*' build",

src/helper/utilities.d.ts

Lines changed: 133 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,135 @@
1+
type AttributeName = string & {
2+
readonly __brand: unique symbol;
3+
};
4+
type FlatKey = string & {
5+
readonly __brand: unique symbol;
6+
};
7+
type NumericValue = number & {
8+
readonly __brand: unique symbol;
9+
};
10+
interface NumberFormatOptions {
11+
digitsAfterDecimal?: number;
12+
scaler?: number;
13+
thousandsSep?: string;
14+
decimalSep?: string;
15+
prefix?: string;
16+
suffix?: string;
17+
}
18+
type Formatter = (value: number) => string;
19+
type SortFunction = (a: any, b: any) => number;
20+
type RecordValue = string | number;
21+
type DataRecord = Record<string, RecordValue>;
22+
interface AggregatorInstance {
23+
count?: number;
24+
sum?: number;
25+
vals?: number[];
26+
uniq?: any[];
27+
val?: any;
28+
sorter?: SortFunction;
29+
n?: number;
30+
m?: number;
31+
s?: number;
32+
sumNum?: number;
33+
sumDenom?: number;
34+
selector?: [any[], any[]];
35+
inner?: AggregatorInstance;
36+
push: (record: DataRecord) => void;
37+
value: () => any;
38+
format?: Formatter | ((x: any) => string);
39+
numInputs?: number;
40+
}
41+
type AggregatorFunction = (data?: PivotDataContext, rowKey?: any[], colKey?: any[]) => AggregatorInstance;
42+
type AggregatorTemplate = (...args: any[]) => AggregatorFunction;
43+
interface AggregatorTemplates {
44+
count: (formatter?: Formatter) => AggregatorTemplate;
45+
uniques: (fn: (uniq: any[]) => any, formatter?: Formatter) => AggregatorTemplate;
46+
sum: (formatter?: Formatter) => AggregatorTemplate;
47+
extremes: (mode: 'min' | 'max' | 'first' | 'last', formatter?: Formatter) => AggregatorTemplate;
48+
quantile: (q: number, formatter?: Formatter) => AggregatorTemplate;
49+
runningStat: (mode: 'mean' | 'var' | 'stdev', ddof?: number, formatter?: Formatter) => AggregatorTemplate;
50+
sumOverSum: (formatter?: Formatter) => AggregatorTemplate;
51+
fractionOf: (wrapped: AggregatorTemplate, type?: 'total' | 'row' | 'col', formatter?: Formatter) => AggregatorTemplate;
52+
countUnique: (formatter?: Formatter) => AggregatorTemplate;
53+
listUnique: (separator: string) => AggregatorTemplate;
54+
max: (formatter?: Formatter) => AggregatorTemplate;
55+
min: (formatter?: Formatter) => AggregatorTemplate;
56+
first: (formatter?: Formatter) => AggregatorTemplate;
57+
last: (formatter?: Formatter) => AggregatorTemplate;
58+
median: (formatter?: Formatter) => AggregatorTemplate;
59+
average: (formatter?: Formatter) => AggregatorTemplate;
60+
var: (ddof: number, formatter?: Formatter) => AggregatorTemplate;
61+
stdev: (ddof: number, formatter?: Formatter) => AggregatorTemplate;
62+
}
63+
interface PivotDataProps {
64+
data: DataRecord[] | DataRecord[][] | ((callback: (record: DataRecord) => void) => void);
65+
aggregators?: Record<string, AggregatorTemplate>;
66+
cols?: string[];
67+
rows?: string[];
68+
vals?: string[];
69+
aggregatorName?: string;
70+
sorters?: Record<string, SortFunction> | ((attr: string) => SortFunction);
71+
valueFilter?: Record<string, Record<string, boolean>>;
72+
rowOrder?: 'key_a_to_z' | 'key_z_to_a' | 'value_a_to_z' | 'value_z_to_a';
73+
colOrder?: 'key_a_to_z' | 'key_z_to_a' | 'value_a_to_z' | 'value_z_to_a';
74+
derivedAttributes?: Record<string, (record: DataRecord) => RecordValue>;
75+
}
76+
interface PivotDataContext {
77+
getAggregator: (rowKey: any[], colKey: any[]) => AggregatorInstance;
78+
}
79+
interface LocaleStrings {
80+
renderError: string;
81+
computeError: string;
82+
uiRenderError: string;
83+
selectAll: string;
84+
selectNone: string;
85+
tooMany: string;
86+
filterResults: string;
87+
totals: string;
88+
vs: string;
89+
by: string;
90+
cancel: string;
91+
only: string;
92+
apply?: string;
93+
}
94+
interface Locale {
95+
aggregators?: Record<string, AggregatorTemplate>;
96+
frAggregators?: Record<string, AggregatorTemplate>;
97+
localeStrings: LocaleStrings;
98+
}
99+
interface Derivers {
100+
bin: (col: string, binWidth: number) => (record: DataRecord) => number;
101+
dateFormat: (col: string, formatString: string, utcOutput?: boolean, mthNames?: string[], dayNames?: string[]) => (record: DataRecord) => string;
102+
}
103+
declare const numberFormat: (optsIn?: NumberFormatOptions) => Formatter;
104+
declare const naturalSort: SortFunction;
105+
declare const sortAs: (order: any[]) => SortFunction;
106+
declare const getSort: (sorters: Record<string, SortFunction> | ((attr: string) => SortFunction) | null, attr: string) => SortFunction;
107+
declare const aggregatorTemplates: AggregatorTemplates;
108+
declare const aggregators: Record<string, AggregatorTemplate>;
109+
declare const locales: Record<string, Locale>;
110+
declare const derivers: Derivers;
1111
declare class PivotData {
2-
constructor(inputProps?: any)
3-
props: any
4-
getRowKeys(): any[]
5-
getColKeys(): any[]
6-
getAggregator(rowKey: any, colKey: any): any
7-
[key: string]: any
8-
}
9-
10-
declare const aggregators: Record<string, any>
11-
declare const aggregatorTemplates: Record<string, any>
12-
declare const locales: Record<string, any>
13-
declare const naturalSort: (a: any, b: any) => number
14-
declare const numberFormat: (opts?: any) => any
15-
declare const getSort: any
16-
declare const sortAs: any
17-
declare const derivers: any
18-
19-
export {
20-
PivotData,
21-
aggregators,
22-
aggregatorTemplates,
23-
locales,
24-
naturalSort,
25-
numberFormat,
26-
getSort,
27-
sortAs,
28-
derivers
112+
static defaultProps: Required<PivotDataProps>;
113+
props: Required<PivotDataProps>;
114+
aggregator: AggregatorFunction;
115+
tree: Record<string, Record<string, AggregatorInstance>>;
116+
rowKeys: any[][];
117+
colKeys: any[][];
118+
rowTotals: Record<string, AggregatorInstance>;
119+
colTotals: Record<string, AggregatorInstance>;
120+
allTotal: AggregatorInstance;
121+
sorted: boolean;
122+
filteredData: DataRecord[];
123+
constructor(inputProps?: Partial<PivotDataProps>);
124+
filter(record: DataRecord): boolean;
125+
forEachMatchingRecord(criteria: Record<string, any>, callback: (record: DataRecord) => void): void;
126+
arrSort(attrs: string[]): SortFunction;
127+
sortKeys(): void;
128+
getFilteredData(): DataRecord[];
129+
getColKeys(): any[][];
130+
getRowKeys(): any[][];
131+
processRecord(record: DataRecord): void;
132+
getAggregator(rowKey: any[], colKey: any[]): AggregatorInstance;
133+
static forEachRecord(input: DataRecord[] | DataRecord[][] | ((callback: (record: DataRecord) => void) => void), derivedAttributes: Record<string, (record: DataRecord) => RecordValue>, f: (record: DataRecord) => void): void;
29134
}
135+
export { type NumberFormatOptions, type Formatter, type SortFunction, type RecordValue, type DataRecord, type AggregatorInstance, type AggregatorFunction, type AggregatorTemplate, type AggregatorTemplates, type PivotDataProps, type PivotDataContext, type LocaleStrings, type Locale, type Derivers, type AttributeName, type FlatKey, type NumericValue, aggregatorTemplates, aggregators, derivers, locales, naturalSort, numberFormat, getSort, sortAs, PivotData };

0 commit comments

Comments
 (0)