type Column = { name: string nowrap?: boolean align?: string colspan?: number } type DataItem = { value: string nowrap?: boolean align?: string colspan?: number }[] export class HTMLTable { data: DataItem[] columns: Column[] constructor(data: DataItem[], columns: Column[]) { this.data = data this.columns = columns } toString() { let output = '\r\n' output += ' \r\n ' for (const column of this.columns) { const nowrap = column.nowrap ? ' nowrap' : '' const align = column.align ? ` align="${column.align}"` : '' const colspan = column.colspan ? ` colspan="${column.colspan}"` : '' output += `${column.name}` } output += '\r\n \r\n' output += ' \r\n' for (const row of this.data) { output += ' ' for (const item of row) { const nowrap = item.nowrap ? ' nowrap' : '' const align = item.align ? ` align="${item.align}"` : '' const colspan = item.colspan ? ` colspan="${item.colspan}"` : '' output += `${item.value}` } output += '\r\n' } output += ' \r\n' output += '
' return output } }