Implemented URL query parsing for initial token /opa/?token=abcde
[src/app-framework-demo.git] / afb-client / bower_components / jszip / lib / base64.js
1 'use strict';
2 // private property
3 var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
4
5
6 // public method for encoding
7 exports.encode = function(input, utf8) {
8     var output = "";
9     var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
10     var i = 0;
11
12     while (i < input.length) {
13
14         chr1 = input.charCodeAt(i++);
15         chr2 = input.charCodeAt(i++);
16         chr3 = input.charCodeAt(i++);
17
18         enc1 = chr1 >> 2;
19         enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
20         enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
21         enc4 = chr3 & 63;
22
23         if (isNaN(chr2)) {
24             enc3 = enc4 = 64;
25         }
26         else if (isNaN(chr3)) {
27             enc4 = 64;
28         }
29
30         output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
31
32     }
33
34     return output;
35 };
36
37 // public method for decoding
38 exports.decode = function(input, utf8) {
39     var output = "";
40     var chr1, chr2, chr3;
41     var enc1, enc2, enc3, enc4;
42     var i = 0;
43
44     input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
45
46     while (i < input.length) {
47
48         enc1 = _keyStr.indexOf(input.charAt(i++));
49         enc2 = _keyStr.indexOf(input.charAt(i++));
50         enc3 = _keyStr.indexOf(input.charAt(i++));
51         enc4 = _keyStr.indexOf(input.charAt(i++));
52
53         chr1 = (enc1 << 2) | (enc2 >> 4);
54         chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
55         chr3 = ((enc3 & 3) << 6) | enc4;
56
57         output = output + String.fromCharCode(chr1);
58
59         if (enc3 != 64) {
60             output = output + String.fromCharCode(chr2);
61         }
62         if (enc4 != 64) {
63             output = output + String.fromCharCode(chr3);
64         }
65
66     }
67
68     return output;
69
70 };