Skip to content

Commit 8bcaee5

Browse files
committed
Add TypeScript type declaration
1 parent 6593d2e commit 8bcaee5

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

lib/index.d.ts

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

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"expresso": "~0.9",
1818
"should": "~0.6"
1919
},
20-
"main": "lib",
20+
"main": "./lib/index.js",
21+
"types": "./lib/main.d.ts",
2122
"files": ["lib"],
2223
"scripts": {
2324
"test": "make test"

0 commit comments

Comments
 (0)