Skip to content

Instantly share code, notes, and snippets.

@minodisk
Created September 28, 2011 06:34
Show Gist options
  • Save minodisk/1247146 to your computer and use it in GitHub Desktop.
Save minodisk/1247146 to your computer and use it in GitHub Desktop.
Escape as unicode
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