Skip to content

Instantly share code, notes, and snippets.

@SiZapPaaiGwat
Created September 7, 2015 07:43
Show Gist options
  • Save SiZapPaaiGwat/5b9ad38e032b561a40bb to your computer and use it in GitHub Desktop.
Save SiZapPaaiGwat/5b9ad38e032b561a40bb to your computer and use it in GitHub Desktop.
simple base64 encode relied on window.btoa
function base64Encode( str ) {
str = str.replace( /[^\x00-\x7F]/g, function ( char ) {
var hex = char.charCodeAt( 0 ).toString( 16 );
while ( hex.length < 4 ) hex = '0' + hex;
return '\\u' + hex;
});
return btoa( str );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment