-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
38 lines (31 loc) · 1.01 KB
/
utils.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
export const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
export function log(text, type='l') {
if (type === 'l') {
console.log(`${new Date().toISOString()}\t${text}`);
} else if (type === 'e') {
console.log('\x1b[31m%s\x1b[0m',`${new Date().toISOString()}\t${text}`);
} else if (type === 'g') {
console.log('\x1b[32m%s\x1b[0m',`${new Date().toISOString()}\t${text}`);
}
}
export function addDaysToDate(date, days) {
return new Date(date.getTime() + (days * 24 * 60 * 60 * 1000))
}
export function addSecondsToDate(date, seconds) {
return new Date(date.getTime() + (seconds * 1000))
}
export function unixTimeStampNow() {
return Math.floor(Date.now() / 1000);
}
export function addDaysToTimeStamp(timestamp, days) {
return timestamp + Math.floor(days * 24 * 60 * 60)
}
export const minutesToDays = (minutes) => {
return minutes / 24 / 60;
}
export function getLastSlash(url) {
const split = url.split('/');
return split[split.length - 1];
}