Skip to content

Commit ae8af80

Browse files
author
Thomas Grießbach
committed
[TASK] updates kayalshri/tableExport.jquery.plugin base64 lib
1 parent f2bd0bb commit ae8af80

File tree

1 file changed

+59
-143
lines changed

1 file changed

+59
-143
lines changed

jspdf/libs/base64.js

Lines changed: 59 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,59 @@
1-
2-
/**
3-
*
4-
* Base64 encode / decode
5-
* http://www.webtoolkit.info/
6-
*
7-
**/
8-
9-
var Base64 = {
10-
11-
// private property
12-
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
13-
14-
// public method for encoding
15-
encode : function (input) {
16-
var output = "";
17-
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
18-
var i = 0;
19-
20-
input = Base64._utf8_encode(input);
21-
22-
while (i < input.length) {
23-
24-
chr1 = input.charCodeAt(i++);
25-
chr2 = input.charCodeAt(i++);
26-
chr3 = input.charCodeAt(i++);
27-
28-
enc1 = chr1 >> 2;
29-
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
30-
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
31-
enc4 = chr3 & 63;
32-
33-
if (isNaN(chr2)) {
34-
enc3 = enc4 = 64;
35-
} else if (isNaN(chr3)) {
36-
enc4 = 64;
37-
}
38-
39-
output = output +
40-
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
41-
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
42-
43-
}
44-
45-
return output;
46-
},
47-
48-
// public method for decoding
49-
decode : function (input) {
50-
var output = "";
51-
var chr1, chr2, chr3;
52-
var enc1, enc2, enc3, enc4;
53-
var i = 0;
54-
55-
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
56-
57-
while (i < input.length) {
58-
59-
enc1 = this._keyStr.indexOf(input.charAt(i++));
60-
enc2 = this._keyStr.indexOf(input.charAt(i++));
61-
enc3 = this._keyStr.indexOf(input.charAt(i++));
62-
enc4 = this._keyStr.indexOf(input.charAt(i++));
63-
64-
chr1 = (enc1 << 2) | (enc2 >> 4);
65-
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
66-
chr3 = ((enc3 & 3) << 6) | enc4;
67-
68-
output = output + String.fromCharCode(chr1);
69-
70-
if (enc3 != 64) {
71-
output = output + String.fromCharCode(chr2);
72-
}
73-
if (enc4 != 64) {
74-
output = output + String.fromCharCode(chr3);
75-
}
76-
77-
}
78-
79-
output = Base64._utf8_decode(output);
80-
81-
return output;
82-
83-
},
84-
85-
// private method for UTF-8 encoding
86-
_utf8_encode : function (string) {
87-
string = string.replace(/\r\n/g,"\n");
88-
var utftext = "";
89-
90-
for (var n = 0; n < string.length; n++) {
91-
92-
var c = string.charCodeAt(n);
93-
94-
if (c < 128) {
95-
utftext += String.fromCharCode(c);
96-
}
97-
else if((c > 127) && (c < 2048)) {
98-
utftext += String.fromCharCode((c >> 6) | 192);
99-
utftext += String.fromCharCode((c & 63) | 128);
100-
}
101-
else {
102-
utftext += String.fromCharCode((c >> 12) | 224);
103-
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
104-
utftext += String.fromCharCode((c & 63) | 128);
105-
}
106-
107-
}
108-
109-
return utftext;
110-
},
111-
112-
// private method for UTF-8 decoding
113-
_utf8_decode : function (utftext) {
114-
var string = "";
115-
var i = 0;
116-
var c = c1 = c2 = 0;
117-
118-
while ( i < utftext.length ) {
119-
120-
c = utftext.charCodeAt(i);
121-
122-
if (c < 128) {
123-
string += String.fromCharCode(c);
124-
i++;
125-
}
126-
else if((c > 191) && (c < 224)) {
127-
c2 = utftext.charCodeAt(i+1);
128-
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
129-
i += 2;
130-
}
131-
else {
132-
c2 = utftext.charCodeAt(i+1);
133-
c3 = utftext.charCodeAt(i+2);
134-
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
135-
i += 3;
136-
}
137-
138-
}
139-
140-
return string;
141-
}
142-
143-
}
1+
jQuery.base64 = (function($) {
2+
3+
// private property
4+
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
5+
6+
// private method for UTF-8 encoding
7+
function utf8Encode(string) {
8+
string = string.replace(/\r\n/g,"\n");
9+
var utftext = "";
10+
for (var n = 0; n < string.length; n++) {
11+
var c = string.charCodeAt(n);
12+
if (c < 128) {
13+
utftext += String.fromCharCode(c);
14+
}
15+
else if((c > 127) && (c < 2048)) {
16+
utftext += String.fromCharCode((c >> 6) | 192);
17+
utftext += String.fromCharCode((c & 63) | 128);
18+
}
19+
else {
20+
utftext += String.fromCharCode((c >> 12) | 224);
21+
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
22+
utftext += String.fromCharCode((c & 63) | 128);
23+
}
24+
}
25+
return utftext;
26+
}
27+
28+
function encode(input) {
29+
var output = "";
30+
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
31+
var i = 0;
32+
input = utf8Encode(input);
33+
while (i < input.length) {
34+
chr1 = input.charCodeAt(i++);
35+
chr2 = input.charCodeAt(i++);
36+
chr3 = input.charCodeAt(i++);
37+
enc1 = chr1 >> 2;
38+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
39+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
40+
enc4 = chr3 & 63;
41+
if (isNaN(chr2)) {
42+
enc3 = enc4 = 64;
43+
} else if (isNaN(chr3)) {
44+
enc4 = 64;
45+
}
46+
output = output +
47+
keyStr.charAt(enc1) + keyStr.charAt(enc2) +
48+
keyStr.charAt(enc3) + keyStr.charAt(enc4);
49+
}
50+
return output;
51+
}
52+
53+
return {
54+
encode: function (str) {
55+
return encode(str);
56+
}
57+
};
58+
59+
}(jQuery));

0 commit comments

Comments
 (0)