Created
April 4, 2018 16:14
-
-
Save juanbrujo/83a6558c7f72d0afabf71eeb8461858f to your computer and use it in GitHub Desktop.
VueJS method to decode Base64 encoded strings
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
methods: { | |
decodeBase64: function (string) { | |
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' | |
var result = '' | |
var i = 0 | |
do { | |
var b1 = characters.indexOf(string.charAt(i++)) | |
var b2 = characters.indexOf(string.charAt(i++)) | |
var b3 = characters.indexOf(string.charAt(i++)) | |
var b4 = characters.indexOf(string.charAt(i++)) | |
var a = ((b1 & 0x3F) << 2) | ((b2 >> 4) & 0x3) | |
var b = ((b2 & 0xF) << 4) | ((b3 >> 2) & 0xF) | |
var c = ((b3 & 0x3) << 6) | (b4 & 0x3F) | |
result += String.fromCharCode(a) + (b ? String.fromCharCode(b) : '') + (c ? String.fromCharCode(c) : '') | |
} while (i < string.length) | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment