-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
35 lines (32 loc) · 941 Bytes
/
helpers.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
const getUserByEmail = function(email, database) {
for (let userID in database) {
if(database[userID].email === email) {
return database[userID]
}
}
};
// random user id generator
function uniqueUserId() {
let randStr = '';
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let charactersLength = characters.length;
for (let i = 0; i < 10; i++) {
randStr += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return randStr;
}
// random short url generator
function generateRandomString() {
let randStr = '';
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let charactersLength = characters.length;
for (let i = 0; i < 6; i++) {
randStr += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return randStr;
}
module.exports = {
getUserByEmail,
uniqueUserId,
generateRandomString
}