UNPKG

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