-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtable.js
49 lines (40 loc) · 902 Bytes
/
table.js
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
45
46
47
48
49
const kHeaders = Symbol('headers')
const kRows = Symbol('row')
const kStyle = Symbol('style')
const kColumStyle = Symbol('columnStyle')
class Table {
constructor(output) {
this.output = output
}
setHeaders(headers) {
this[kHeaders] = headers
return this
}
setRows(rows) {
this[kRows] = rows
return this
}
setStyle(style) {
this[kStyle] = style
return this
}
setColumnStyle(style) {
this[kColumStyle] = style
}
render() {
let datas = []
for(let row of this[kRows]){
let data = {}
this[kHeaders].forEach((header,i)=>{
let message = row[i]
if(typeof message == 'string'){
message = message.replace(/<.*>(.*)<\/.*>/g,'$1')
}
data[header] = message
})
datas.push(data)
}
console.table(datas)
}
}
module.exports = Table