Skip to content

Instantly share code, notes, and snippets.

@ahomu
Created January 30, 2013 11:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ahomu/4672522 to your computer and use it in GitHub Desktop.
Save ahomu/4672522 to your computer and use it in GitHub Desktop.
% totsuzen 突然の死 | pbcopy
#!/bin/node
// via http://starwing.net/suddenly_death.html
String.prototype.lengthByte = function()
{
var str = this;
var r = 0;
for (var i = 0; i < str.length; i++) {
var c = str.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;
}
String.prototype.repeat = function(n)
{
return new Array(n + 1).join(this);
}
String.prototype.replaceAll = function(str1,str2){
var temp = this;
while(temp.indexOf(str1) != -1){
temp=temp.replace(str1,str2);
};
return temp;
};
function getWrappedText(str)
{
var len = Math.floor(str.lengthByte() / 2);
return "_" + ("人".repeat(len + 2)) + "_\n" +
"> " + str + " <\n" +
" ̄Y" + ("^Y".repeat(len)) + " ̄";
}
console.log(getWrappedText(process.argv[2]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment