-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (28 loc) · 966 Bytes
/
index.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 fs = require('fs')
const d3 = require('d3')
// Simple promisify readFile function.
const readfileDataAsync = (filePath) => new Promise((resolve, reject) => {
fs.readFile(filePath, 'utf8', function (err, data) {
if (err) reject(err);
resolve(data)
});
})
// Simple promisify readFile function with normal function
function readfileDataAsync2(filePath) {
return new Promise((resolve, reject) => {
fs.readFile(filePath, 'utf8', function (err, data) {
if (err) reject(err);
resolve(data)
});
})
}
async function readAndParse() {
const fileData = await readfileDataAsync2('./teste.csv')
const fileDataParsed = d3.csvParse(fileData)
console.log(fileDataParsed)
}
readAndParse()
// parsedData é um array de objetos chave valor
// console.log(parsedData.filter(item => item.state === 'MO'))
// console.log(parsedData.filter(item => item.state === 'MO'))
// console.log(parsedData.filter(item => item.state === 'MO'))