Created
February 25, 2016 20:43
-
-
Save JDMcKinstry/9b18a615ab07db50a672 to your computer and use it in GitHub Desktop.
Easy way to get base64 encode and decode of a string
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
if (Object['defineProperty'] && !String.prototype.hasOwnProperty('deCode')) Object.defineProperty(String.prototype, 'deCode', { value: function() { return decodeURIComponent(unescape(window.atob(this))); } }); | |
if (Object['defineProperty'] && !String.prototype.hasOwnProperty('enCode')) Object.defineProperty(String.prototype, 'enCode', { value: function() { return window.btoa(escape(encodeURIComponent(this))); } }); | |
var a = 'GitHub'.enCode(); // a = "R2l0SHVi" | |
var b = a.deCode(); // b = "GitHub" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment