-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
26 lines (24 loc) · 827 Bytes
/
utils.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
const crypto = require('crypto');
/**
* Function to generate random tokens
* @param {Integer} The length of the string it should generate
* @returns {String} A string containing the token
*/
const generateRandomToken = (length) => {
let alphaNum,randomString;
alphaNum = 'ABCDEFGHIJKMNOPQRSTUVWXYZ1234567890abcdefghijkmnopqrstuvwxyz';
for (let i = 0 ; i < length ; i++) {
randomString += alphaNum.charAt(Math.random() * alphaNum.length);
}
return crypto.createHash('sha256').update(randomString).digest('base64');
}
/**
* Function to get date time in Feature
* @param {Integer} hours
* @returns
*/
const featureTime = (hours) => {
let currentTime = new Date().getTime();
return new Date(currentTime + hours * 60 * 60 * 1000);
}
module.exports = {generateRandomToken,featureTime};