Skip to content

Commit ebfe8a0

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

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

lib/index.d.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
interface TableOptions<T> {
2+
rows?: T[];
3+
chars?: {
4+
[k in
5+
| 'top'
6+
| 'top-mid'
7+
| 'top-left'
8+
| 'top-right'
9+
| 'bottom'
10+
| 'bottom-mid'
11+
| 'bottom-left'
12+
| 'bottom-right'
13+
| 'left'
14+
| 'left-mid'
15+
| 'mid'
16+
| 'mid-mid'
17+
| 'right'
18+
| 'right-mid'
19+
| 'middle']?: string;
20+
};
21+
truncate?: string;
22+
colors?: boolean;
23+
colWidths?: number[];
24+
colAligns?: Array<'left' | 'middle' | 'right'>;
25+
style?: {
26+
'padding-left'?: number;
27+
'padding-right'?: number;
28+
head?: string[];
29+
border?: string[];
30+
compact?: boolean;
31+
};
32+
head?: string[];
33+
}
34+
35+
type HorizontalTableRow = string[];
36+
type VerticalTableRow = Record<string, string>;
37+
type CrossTableRow = Record<string, string[]>;
38+
type TableRow = HorizontalTableRow | VerticalTableRow | CrossTableRow;
39+
40+
declare class Table<T extends TableRow> extends Array<T> {
41+
constructor(options?: T extends CrossTableRow ? never : TableOptions<T>);
42+
constructor(options: T extends CrossTableRow ? TableOptions<T> & { head: ['', ...string[]] } : never);
43+
render(): string;
44+
toString(): string;
45+
static readonly version: string;
46+
}
47+
48+
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)