Skip to content

Instantly share code, notes, and snippets.

@1000ch
Forked from studiomohawk/totsuzen.js
Last active December 16, 2015 07:59
Show Gist options
  • Save 1000ch/5402423 to your computer and use it in GitHub Desktop.
Save 1000ch/5402423 to your computer and use it in GitHub Desktop.
#!/bin/node
// via http://starwing.net/suddenly_death.html
function getByteLength (string) {
var r = 0;
for (var i = 0; i < string.length; i++) {
var c = string.charCodeAt(i);
// Shift_JIS: 0x0 ~ 0x80, 0xa0 , 0xa1 ~ 0xdf , 0xfd ~ 0xff
// Unicode : 0x0 ~ 0x80, 0xf8f0, 0xff61 ~ 0xff9f, 0xf8f1 ~ 0xf8f3
if ((c >= 0x0 && c < 0x81) ||
(c == 0xf8f0) ||
(c >= 0xff61 && c < 0xffa0) ||
(c >= 0xf8f1 && c < 0xf8f4)) {
r += 1;
} else {
r += 2;
}
}
return r;
}
function repeatText (string, n) {
return new Array(n + 1).join(string);
};
function getWrappedText (string) {
var length = Math.floor(getByteLength(string) / 2);
var upper = "_" + repeatText("人", length + 2) + "_\n";
var middle = "> " + string + " <\n";
var under = " ̄Y" + repeatText("^Y", length + 1) + " ̄";
return upper + middle + under;
}
console.log(getWrappedText(process.argv[2]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment