import { Collection } from '@freearhey/core' export type HTMLTableColumn = { name: string nowrap?: boolean align?: string } export type HTMLTableItem = string[] export class HTMLTable { data: Collection columns: Collection constructor(data: Collection, columns: Collection) { this.data = data this.columns = columns } toString() { let output = '\r\n' output += ' \r\n ' this.columns.forEach((column: HTMLTableColumn) => { output += `` }) output += '\r\n \r\n' output += ' \r\n' this.data.forEach((item: HTMLTableItem) => { output += ' ' let i = 0 for (const prop in item) { const column = this.columns.all()[i] const nowrap = column.nowrap ? ' nowrap' : '' const align = column.align ? ` align="${column.align}"` : '' output += `${item[prop]}` i++ } output += '\r\n' }) output += ' \r\n' output += '
${column.name}
' return output } }