mirror of
https://github.com/SunRed/haste-server.git
synced 2024-11-23 17:50:19 +01:00
7808ccf009
-Tests were not brought up to date with some updates that were done to key generator modules. -Apparently original creator had no idea that 'y' is a vowel; fixed this issue and reflected changes in actual files.
29 lines
724 B
JavaScript
29 lines
724 B
JavaScript
const winston = require('winston');
|
|
const fs = require('fs');
|
|
|
|
module.exports = class DictionaryGenerator {
|
|
|
|
constructor({ path } = {}){
|
|
//check for dictionary path
|
|
if (!path){
|
|
let error = 'No dictionary path specified in options';
|
|
winston.error(error);
|
|
throw error;
|
|
}
|
|
|
|
//load dictionary
|
|
if (!fs.existsSync(path)){
|
|
let error = `Dictionary file "${path}" doesn't exist`;
|
|
winston.error(error);
|
|
throw error;
|
|
}
|
|
|
|
this.dictionary = fs.readFileSync(path).toString().split(/\s+/gm);
|
|
}
|
|
|
|
// Generates a dictionary-based key, of keyLength words
|
|
createKey(keyLength){
|
|
return Array(keyLength).fill().map(() => this.dictionary[ Math.floor(Math.random() * this.dictionary.length) ] ).join('');
|
|
}
|
|
|
|
};
|