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);
});
}...
var think = /think$/.test(argv["$0"]);
console.log(think ? module.think(argv) : module.say(argv));
}
function listCows () {
require("./index").list(function(err, list) {
if (err) throw new Error(err);
console.log(list.join(" "));
});
}
function showHelp () {
require("optimist").showHelp();
...say = function (options) {
return doIt(options, true);
}...
## Usage as a module
cowsay can be used as any other npm dependency
var cowsay = require("cowsay");
console.log(cowsay.say({
text : "I'm a moooodule",
e : "oO",
T : "U "
}));
// or cowsay.think()
...think = function (options) {
return doIt(options, false);
}...
console.log(cowsay.say({
text : "I'm a moooodule",
e : "oO",
T : "U "
}));
// or cowsay.think()
````
_________________
( I'm a moooodule )
-----------------
o ^__^
o (oO)\_______
...say = function (text, wrap) {
delimiters = {
first : ["/", "\\"],
middle : ["|", "|"],
last : ["\\", "/"],
only : ["<", ">"]
};
return format(text, wrap, delimiters);
}...
## Usage as a module
cowsay can be used as any other npm dependency
var cowsay = require("cowsay");
console.log(cowsay.say({
text : "I'm a moooodule",
e : "oO",
T : "U "
}));
// or cowsay.think()
...think = function (text, wrap) {
delimiters = {
first : ["(", ")"],
middle : ["(", ")"],
last : ["(", ")"],
only : ["(", ")"]
};
return format(text, wrap, delimiters);
}...
console.log(cowsay.say({
text : "I'm a moooodule",
e : "oO",
T : "U "
}));
// or cowsay.think()
````
_________________
( I'm a moooodule )
-----------------
o ^__^
o (oO)\_______
...get = function (cow) {
var text = textCache[cow];
if (!text) {
var filePath;
if (cow.match(/\\/) || cow.match(/\//)) {
filePath = cow;
} else {
filePath = path.join(__dirname, "/../cows", cow) + ".cow";
}
text = fs.readFileSync(filePath, "utf-8");
textCache[cow] = text;
}
return function (options) {
return replacer(text, options);
};
}...
exports.think = function (options) {
return doIt(options, false);
};
exports.list = cows.list;
function doIt (options, sayAloud) {
var cow = cows.get(options.f || "default");
var face = faces(options);
face.thoughts = sayAloud ? "\\" : "o";
var action = sayAloud ? "say" : "think";
return baloon[action](options.text || options._.join(" "), options.n ? null : options.W) + "\n" + cow(face);
}
...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);
});
}...
var think = /think$/.test(argv["$0"]);
console.log(think ? module.think(argv) : module.say(argv));
}
function listCows () {
require("./index").list(function(err, list) {
if (err) throw new Error(err);
console.log(list.join(" "));
});
}
function showHelp () {
require("optimist").showHelp();
...