1
0
Fork 0
mirror of https://github.com/seejohnrun/haste-server.git synced 2024-11-22 04:31:21 +00: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 //Load dictionary
fs.readFile(options.path, 'utf8', (err,data) => { fs.readFile(options.path, 'utf8', (err,data) => {
if(err) throw err; if(err) throw err;
this.dictionary = data.split(','); this.dictionary = data.split(/[\n\r]+/);
});
//Remove any non alpha-numeric characters
for(var i = 0; i < this.dictionary.length; i++)
this.dictionary[i] = this.dictionary[i].replace(/\W/g,'');
});
}; };
//Generates a dictionary-based key, of keyLength words //Generates a dictionary-based key, of keyLength words
DictionaryGenerator.prototype.createKey = function(keyLength) { DictionaryGenerator.prototype.createKey = function(keyLength) {
var text = ''; var text = '';
for(var i = 0; i < keyLength; i++) for(var i = 0; i < keyLength; i++) {
text += this.dictionary[Math.floor(Math.random()*this.dictionary.length)]; var index =Math.floor(Math.random()*this.dictionary.length);
text += this.dictionary[index];
}
return text; return text;
}; };