Created
September 7, 2015 07:43
-
-
Save SiZapPaaiGwat/5b9ad38e032b561a40bb to your computer and use it in GitHub Desktop.
simple base64 encode relied on window.btoa
This file contains 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 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