-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgear.js
35 lines (29 loc) · 769 Bytes
/
gear.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 CSVToJSON = require('csvtojson')
const compare = (a, b) => {
a.Priority = (a.Priority) ? Number.parseInt(a.Priority, 10) : a.Priority = 9000
b.Priority = (b.Priority) ? Number.parseInt(b.Priority, 10) : b.Priority = 9000
if (a.Priority > b.Priority) {
return 1
}
if (a.Priority < b.Priority) {
return -1
}
if (a.Title > b.Title) {
return 1
}
if (a.Title < b.Title) {
return -1
}
return 0
}
module.exports = function () {
return new Promise(async (resolve) => {
try {
const gears = await CSVToJSON().fromFile('_data/gear.csv')
const gearsSorted = gears.sort(compare)
return resolve(gearsSorted)
} catch (error) {
console.error('error while loading gears CSV file:', error)
}
})
}