-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.js
More file actions
60 lines (48 loc) · 1.13 KB
/
Copy pathhelper.js
File metadata and controls
60 lines (48 loc) · 1.13 KB
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
59
60
function computeHash(str) {
let hash = 0;
if (!str)
return hash;
for (let i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
hash = hash & hash;
}
return hash;
}
function randomColorFromString(str) {
var hue = computeHash(str) % 360;
return `hsl(${hue}, 100%, 30%)`
}
function remove_from(users, socket) {
let idx = users.findIndex(user => user.id === socket.id);
users.splice(idx, 1);
}
const htmlEscapes = {
"&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'",
"`": "`"
};
const reUnescapedHtml = /[&<>"'`]/g;
function escapeHtmlChar(chr) {
return htmlEscapes[chr];
}
function escapeHtml(string) {
return string.replace(reUnescapedHtml, escapeHtmlChar);
}
function IntTwoChars(num) {
return (`0${num}`).slice(-2);
}
function getTimeStamp() {
let time = new Date();
let hours = IntTwoChars(time.getHours());
let minutes = IntTwoChars(time.getMinutes());
return `${hours}:${minutes}`;
}
module.exports = {
randomColorFromString,
remove_from,
escapeHtml,
getTimeStamp
};