UNPKG

2.08 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 [k in
17 | 'top'
18 | 'top-mid'
19 | 'top-left'
20 | 'top-right'
21 | 'bottom'
22 | 'bottom-mid'
23 | 'bottom-left'
24 | 'bottom-right'
25 | 'left'
26 | 'left-mid'
27 | 'mid'
28 | 'mid-mid'
29 | 'right'
30 | 'right-mid'
31 | 'middle']?: string;
32 };
33 truncate?: string;
34 colors?: boolean;
35 colWidths?: number[];
36 colAligns?: Array<'left' | 'middle' | 'right'>;
37 style?: {
38 'padding-left'?: number;
39 'padding-right'?: number;
40 head?: string[];
41 border?: string[];
42 compact?: boolean;
43 };
44 head?: string[];
45}
46
47declare class Table<T extends TableRow = TableRow> extends Array<T> {
48 /**
49 * Table constructor
50 *
51 * @param options
52 * @api public
53 */
54 constructor(options?: T extends CrossTableRow ? never : TableOptions<T>);
55 constructor(options: T extends CrossTableRow ? TableOptions<T> & { head: ['', ...string[]] } : never);
56
57 /**
58 * Width getter
59 *
60 * @return width
61 * @api public
62 */
63 get width(): number;
64
65 /**
66 * Render to a string.
67 *
68 * @return table representation
69 * @api public
70 */
71 render(): string;
72
73 /**
74 * Render to a string.
75 *
76 * @return table representation
77 * @api public
78 */
79 toString(): string;
80
81 static readonly version: string;
82}
83
84export = Table;