-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
28 lines (24 loc) · 797 Bytes
/
helpers.js
File metadata and controls
28 lines (24 loc) · 797 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
const getUserByEmail = function(email, database) {
return Object.values(database).find(user => user.email === email);
};
const isUserHasUrl = function(urlID, userURL) {
return Object.keys(userURL).includes(urlID);
};
const isLogin = function(obj) {
if (!Object.keys(obj.session).includes("user_id")) {
return false;
}
return true;
};
const generateRandomString = (length) => {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
let counter = 0;
while (counter < length) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
counter += 1;
}
return result;
};
module.exports = { getUserByEmail, isUserHasUrl, isLogin, generateRandomString };