forked from fac-17/week-3-MEIA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.js
51 lines (40 loc) · 1.16 KB
/
logic.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
//API URL and Callback abstraction
// url - string with url
// cb is function given result
// cors is Boolean, if true then use CORS proxy
function request(url, cb, cors) {
if (cors) {
url = "https://cors-anywhere.herokuapp.com/" + url;
}
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
let response = JSON.parse(xhr.responseText);
// Passes response into the callback function, callback function processes it as needed.
cb(response);
}
};
xhr.open("GET", url, true);
xhr.send();
}
function getStatusClass(severityString) {
return "tube-" + severityString.split(" ")[0].toLowerCase();
}
const shadowedNames = [
"hammersmith-city",
"circle",
"victoria",
"waterloo-city"
];
function requiresShadow(lineID){
return shadowedNames.includes(lineID);
}
function getTimeOfDay(hour){
if (hour > 5 && hour < 12) return "Morning";
if (hour > 11 && hour < 18) return "Afternoon";
if (hour > 17 && hour < 22) return "Evening";
return "Night"
}
if (typeof module !== "undefined") {
module.exports = { getStatusClass, requiresShadow, getTimeOfDay };
}