-
-
Save Layzie/4672548 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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