Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var fs = require("fs");
var helpers = require("./helpers");
var readline = require("readline");
var path = require("path");
var adjectives = [];
var nouns = [];
function loadData() {
"use strict";
var adjectivesPath = path.join(__dirname, "txt", "adjectives.txt");
var rl = readline.createInterface({
input: fs.createReadStream(adjectivesPath)
});
rl.on("line", function(line) {
adjectives.push(helpers.capitalizeFirtsLetter(line).trim());
});
var nounPath = path.join(__dirname, "txt", "nouns.txt");
var rl2 = readline.createInterface({
input: fs.createReadStream(nounPath)
});
rl2.on("line", function(line) {
nouns.push(helpers.capitalizeFirtsLetter(line).trim());
});
}
loadData();
function generateKey() {
"use strict";
var adjIndex = Math.floor(Math.random() * adjectives.length);
var secondAdjIndex = Math.floor(Math.random() * adjectives.length);
while (adjIndex === secondAdjIndex) {
secondAdjIndex = Math.floor(Math.random() * adjectives.length);
}
var nounIndex = Math.floor(Math.random() * adjectives.length);
return adjectives[adjIndex] + adjectives[secondAdjIndex] + nouns[nounIndex];
}
module.exports = generateKey;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment