-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.js
37 lines (30 loc) · 850 Bytes
/
utilities.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
const csv = require('csv-parser');
const fs = require('fs');
const path = require("path");
class Utilities {
static readCSV(path) {
return new Promise(((resolve, reject) => {
const results = [];
fs.createReadStream(path)
.pipe(csv())
.on('data', data => results.push(data))
.on('end', () => {
resolve(results);
})
.on('error', reject);
}));
}
static readFile(path) {
return fs.readFileSync(path).toString();
}
static writeFile(path, content) {
fs.writeFileSync(path, content);
}
static removeFilePart(dirname){
return path.parse(dirname).dir;
};
static fileExists(path) {
return fs.existsSync(path);
}
}
module.exports = Utilities;