UNPKG

1.85 kBTypeScriptView Raw
1type HorizontalTableRow = string[];
2type VerticalTableRow = Record<string, string>;
3type CrossTableRow = Record<string, string[]>;
4type TableRow = HorizontalTableRow | VerticalTableRow | CrossTableRow;
5
6interface TableOptions<T extends TableRow = TableRow> {
7 rows?: T[];
8 chars?: {
9 [
10 k in
11 | "top"
12 | "top-mid"
13 | "top-left"
14 | "top-right"
15 | "bottom"
16 | "bottom-mid"
17 | "bottom-left"
18 | "bottom-right"
19 | "left"
20 | "left-mid"
21 | "mid"
22 | "mid-mid"
23 | "right"
24 | "right-mid"
25 | "middle"
26 ]?: string;
27 };
28 truncate?: string;
29 colors?: boolean;
30 colWidths?: number[];
31 colAligns?: Array<"left" | "middle" | "right">;
32 style?: {
33 "padding-left"?: number;
34 "padding-right"?: number;
35 head?: string[];
36 border?: string[];
37 compact?: boolean;
38 };
39 head?: string[];
40}
41
42declare class Table<T extends TableRow = TableRow> extends Array<T> {
43 /**
44 * Table constructor
45 *
46 * @param options
47 * @api public
48 */
49 constructor(options?: T extends CrossTableRow ? never : TableOptions<T>);
50 constructor(options: T extends CrossTableRow ? TableOptions<T> & { head: ["", ...string[]] } : never);
51
52 /**
53 * Width getter
54 *
55 * @return width
56 * @api public
57 */
58 get width(): number;
59
60 /**
61 * Render to a string.
62 *
63 * @return table representation
64 * @api public
65 */
66 render(): string;
67
68 /**
69 * Render to a string.
70 *
71 * @return table representation
72 * @api public
73 */
74 toString(): string;
75
76 static readonly version: string;
77}
78
79export = Table;