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