-
Notifications
You must be signed in to change notification settings - Fork 6
/
common.js
58 lines (51 loc) · 1.46 KB
/
common.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
52
53
54
55
56
57
58
export const COLORS = {
NEWBIE: "#8b898b",
PUPIL: "#0fdb0f",
SPECIALIST: "#55d3ab",
EXPERT: "#2e2eff",
CANDIDATE_MASTER: "#fc3dff",
MASTER: "#ffbd66",
INTERNATIONAL_MASTER: "#ffaf38",
GRANDMASTER: "#fe5858",
INTERNATIONAL_GRANDMASTER: "#ff0000",
};
export function get_color_from_rating(rank){
switch (true) {
case rank<1200:
return COLORS.NEWBIE;
case rank<1400:
return COLORS.PUPIL;
case rank<1600:
return COLORS.SPECIALIST;
case rank<1900:
return COLORS.EXPERT;
case rank<2100:
return COLORS.CANDIDATE_MASTER;
case rank<2300:
return COLORS.MASTER;
case rank<2400:
return COLORS.INTERNATIONAL_MASTER;
case rank<2600:
return COLORS.GRANDMASTER;
default:
return COLORS.INTERNATIONAL_GRANDMASTER;
}
};
export const CONSTANTS = {
THIRTY_MINUTES: 1800,
TWO_HOURS: 7200,
FOUR_HOURS: 14400,
ONE_DAY: 86400,
};
export const clamp_value = (number, min, max) => {
if (Number.isNaN(parseInt(number))) return min;
return Math.max(min, Math.min(number, max));
};
export const capitalize = (str) => {
const words = str.split(" ");
const capitalized_words = words.map(word => word.charAt(0).toUpperCase() + word.slice(1));
return capitalized_words.join(" ");
};
export const word_count = (str) => {
return str.split(" ").length;
}