Browse Source

Merge pull request #1 from blastedt/master

Add javascript roosay
pull/11/head
Jeffery R 7 years ago
committed by GitHub
parent
commit
4936c7d764
1 changed files with 54 additions and 0 deletions
  1. +54
    -0
      src/roosay.js

+ 54
- 0
src/roosay.js View File

@ -0,0 +1,54 @@
#!/usr/bin/env node
(function () {
var DEFAULT_LEN, ROO, BUBBLE_TOP_CHAR,
textToRoo;
DEFAULT_LEN = 35;
BUBBLE_TOP_CHAR = "-";
roo = `
\\ /)/)
\\ (ø.ø)
\\ ( />
__/ _\\ //
'~( '~ )//
_\\ '}/
\\"--~(/`;
function lineify(maxLen) {
function bar([word, ...words], [line, ...lines]) {
if (!word) return [pad(line), ...lines];
word = word.trim();
if (!line) return bar(words, [word, ...lines]);
return bar(words, (word.length + line.length < maxLen)
? [[line, word].join(" "), ...lines]
: [word, pad(line), ...lines]);
}
function pad(line) {
return line + new Array(maxLen - line.length).fill(" ").join("");
}
return (s => bar(s.split(" "), [""]).reverse());
}
function rooify(text) {
var textLines, finalOutput, bubbleHeader;
finalOutput = "";
textLines = lineify(DEFAULT_LEN)(text);
bubbleHeader = new Array(DEFAULT_LEN+2).fill(BUBBLE_TOP_CHAR).join("");
finalOutput += "/" + bubbleHeader + "\\\n";
textLines.forEach(l => finalOutput += "| " + l + " |\n");
finalOutput += "\\" + bubbleHeader + "/";
finalOutput += roo;
return finalOutput;
}
if (process.stdin.isTTY) {
textToRoo = process.argv.splice(2).join(" ");
console.log(rooify(textToRoo));
} else {
textToRoo = "";
process.stdin.on('data', b => textToRoo += b.toString());
process.stdin.on('end', _ => console.log(rooify(textToRoo)));
process.stdin.resume();
}
}());

Loading…
Cancel
Save