1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2024-12-27 22:50:11 +01:00

Updated dictionary.js

Now expects a newline separated dictionary, supports both \n and \n\r
This commit is contained in:
Klas af Geijerstam 2017-06-26 18:03:18 +02:00 committed by GitHub
parent ac2bceefbb
commit 80f0618736

View file

@ -11,20 +11,18 @@ var DictionaryGenerator = function(options) {
//Load dictionary
fs.readFile(options.path, 'utf8', (err,data) => {
if(err) throw err;
this.dictionary = data.split(',');
//Remove any non alpha-numeric characters
for(var i = 0; i < this.dictionary.length; i++)
this.dictionary[i] = this.dictionary[i].replace(/\W/g,'');
});
this.dictionary = data.split(/[\n\r]+/);
});
};
//Generates a dictionary-based key, of keyLength words
DictionaryGenerator.prototype.createKey = function(keyLength) {
var text = '';
for(var i = 0; i < keyLength; i++)
text += this.dictionary[Math.floor(Math.random()*this.dictionary.length)];
for(var i = 0; i < keyLength; i++) {
var index =Math.floor(Math.random()*this.dictionary.length);
text += this.dictionary[index];
}
return text;
};