Created
September 28, 2011 06:34
-
-
Save minodisk/1247146 to your computer and use it in GitHub Desktop.
Escape as unicode
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
| function escapeAsUnicode (text) { | |
| var unicode = ''; | |
| for (var i = 0, len = text.length, code; i < len; ++i) { | |
| code = text.charCodeAt(i).toString(16); | |
| while (code.length < 4) { | |
| code = '0' + code; | |
| } | |
| unicode += '\\\u' + code; | |
| } | |
| return unicode; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment