×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Added: Dec 24, 2017 11:17 AM
Modified: Dec 24, 2017 11:18 AM
Views: 1
Tags: base64
  1. function b64EncodeUnicode(str) {
  2.     // first we use encodeURIComponent to get percent-encoded UTF-8,
  3.     // then we convert the percent encodings into raw bytes which
  4.     // can be fed into btoa.
  5.     return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
  6.         function toSolidBytes(match, p1) {
  7.             return String.fromCharCode('0x' + p1);
  8.     }));
  9. }
  10.  
  11. b64EncodeUnicode('✓ à la mode'); // "4pyTIMOgIGxhIG1vZGU="