-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
53 lines (43 loc) · 1.15 KB
/
Copy pathhelpers.js
File metadata and controls
53 lines (43 loc) · 1.15 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
const getUserByEmail = (email, database) => {
for (let id in database) {
if (database[id].email === email) {
return database[id];
}
}
};
const generateRandomString = () => {
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
let random = '';
for (let i = 0; i < chars.length; i++) {
if (random.length < 6) {
random += chars[(Math.random() * 61).toFixed(0)];
}
}
return random;
};
const urlsForUser = (id, database) => {
const urlsForUser = {};
for (let url in database) {
if (database[url].userID === id) {
urlsForUser[url] = database[url];
}
}
return urlsForUser;
};
const checkForHTTP = (longURL, database, sessionID, visitorID, timeStamp) => {
// add total view count, unique view count, and time stamp for stretch work
// check if longURL includes http:// or https://
if ((longURL.slice(0, 7)) === 'http://' || (longURL.slice(0, 8)) === 'https://') {
database.viewCount++;
visitorID.push(sessionID);
timeStamp.push(Date());
return true;
}
return false;
};
module.exports = {
getUserByEmail,
generateRandomString,
urlsForUser,
checkForHTTP
};