Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function escapeUnicode(s) {
- return s.replace(/[^\x20-\x7e]/g, function (c) {
- c = c.charCodeAt(0);
- if (c == 8) c = '\\b';
- else if (c == 9) c = '\\t';
- else if (c == 10) c = '\\n';
- else if (c == 12) c = '\\f';
- else if (c == 13) c = '\\r';
- else if (c < 128) c = '\\x' + (c < 16 ? '0' : '') + c.toString(16);
- else c = c.toString(16), c = '\\u' + ('000' + c).slice(-4);
- return c;
- });
- }
- console.log(escapeUnicode('吉 – удача.')); // "\u5409 \u2013 \u0443\u0434\u0430\u0447\u0430."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement