-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exporter.ts
36 lines (30 loc) · 927 Bytes
/
Exporter.ts
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
import { FukkanComment, CsvRow } from './@types/index'
import { writeToPath } from '@fast-csv/format'
class Exporter {
fukkanComments: FukkanComment[]
outputCsvPath: string
constructor(
fukkanComments: FukkanComment[],
outputCsvPath: string = 'fukkan_comments.csv'
) {
this.fukkanComments = fukkanComments
this.outputCsvPath = outputCsvPath
}
toCsv() {
const headers: CsvRow = ['userId', 'userName', 'commentDetail', 'postedOn']
const rows = [] as CsvRow[]
rows.push(headers)
this.fukkanComments.forEach((comment: FukkanComment) => {
rows.push([
comment.userId,
comment.userName,
comment.commentDetail,
comment.postedOn,
])
})
writeToPath(this.outputCsvPath, rows)
.on('error', (err) => console.error(err))
.on('finish', () => console.log('[LOG] CSV出力が完了しました。'))
}
}
export default Exporter