Skip to content

Commit 42fddf9

Browse files
authored
Merge pull request #21 from Turbo87/typing
Import type definition from `@types/cli-table2`
2 parents 174c23f + 51da150 commit 42fddf9

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

index.d.ts

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
declare namespace CliTable3 {
2+
type CharName =
3+
"top" |
4+
"top-mid" |
5+
"top-left" |
6+
"top-right" |
7+
"bottom" |
8+
"bottom-mid" |
9+
"bottom-left" |
10+
"bottom-right" |
11+
"left" |
12+
"left-mid" |
13+
"mid" |
14+
"mid-mid" |
15+
"right" |
16+
"right-mid" |
17+
"middle";
18+
19+
type HorizontalAlignment = "left" | "center" | "right";
20+
type VerticalAlignment = "top" | "center" | "bottom";
21+
22+
interface TableOptions {
23+
truncate: string;
24+
colWidths: Array<number | null>;
25+
rowHeights: Array<number | null>;
26+
colAligns: HorizontalAlignment[];
27+
rowAligns: VerticalAlignment[];
28+
head: string[];
29+
wordWrap: boolean;
30+
}
31+
32+
interface TableInstanceOptions extends TableOptions {
33+
chars: Record<CharName, string>;
34+
style: {
35+
"padding-left": number;
36+
"padding-right": number;
37+
head: string[];
38+
border: string[];
39+
compact: boolean;
40+
};
41+
}
42+
43+
interface TableConstructorOptions extends Partial<TableOptions> {
44+
chars?: Partial<Record<CharName, string>>;
45+
style?: Partial<TableInstanceOptions["style"]>;
46+
}
47+
48+
type CellValue = boolean | number | string | null | undefined;
49+
50+
interface CellOptions {
51+
content: CellValue;
52+
chars?: Partial<Record<CharName, string>>;
53+
truncate?: string;
54+
colSpan?: number;
55+
rowSpan?: number;
56+
hAlign?: HorizontalAlignment;
57+
vAlign?: VerticalAlignment;
58+
style?: {
59+
"padding-left"?: number;
60+
"padding-right"?: number;
61+
head?: string[];
62+
border?: string[];
63+
};
64+
}
65+
66+
interface GenericTable<T> extends Array<T> {
67+
options: TableInstanceOptions;
68+
readonly width: number;
69+
}
70+
71+
type Table = HorizontalTable | VerticalTable | CrossTable;
72+
type Cell = CellValue | CellOptions;
73+
74+
type HorizontalTable = GenericTable<HorizontalTableRow>;
75+
type HorizontalTableRow = Cell[];
76+
77+
type VerticalTable = GenericTable<VerticalTableRow>;
78+
interface VerticalTableRow {
79+
[name: string]: Cell;
80+
}
81+
82+
type CrossTable = GenericTable<CrossTableRow>;
83+
interface CrossTableRow {
84+
[name: string]: Cell[];
85+
}
86+
}
87+
88+
interface CliTable3 {
89+
new (options?: CliTable3.TableConstructorOptions): CliTable3.Table;
90+
readonly prototype: CliTable3.Table;
91+
}
92+
93+
declare const CliTable3: CliTable3;
94+
95+
export = CliTable3;

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
"version": "0.5.0",
44
"description": "Pretty unicode tables for the command line. Based on the original cli-table.",
55
"main": "index.js",
6+
"types": "index.d.ts",
67
"files": [
78
"src/",
9+
"index.d.ts",
810
"index.js"
911
],
1012
"directories": {

0 commit comments

Comments
 (0)