UNPKG

mehdown-cowsay

Version:

cowsay is a configurable talking cow

37 lines (29 loc) 768 B
var path = require("path"); var fs = require("fs"); var replacer = require("./replacer"); var textCache = {}; exports.get = function (cow) { var text = textCache[cow]; if (!text) { var filePath; if (cow.indexOf("/") === -1) { filePath = path.join(__dirname, "/../cows", cow) + ".cow"; } else { filePath = path.relative(process.cwd(), cow); } text = fs.readFileSync(filePath, "utf-8"); textCache[cow] = text; } return function (options) { return replacer(text, options); }; } exports.list = function (callback) { fs.readdir(path.join(__dirname, "../cows"), function (err, files) { if (err) return callback(err); var cows = files.map(function (cow) { return path.basename(cow, ".cow"); }); return callback(null, cows); }); }