-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
35 lines (34 loc) · 1.12 KB
/
main.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
const document = require("csv-parse");
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const fs = require('fs');
let auxArr = []
// const assert = require('assert')
function readCSV(direction, name) {
fs.createReadStream(direction).pipe(document({ delimiter: ";", trim: true, columns: ['ID', 'TEXTO'] })).on('data', (row) => {
auxArr.push(row)
}).on('end', () => {
let aux = auxArr.map((x) => {
return {
id_order: x.ID,
order_note: x.TEXTO === '' ? 'null' : String(x.TEXTO).replace(/(\r\n|\n|\r)/gm, " ")
}
});
const csvWriter = createCsvWriter({
path: `${name}.csv`,
header: [
{
id: "id_order",
title: "id_order"
},
{
id: "order_note",
title: "order_note"
}
]
})
csvWriter
.writeRecords(aux)
.then(() => console.log('The CSV file was written successfully'))
})
}
readCSV('./notas_pedidos.csv','notas')