-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
56 lines (50 loc) · 1.26 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// dependencies
var CsvToArray = require ("csv-to-array")
, Fs = require ("fs")
, PATHS = {
csv: "./RO/csv/"
, json: "./RO/json/"
}
, csvData = [
{
file: "books"
, columns: [
"id"
, "book"
]
}
, {
file: "verses"
, columns: [
"book"
, "chapter"
, "verse"
, "type"
, "text"
]
}
]
;
// each object in csv data
for (var i = 0; i < csvData.length; ++i) {
(function (cDataObj) {
// convert CSV to JSON
CsvToArray ({
csvOptions: {
delimiter: ";"
}
, file: PATHS.csv + cDataObj.file + ".csv"
, columns: cDataObj.columns
}, function (err, response) {
// handle error
if (err) {
console.log ("Cannot convert " + cDataObj.file + ": ", err);
return;
}
// output
console.log ("Writing " + cDataObj.file + ".json ...");
// write file
Fs.writeFileSync(PATHS.json + cDataObj.file + ".json", JSON.stringify (response, null, 4));
});
})(csvData[i]);
}