Last active
December 15, 2015 03:39
-
-
Save leodutra/5196223 to your computer and use it in GitHub Desktop.
Converts Array, String or Number to Unicode String
This file contains 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
function toUnicode(val/* :Array|Number|String */) { | |
var res = ''; | |
var type = $.type(val); | |
var i; | |
switch(type) { | |
case 'array': | |
val = s.join(''); | |
case 'string': | |
case 'number': | |
i = (val + '').length; | |
res = Array(i); | |
while (i--) res[i] = '\\u' + ('000' + val.charCodeAt(i).toString(16)).substr(-4); | |
res = res.join(''); | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment