1
0
Fork 0
mirror of https://github.com/seejohnrun/haste-server.git synced 2024-11-25 05:51:22 +00:00

Update dictionary.js

This commit is contained in:
Klas af Geijerstam 2017-06-26 17:37:04 +02:00 committed by GitHub
parent e54a860172
commit 8e9205cecc

View file

@ -1,7 +1,7 @@
var rand = require('random-js');
var fs = require('fs')
var dictionary;
var randomEngine;
var randomEngine = rand.engines.nativeMath;
var random;
var DictionaryGenerator = function(options) {
@ -12,17 +12,15 @@ var DictionaryGenerator = function(options) {
return done(Error('No dictionary path specified in options'));
//Load dictionary
fs.readFile(options.path,'utf8',(err,data) => {
fs.readFile(options.path, 'utf8', (err,data) => {
if(err) throw err;
dictionary = data.split(',');
this.dictionary = data.split(',');
//Remove any non alpha-numeric characters
for(var i = 0; i < dictionary.length; i++){
dictionary[i] = dictionary[i].replace(/\W/g,'');
}
for(var i = 0; i < this.dictionary.length; i++)
this.dictionary[i] = this.dictionary[i].replace(/\W/g,'');
random = rand.integer(0,dictionary.length);
randomEngine = rand.engines.nativeMath;
this.random = rand.integer(0, this.dictionary.length);
});
};
@ -30,7 +28,7 @@ var DictionaryGenerator = function(options) {
DictionaryGenerator.prototype.createKey = function(keyLength) {
var text = '';
for(var i = 0; i < keyLength; i++)
text += dictionary[random(randomEngine)];
text += this.dictionary[random(randomEngine)];
return text;
};