| 145 | } |
| 146 | |
| 147 | const setupTable = (options: Partial<TableOptions>): Table => { |
| 148 | const data: string[][] = [] |
| 149 | |
| 150 | const push = (row: TableCellData[]): number => data.push(row.map(cell => cell?.toString() ?? '')) |
| 151 | |
| 152 | if (options.head) { |
| 153 | data.push(options.head) |
| 154 | } |
| 155 | |
| 156 | const toString = (): string => { |
| 157 | const border = { |
| 158 | topBody: '─', |
| 159 | topJoin: '', |
| 160 | topLeft: '', |
| 161 | topRight: '', |
| 162 | |
| 163 | bottomBody: '─', |
| 164 | bottomJoin: '', |
| 165 | bottomLeft: '', |
| 166 | bottomRight: '', |
| 167 | |
| 168 | bodyLeft: '', |
| 169 | bodyRight: '', |
| 170 | bodyJoin: '', |
| 171 | |
| 172 | joinBody: '─', |
| 173 | joinLeft: '', |
| 174 | joinRight: '', |
| 175 | joinJoin: '', |
| 176 | } |
| 177 | |
| 178 | const listDrawHorizontalLine = options.groupRows |
| 179 | ? (index: number) => index === 0 || index === data.length || (index - 1) % 5 === 0 |
| 180 | : (index: number) => index === 0 || index === data.length || index === 1 |
| 181 | const drawHorizontalLine = options.isList |
| 182 | ? listDrawHorizontalLine |
| 183 | : (index: number) => index === 0 || index === data.length |
| 184 | const config = { drawHorizontalLine, border } |
| 185 | return table(data, config) |
| 186 | } |
| 187 | |
| 188 | return { push, toString } |
| 189 | } |
| 190 | |
| 191 | export const defaultTableGenerator = (tableOptions: Pick<TableOptions, 'groupRows'>): TableGenerator => { |
| 192 | const logger = log4js.getLogger('table-manager') |