mirror of
https://github.com/toptal/haste-server.git
synced 2024-11-14 10:35:18 +01:00
Updated dictionary.js
Now expects a newline separated dictionary, supports both \n and \n\r
This commit is contained in:
parent
ac2bceefbb
commit
80f0618736
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user