1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2024-11-01 01:30:21 +01:00
haste-server/lib/key_generators/dictionary.js
2017-06-26 18:09:13 +02:00

26 lines
707 B
JavaScript

var fs = require('fs')
var DictionaryGenerator = function(options) {
//Options
if (!options)
return done(Error('No options passed to generator'));
if(!options.path)
return done(Error('No dictionary path specified in options'));
//Load dictionary
fs.readFile(options.path, 'utf8', (err,data) => {
if(err) throw err;
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)];
return text;
};
module.exports = DictionaryGenerator;