-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-random-char-file.js
More file actions
33 lines (28 loc) · 1.03 KB
/
generate-random-char-file.js
File metadata and controls
33 lines (28 loc) · 1.03 KB
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
const fs = require('fs');
const charLimit = process.argv[2] || 18588430;
const fileName = process.argv[3] || '18mbs.please';
const helpParams = ['help', '-h', '--help', '-help'];
function generateRandomChars() {
var text = '';
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (var i = 0; i < charLimit; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
function generateRandomCharFile() {
let fileContent = generateRandomChars();
fs.writeFile(fileName, fileContent);
}
function showHelp() {
console.log('### RANDOM CHAR FILE GENERATOR ### \n');
console.log('Usage: ');
console.log('$ node generate-random-char-file.js [charNumberLimit] [fileName]');
console.log('$ ... --help Show this help \n');
}
if (process.argv[2] && ~helpParams.indexOf(process.argv[2])) {
showHelp();
} else {
generateRandomCharFile();
console.log('Generated file: ' + fileName + ' with ' + charLimit + ' characters.');
}