-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
38 lines (33 loc) · 811 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
27
28
29
30
31
32
33
34
35
36
37
38
const UserAgent = require('user-agents')
/**
* Resolves the returned promise after the set amount of ms. This should be used with
* async-await to take advantage of the waiting.
* @param {number} ms The time in ms to sleep.
* @returns {Promise<void>}
*/
const sleep = (ms) => new Promise((resolve) => {
setTimeout(resolve, ms)
})
/**
* Generates a random user agent string.
* @returns {string}
*/
const genUserAgent = () => {
const userAgent = new UserAgent()
return userAgent.toString()
}
/**
* Generate a random number within a range
* @param {number} min
* @param {number} max
* @returns number
*/
const randomNumber = (min, max) => Math.random() * (max - min) + min
/** no-op function */
const noop = () => { }
module.exports = {
sleep,
genUserAgent,
noop,
randomNumber,
}