Base64 encode data: Difference between revisions

No edit summary
Line 3:
 
=={{header|JavaScript}}==
<lang JavaScript>(function(){//JavaScriptECMAScript doesn't have an internal base64 function or method, so we have to do it ourselves, isn't that exciting?
function stringToArrayUnicode(str){for(var i=0,l=str.length,n=[];i<l;i++)n.push(str.charCodeAt(i));return n;}
function generateOnesByLength(n){//Attempts to generate a binary number full of ones given a length.. they don't redefine each other that much.
Line 68:
return toBase64(stringToArrayUnicode("Nothing seems hard to the people who don't know what they're talking about."))
}())</lang>
 
{{works with|Gecko}}
{{works with|Webkit}}
Works with IE10 or higher.
<lang JavaScript>window.btoa("String to encode, etc..");//Will throw error if any unicode character is larger than 255 it's counterpart it's the window.atob</lang>To make it.. just work, you could convert it to UTF-8 Manually or..
JSON.stringify it or..
encodeURIComponent it.
 
{{works with|Node.js}}
Anonymous user