Skip to content

Instantly share code, notes, and snippets.

@cthpw103
Created September 11, 2019 11:51
Show Gist options
  • Save cthpw103/0cdf7917f5369c8330bbfa3892749d46 to your computer and use it in GitHub Desktop.
Save cthpw103/0cdf7917f5369c8330bbfa3892749d46 to your computer and use it in GitHub Desktop.
cowsay
let dashes = "";
let callback;
fixLineBreak = c => {
if (c[0].length < 41) {
callback = e => {
let su = '< ' + e + ' >'
return su
}
} else {
callback = (e, index, array) => {
let chars2use = ['| ', ' |'];
if (index === 0) chars2use = ['/ ', ' \\'];
if (index === array.length - 1) chars2use = ['\\ ', ' /'];
let su = chars2use[0] + e + chars2use[1]
// j'adore javascript
if (e.length < 41) {
su = chars2use[0] + e + " ".repeat(41 - e.length) + chars2use[1];
}
return su
}
}
return c.map(callback)
}
cowsay = t => {
dashes = "";
let length = t.length;
if ( length > 41 ) length = 41;
dashes = "-".repeat(length + 2);
dashes = " " + dashes;
return "\n" + dashes.replace(/-/g, "_") + "\n" +
fixLineBreak(t.match(/.{1,41}/g)).join("\n") + '\n' +
dashes + "\n" +
" \\ ^__^" + "\n" +
" \\ (oo)\_______" + "\n" +
" (__)\ )\\/\\" + "\n" +
" ||----w |" + "\n" +
" || ||";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment