-
Notifications
You must be signed in to change notification settings - Fork 0
/
processList.js
34 lines (29 loc) · 907 Bytes
/
processList.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
const fs = require("fs");
let dmc = {};
let totalArr;
//parse the data from the CSV
fs.readFile("result.csv", "utf8", (err, data) => {
if (err) {
console.log(err);
return;
}
//get it into an array
totalArr = data.split("\r\n")
totalArr.pop();
//format it into an object
for (let colour of totalArr) {
let line = colour.split(",");
dmc[line[0].toLowerCase()] = {
number: line[0].toLowerCase().trim(), //this is redundant, but it's useful for managing search responses
readableName: line[1].trim(),
searchName: line[1].toLowerCase().trim().replace(/ /g, "_"),
hex: line[2].trim().slice(1)
}
}
delete dmc.dmc_color;
console.log(dmc);
//write to flossList.json
fs.writeFile("flossList.json", JSON.stringify(dmc), err => {
if (err) console.error(err);
})
});