-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathdrawTable.ts
44 lines (40 loc) · 1.1 KB
/
drawTable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {
createTableBorderGetter,
} from './drawBorder';
import {
drawContent,
} from './drawContent';
import {
drawRow,
} from './drawRow';
import type {
TableConfig, Row,
} from './types/internal';
import {
groupBySizes,
} from './utils';
export const drawTable = (rows: Row[], outputColumnWidths: number[], rowHeights: number[], config: TableConfig): string => {
const {
drawHorizontalLine,
singleLine,
} = config;
const contents = groupBySizes(rows, rowHeights).map((group, groupIndex) => {
return group.map((row) => {
return drawRow(row, {...config,
rowIndex: groupIndex});
}).join('');
});
return drawContent({contents,
drawSeparator: (index, size) => {
// Top/bottom border
if (index === 0 || index === size) {
return drawHorizontalLine(index, size);
}
return !singleLine && drawHorizontalLine(index, size);
},
elementType: 'row',
rowIndex: -1,
separatorGetter: createTableBorderGetter(outputColumnWidths, {...config,
rowCount: contents.length}),
spanningCellManager: config.spanningCellManager});
};