-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (33 loc) · 852 Bytes
/
index.js
File metadata and controls
39 lines (33 loc) · 852 Bytes
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
// To have a fetch Response reject on error
function checkStatus(response) {
if (response.ok) {
return response;
} else {
let error = new Error(response.statusText);
error.response = response;
throw error;
}
}
// Delay for a number of milliseconds
async function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Return a timestamp like "2020-04-08T11_45_35_407Z"
function getTimeStamp() {
return (new Date()).toISOString().replace(/(:|\.)/g, '_');
}
// Get hours, minutes, seconds from milliseconds input
function getHMS(ms) {
let seconds = ms / 1000;
const hours = Math.floor(seconds / 3600);
seconds %= 3600;
const minutes = Math.floor(seconds / 60);
seconds = seconds % 60;
return {hours, minutes, seconds};
}
module.exports = {
checkStatus,
delay,
getTimeStamp,
getHMS
};