ButlerBin/lib/key_generator.js
Jack Hadrill a21a6c595a
All checks were successful
TerribleCodeClub/ButlerBin/pipeline/head This commit looks good
Simplify for Butlersaurus
2020-06-08 23:36:02 +01:00

20 lines
477 B
JavaScript

module.exports = class KeyGenerator {
// Initialise a new generator with the given key space.
constructor(options = {}) {
this.keyLength = options.keyLength;
this.keySpace = options.keySpace;
}
// Generate a key of the given length.
createKey() {
var text = "";
for (var i = 0; i < this.keyLength; i++) {
const index = Math.floor(Math.random() * this.keySpace.length);
text += this.keySpace.charAt(index);
}
return text;
}
};