forked from AIHubCentral/automaze-fork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
32 lines (28 loc) · 923 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
// Libraries neccesaries
const fs = require('fs');
// Will give you all the files in a folder recursively
function getAllFiles(currentPath){
let currentFiles = [];
for(const thatFile of fs.readdirSync(currentPath)){
let filePath = currentPath + '/' + thatFile;
if(fs.lstatSync(filePath).isDirectory()){
currentFiles = currentFiles.concat(currentFiles, getAllFiles(filePath));
} else {
currentFiles.push(filePath);
}
}
return [...new Set(currentFiles)];
}
exports.getAllFiles = getAllFiles;
// Create delay async in the script
async function delay(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
exports.delay = delay;
function getRandomNumber(min, max) {
/* gets a random number between min and max */
return Math.floor(Math.random() * (max - min + 1)) + min;
}
exports.getRandomNumber = getRandomNumber;