-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreaderExcel.js
56 lines (49 loc) · 1.52 KB
/
readerExcel.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
50
51
52
53
54
const fs = require("fs");
const csv = require('csv-parser');
const readerCsv = async(dir) => {
const results = {
info: {},
data: []
};
var pipeCsv = csv({
headers: [
"No",
'WaktuTransaksi',
"NoReferensi",
"NamaPengirim",
"BankPengirim",
"NamaPenerima",
"BankPenerima",
"Deskripsi",
"Debet",
"Kredit",
"SaldoRiil",
"Kode",
],
})
return new Promise((resolve, reject) => {
fs.createReadStream(dir)
.pipe(pipeCsv)
.on('data', (data) => {
if (data.No && data.No != " ") {
if (data.WaktuTransaksi) {
if (data.No != "No")
results.data.push(data);
} else {
var x = data.No.split(": ");
var key = x[0].replaceAll("\t", "").replaceAll("(dlm Periode)", "").split(" ").map(e => e ? e[0].toUpperCase() + e.substr(1) : e).join("");
var val = x[1].replaceAll("\t", "");
results.info[key] = val;
}
}
}).on('end', () => {
resolve(results);
});
})
}
// (async() => {
// var csvFilePath = __dirname+"/mutasi_rekening.csv";
// var x = await readerCsv(csvFilePath);
// console.log("dari sini => ",x);
// })()
module.exports = readerCsv;