This repository has been archived on 2024-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
Files
ShareX-Upload-Server/util/randomToken.js
2021-08-18 00:12:37 -07:00

21 lines
736 B
JavaScript

/** Used to generate file names
* @param {number} number - Number of characters the file name should be
* @returns {string} String containing file name
*/
function randomToken(number, symbols) {
// eslint-disable-next-line no-param-reassign
number = parseInt(number, 10);
let text = '';
let possible
if(symbols !== true) {
possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
} else {
possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()-_=+[]{}|;:/?><,.';
}
for (let i = 0; i < number; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
module.exports = randomToken;