const fs = require('fs') const path = require('path') const products = fs.readFileSync('./mock/data/products.default.txt').toString().split('\n') const techniques = fs.readFileSync('./mock/data/techniques.txt').toString().split('\n') const preparations = fs.readFileSync('./mock/data/preparations.txt').toString().split('\n') function choice(a){ return a[ randint(a.length) ]} function randint(n){ return Math.floor(Math.random()*n) } module.exports = function dish(n){ var pcount = randint(2) + 1; var ps = []; while (pcount-- > 0) ps.push(product()); if (randint(100) < 90) { var d = ps.join(" and ") + " " + choice(preparations); } else { var d = ps.join(", "); } return d; } function product(){ var result; if (randint(100) > 1) { var technique = choice(techniques); if (technique[0] == '-') { result = choice(products) + technique + " " + choice(products); } else { result = technique + " " + choice(products) } } else { result = choice(products) } return result; }