js-base64 3.9.1 → 3.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/base64.d.mts +2 -2
- package/base64.d.ts +2 -2
- package/base64.js +310 -307
- package/base64.mjs +3 -24
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Locally…
|
|
|
26
26
|
… or Directly from CDN. In which case you don't even need to install.
|
|
27
27
|
|
|
28
28
|
```html
|
|
29
|
-
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.9.
|
|
29
|
+
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.9.2/base64.min.js"></script>
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
This good old way loads `Base64` in the global context (`window`). Though `Base64.noConflict()` is made available, you should consider using ES6 Module to avoid tainting `window`.
|
|
@@ -49,14 +49,14 @@ or even remotely.
|
|
|
49
49
|
```html
|
|
50
50
|
<script type="module">
|
|
51
51
|
// note jsdelivr.net does not automatically minify .mjs
|
|
52
|
-
import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.9.
|
|
52
|
+
import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.9.2/base64.mjs';
|
|
53
53
|
</script>
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
```html
|
|
57
57
|
<script type="module">
|
|
58
58
|
// or if you prefer no Base64 namespace
|
|
59
|
-
import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.9.
|
|
59
|
+
import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.9.2/base64.mjs';
|
|
60
60
|
</script>
|
|
61
61
|
```
|
|
62
62
|
|
|
@@ -165,6 +165,6 @@ Or even better, `Base64.toUint8Array(pngBase64)`.
|
|
|
165
165
|
|
|
166
166
|
## Brief History
|
|
167
167
|
|
|
168
|
-
* Since version 3.3 it is written in TypeScript.
|
|
168
|
+
* Since version 3.3 it is written in TypeScript. Both `base64.mjs` and `base64.js` are compiled from `base64.ts` via [Rollup](https://rollupjs.org).
|
|
169
169
|
* Since version 3.7 `base64.js` is ES5-compatible again (hence IE11-compatible).
|
|
170
170
|
* Since 3.0 `js-base64` switch to ES2015 module so it is no longer compatible with legacy browsers like IE (see above)
|
package/base64.d.mts
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @author Dan Kogai (https://github.com/dankogai)
|
|
11
11
|
*/
|
|
12
|
-
declare const version
|
|
12
|
+
declare const version: string;
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated use lowercase `version`.
|
|
15
15
|
*/
|
|
16
|
-
declare const VERSION
|
|
16
|
+
declare const VERSION: string;
|
|
17
17
|
/**
|
|
18
18
|
* polyfill version of `btoa`
|
|
19
19
|
*/
|
package/base64.d.ts
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @author Dan Kogai (https://github.com/dankogai)
|
|
11
11
|
*/
|
|
12
|
-
declare const version
|
|
12
|
+
declare const version: string;
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated use lowercase `version`.
|
|
15
15
|
*/
|
|
16
|
-
declare const VERSION
|
|
16
|
+
declare const VERSION: string;
|
|
17
17
|
/**
|
|
18
18
|
* polyfill version of `btoa`
|
|
19
19
|
*/
|
package/base64.js
CHANGED
|
@@ -1,312 +1,315 @@
|
|
|
1
1
|
//
|
|
2
2
|
// THIS FILE IS AUTOMATICALLY GENERATED! DO NOT EDIT BY HAND!
|
|
3
3
|
//
|
|
4
|
-
;
|
|
5
4
|
(function (global, factory) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
5
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
6
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
7
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, (function () {
|
|
8
|
+
var current = global.Base64;
|
|
9
|
+
var exports = global.Base64 = {};
|
|
10
|
+
factory(exports);
|
|
11
|
+
exports.noConflict = function () { global.Base64 = current; return exports; };
|
|
12
|
+
})());
|
|
13
|
+
})(this, (function (exports) { 'use strict';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* base64.ts
|
|
17
|
+
*
|
|
18
|
+
* Licensed under the BSD 3-Clause License.
|
|
19
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
|
20
|
+
*
|
|
21
|
+
* References:
|
|
22
|
+
* http://en.wikipedia.org/wiki/Base64
|
|
23
|
+
*
|
|
24
|
+
* @author Dan Kogai (https://github.com/dankogai)
|
|
25
|
+
*/
|
|
26
|
+
var version = '3.9.2';
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated use lowercase `version`.
|
|
29
|
+
*/
|
|
30
|
+
var VERSION = version;
|
|
31
|
+
var _TD = typeof TextDecoder === 'function' ? new TextDecoder('utf-8', { ignoreBOM: true }) : undefined;
|
|
32
|
+
var _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
|
|
33
|
+
var b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
34
|
+
var b64chs = Array.prototype.slice.call(b64ch);
|
|
35
|
+
var b64tab = (function (a) {
|
|
36
|
+
var tab = {};
|
|
37
|
+
a.forEach(function (c, i) { return tab[c] = i; });
|
|
38
|
+
return tab;
|
|
39
|
+
})(b64chs);
|
|
40
|
+
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
41
|
+
var _fromCC = String.fromCharCode.bind(String);
|
|
42
|
+
var _U8Afrom = typeof Uint8Array.from === 'function'
|
|
43
|
+
? Uint8Array.from.bind(Uint8Array)
|
|
44
|
+
: function (it) { return new Uint8Array(Array.prototype.slice.call(it, 0)); };
|
|
45
|
+
var _mkUriSafe = function (src) { return src
|
|
46
|
+
.replace(/=/g, '').replace(/[+\/]/g, function (m0) { return m0 == '+' ? '-' : '_'; }); };
|
|
47
|
+
var _tidyB64 = function (s) { return s.replace(/[^A-Za-z0-9\+\/]/g, ''); };
|
|
48
|
+
/**
|
|
49
|
+
* polyfill version of `btoa`
|
|
50
|
+
*/
|
|
51
|
+
var btoaPolyfill = function (bin) {
|
|
52
|
+
// console.log('polyfilled');
|
|
53
|
+
var u32, c0, c1, c2, asc = '';
|
|
54
|
+
var pad = bin.length % 3;
|
|
55
|
+
for (var i = 0; i < bin.length;) {
|
|
56
|
+
if ((c0 = bin.charCodeAt(i++)) > 255 ||
|
|
57
|
+
(c1 = bin.charCodeAt(i++)) > 255 ||
|
|
58
|
+
(c2 = bin.charCodeAt(i++)) > 255)
|
|
59
|
+
throw new TypeError('invalid character found');
|
|
60
|
+
u32 = (c0 << 16) | (c1 << 8) | c2;
|
|
61
|
+
asc += b64chs[u32 >> 18 & 63]
|
|
62
|
+
+ b64chs[u32 >> 12 & 63]
|
|
63
|
+
+ b64chs[u32 >> 6 & 63]
|
|
64
|
+
+ b64chs[u32 & 63];
|
|
65
|
+
}
|
|
66
|
+
return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* does what `window.btoa` of web browsers do.
|
|
70
|
+
* @param {String} bin binary string
|
|
71
|
+
* @returns {string} Base64-encoded string
|
|
72
|
+
*/
|
|
73
|
+
var _btoa = typeof btoa === 'function' ? function (bin) { return btoa(bin); }
|
|
74
|
+
: btoaPolyfill;
|
|
75
|
+
var _fromUint8Array = typeof Uint8Array.prototype.toBase64 === 'function' ? function (u8a) { return u8a.toBase64(); }
|
|
76
|
+
: function (u8a) {
|
|
77
|
+
// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
|
|
78
|
+
var maxargs = 0x1000;
|
|
79
|
+
var strs = [];
|
|
80
|
+
for (var i = 0, l = u8a.length; i < l; i += maxargs) {
|
|
81
|
+
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
|
|
82
|
+
}
|
|
83
|
+
return _btoa(strs.join(''));
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* converts a Uint8Array to a Base64 string.
|
|
87
|
+
* @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
|
|
88
|
+
* @returns {string} Base64 string
|
|
89
|
+
*/
|
|
90
|
+
var fromUint8Array = function (u8a, urlsafe) {
|
|
91
|
+
if (urlsafe === void 0) { urlsafe = false; }
|
|
92
|
+
return urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);
|
|
93
|
+
};
|
|
94
|
+
// This trick is found broken https://github.com/dankogai/js-base64/issues/130
|
|
95
|
+
// const utob = (src: string) => unescape(encodeURIComponent(src));
|
|
96
|
+
// reverting good old fationed regexp
|
|
97
|
+
var cb_utob = function (c) {
|
|
98
|
+
if (c.length < 2) {
|
|
99
|
+
var cc = c.charCodeAt(0);
|
|
100
|
+
return cc < 0x80 ? c
|
|
101
|
+
: cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6))
|
|
102
|
+
+ _fromCC(0x80 | (cc & 0x3f)))
|
|
103
|
+
: (_fromCC(0xe0 | ((cc >>> 12) & 0x0f))
|
|
104
|
+
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
|
|
105
|
+
+ _fromCC(0x80 | (cc & 0x3f)));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
var cc = 0x10000
|
|
109
|
+
+ (c.charCodeAt(0) - 0xD800) * 0x400
|
|
110
|
+
+ (c.charCodeAt(1) - 0xDC00);
|
|
111
|
+
return (_fromCC(0xf0 | ((cc >>> 18) & 0x07))
|
|
112
|
+
+ _fromCC(0x80 | ((cc >>> 12) & 0x3f))
|
|
113
|
+
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
|
|
114
|
+
+ _fromCC(0x80 | (cc & 0x3f)));
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated should have been internal use only.
|
|
120
|
+
* @param {string} src UTF-8 string
|
|
121
|
+
* @returns {string} UTF-16 string
|
|
122
|
+
*/
|
|
123
|
+
var utob = function (u) { return u.replace(re_utob, cb_utob); };
|
|
124
|
+
//
|
|
125
|
+
var _encode = _TE
|
|
126
|
+
? function (s) { return _fromUint8Array(_TE.encode(s)); }
|
|
127
|
+
: function (s) { return _btoa(utob(s)); };
|
|
128
|
+
/**
|
|
129
|
+
* converts a UTF-8-encoded string to a Base64 string.
|
|
130
|
+
* @param {boolean} [urlsafe] if `true` make the result URL-safe
|
|
131
|
+
* @returns {string} Base64 string
|
|
132
|
+
*/
|
|
133
|
+
var encode = function (src, urlsafe) {
|
|
134
|
+
if (urlsafe === void 0) { urlsafe = false; }
|
|
135
|
+
return urlsafe
|
|
136
|
+
? _mkUriSafe(_encode(src))
|
|
137
|
+
: _encode(src);
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5.
|
|
141
|
+
* @returns {string} Base64 string
|
|
142
|
+
*/
|
|
143
|
+
var encodeURI = function (src) { return encode(src, true); };
|
|
144
|
+
// This trick is found broken https://github.com/dankogai/js-base64/issues/130
|
|
145
|
+
// const btou = (src: string) => decodeURIComponent(escape(src));
|
|
146
|
+
// reverting good old fationed regexp
|
|
147
|
+
var re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
|
|
148
|
+
var cb_btou = function (cccc) {
|
|
149
|
+
switch (cccc.length) {
|
|
150
|
+
case 4:
|
|
151
|
+
var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
|
|
152
|
+
| ((0x3f & cccc.charCodeAt(1)) << 12)
|
|
153
|
+
| ((0x3f & cccc.charCodeAt(2)) << 6)
|
|
154
|
+
| (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000;
|
|
155
|
+
return (_fromCC((offset >>> 10) + 0xD800)
|
|
156
|
+
+ _fromCC((offset & 0x3FF) + 0xDC00));
|
|
157
|
+
case 3:
|
|
158
|
+
return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12)
|
|
159
|
+
| ((0x3f & cccc.charCodeAt(1)) << 6)
|
|
160
|
+
| (0x3f & cccc.charCodeAt(2)));
|
|
161
|
+
default:
|
|
162
|
+
return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6)
|
|
163
|
+
| (0x3f & cccc.charCodeAt(1)));
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* @deprecated should have been internal use only.
|
|
168
|
+
* @param {string} src UTF-16 string
|
|
169
|
+
* @returns {string} UTF-8 string
|
|
170
|
+
*/
|
|
171
|
+
var btou = function (b) { return b.replace(re_btou, cb_btou); };
|
|
172
|
+
/**
|
|
173
|
+
* polyfill version of `atob`
|
|
174
|
+
*/
|
|
175
|
+
var atobPolyfill = function (asc) {
|
|
176
|
+
// console.log('polyfilled');
|
|
177
|
+
asc = asc.replace(/\s+/g, '');
|
|
178
|
+
if (!b64re.test(asc))
|
|
179
|
+
throw new TypeError('malformed base64.');
|
|
180
|
+
asc += '=='.slice(2 - (asc.length & 3));
|
|
181
|
+
var u24, r1, r2;
|
|
182
|
+
var binArray = []; // use array to avoid minor gc in loop
|
|
183
|
+
for (var i = 0; i < asc.length;) {
|
|
184
|
+
u24 = b64tab[asc.charAt(i++)] << 18
|
|
185
|
+
| b64tab[asc.charAt(i++)] << 12
|
|
186
|
+
| (r1 = b64tab[asc.charAt(i++)]) << 6
|
|
187
|
+
| (r2 = b64tab[asc.charAt(i++)]);
|
|
188
|
+
if (r1 === 64) {
|
|
189
|
+
binArray.push(_fromCC(u24 >> 16 & 255));
|
|
190
|
+
}
|
|
191
|
+
else if (r2 === 64) {
|
|
192
|
+
binArray.push(_fromCC(u24 >> 16 & 255, u24 >> 8 & 255));
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
binArray.push(_fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return binArray.join('');
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* does what `window.atob` of web browsers do.
|
|
202
|
+
* @param {String} asc Base64-encoded string
|
|
203
|
+
* @returns {string} binary string
|
|
204
|
+
*/
|
|
205
|
+
var _atob = typeof atob === 'function' ? function (asc) { return atob(_tidyB64(asc)); }
|
|
206
|
+
: atobPolyfill;
|
|
207
|
+
//
|
|
208
|
+
var _toUint8Array = typeof Uint8Array.fromBase64 === 'function'
|
|
209
|
+
? function (a) { return Uint8Array.fromBase64(a); } : function (a) { return _U8Afrom(_atob(a).split('').map(function (c) { return c.charCodeAt(0); })); };
|
|
210
|
+
/**
|
|
211
|
+
* converts a Base64 string to a Uint8Array.
|
|
212
|
+
*/
|
|
213
|
+
var toUint8Array = function (a) { return _toUint8Array(_unURI(a)); };
|
|
214
|
+
//
|
|
215
|
+
var _decode = _TD
|
|
216
|
+
? function (a) { return _TD.decode(_toUint8Array(a)); }
|
|
217
|
+
: function (a) { return btou(_atob(a)); };
|
|
218
|
+
var _unURI = function (a) {
|
|
219
|
+
return _tidyB64(a.replace(/[-_]/g, function (m0) { return m0 == '-' ? '+' : '/'; }));
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* converts a Base64 string to a UTF-8 string.
|
|
223
|
+
* @param {String} src Base64 string. Both normal and URL-safe are supported
|
|
224
|
+
* @returns {string} UTF-8 string
|
|
225
|
+
*/
|
|
226
|
+
var decode = function (src) { return _decode(_unURI(src)); };
|
|
227
|
+
/**
|
|
228
|
+
* check if a value is a valid Base64 string
|
|
229
|
+
* @param {String} src a value to check
|
|
230
|
+
*/
|
|
231
|
+
var isValid = function (src) {
|
|
232
|
+
if (typeof src !== 'string')
|
|
233
|
+
return false;
|
|
234
|
+
var s = src.replace(/\s+/g, '').replace(/={0,2}$/, '');
|
|
235
|
+
return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s);
|
|
236
|
+
};
|
|
237
|
+
//
|
|
238
|
+
var _noEnum = function (v) {
|
|
239
|
+
return {
|
|
240
|
+
value: v, enumerable: false, writable: true, configurable: true
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* extend String.prototype with relevant methods
|
|
245
|
+
*/
|
|
246
|
+
var extendString = function () {
|
|
247
|
+
var _add = function (name, body) { return Object.defineProperty(String.prototype, name, _noEnum(body)); };
|
|
248
|
+
_add('fromBase64', function () { return decode(this); });
|
|
249
|
+
_add('toBase64', function (urlsafe) { return encode(this, urlsafe); });
|
|
250
|
+
_add('toBase64URI', function () { return encode(this, true); });
|
|
251
|
+
_add('toBase64URL', function () { return encode(this, true); });
|
|
252
|
+
_add('toUint8Array', function () { return toUint8Array(this); });
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* extend Uint8Array.prototype with relevant methods
|
|
256
|
+
*/
|
|
257
|
+
var extendUint8Array = function () {
|
|
258
|
+
var _add = function (name, body) { return Object.defineProperty(Uint8Array.prototype, name, _noEnum(body)); };
|
|
259
|
+
_add('toBase64', function (urlsafe) { return fromUint8Array(this, urlsafe); });
|
|
260
|
+
_add('toBase64URI', function () { return fromUint8Array(this, true); });
|
|
261
|
+
_add('toBase64URL', function () { return fromUint8Array(this, true); });
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* extend Builtin prototypes with relevant methods
|
|
265
|
+
*/
|
|
266
|
+
var extendBuiltins = function () {
|
|
267
|
+
extendString();
|
|
268
|
+
extendUint8Array();
|
|
269
|
+
};
|
|
270
|
+
var gBase64 = {
|
|
271
|
+
version: version,
|
|
272
|
+
VERSION: VERSION,
|
|
273
|
+
atob: _atob,
|
|
274
|
+
atobPolyfill: atobPolyfill,
|
|
275
|
+
btoa: _btoa,
|
|
276
|
+
btoaPolyfill: btoaPolyfill,
|
|
277
|
+
fromBase64: decode,
|
|
278
|
+
toBase64: encode,
|
|
279
|
+
encode: encode,
|
|
280
|
+
encodeURI: encodeURI,
|
|
281
|
+
encodeURL: encodeURI,
|
|
282
|
+
utob: utob,
|
|
283
|
+
btou: btou,
|
|
284
|
+
decode: decode,
|
|
285
|
+
isValid: isValid,
|
|
286
|
+
fromUint8Array: fromUint8Array,
|
|
287
|
+
toUint8Array: toUint8Array,
|
|
288
|
+
extendString: extendString,
|
|
289
|
+
extendUint8Array: extendUint8Array,
|
|
290
|
+
extendBuiltins: extendBuiltins
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
exports.Base64 = gBase64;
|
|
294
|
+
exports.VERSION = VERSION;
|
|
295
|
+
exports.atob = _atob;
|
|
296
|
+
exports.atobPolyfill = atobPolyfill;
|
|
297
|
+
exports.btoa = _btoa;
|
|
298
|
+
exports.btoaPolyfill = btoaPolyfill;
|
|
299
|
+
exports.btou = btou;
|
|
300
|
+
exports.decode = decode;
|
|
301
|
+
exports.encode = encode;
|
|
302
|
+
exports.encodeURI = encodeURI;
|
|
303
|
+
exports.encodeURL = encodeURI;
|
|
304
|
+
exports.extendBuiltins = extendBuiltins;
|
|
305
|
+
exports.extendString = extendString;
|
|
306
|
+
exports.extendUint8Array = extendUint8Array;
|
|
307
|
+
exports.fromBase64 = decode;
|
|
308
|
+
exports.fromUint8Array = fromUint8Array;
|
|
309
|
+
exports.isValid = isValid;
|
|
310
|
+
exports.toBase64 = encode;
|
|
311
|
+
exports.toUint8Array = toUint8Array;
|
|
312
|
+
exports.utob = utob;
|
|
313
|
+
exports.version = version;
|
|
314
|
+
|
|
312
315
|
}));
|
package/base64.mjs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @author Dan Kogai (https://github.com/dankogai)
|
|
11
11
|
*/
|
|
12
|
-
const version = '3.9.
|
|
12
|
+
const version = '3.9.2';
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated use lowercase `version`.
|
|
15
15
|
*/
|
|
@@ -267,26 +267,5 @@ const gBase64 = {
|
|
|
267
267
|
extendUint8Array: extendUint8Array,
|
|
268
268
|
extendBuiltins: extendBuiltins
|
|
269
269
|
};
|
|
270
|
-
|
|
271
|
-
export { version };
|
|
272
|
-
export { VERSION };
|
|
273
|
-
export { _atob as atob };
|
|
274
|
-
export { atobPolyfill };
|
|
275
|
-
export { _btoa as btoa };
|
|
276
|
-
export { btoaPolyfill };
|
|
277
|
-
export { decode as fromBase64 };
|
|
278
|
-
export { encode as toBase64 };
|
|
279
|
-
export { utob };
|
|
280
|
-
export { encode };
|
|
281
|
-
export { encodeURI };
|
|
282
|
-
export { encodeURI as encodeURL };
|
|
283
|
-
export { btou };
|
|
284
|
-
export { decode };
|
|
285
|
-
export { isValid };
|
|
286
|
-
export { fromUint8Array };
|
|
287
|
-
export { toUint8Array };
|
|
288
|
-
export { extendString };
|
|
289
|
-
export { extendUint8Array };
|
|
290
|
-
export { extendBuiltins };
|
|
291
|
-
// and finally,
|
|
292
|
-
export { gBase64 as Base64 };
|
|
270
|
+
|
|
271
|
+
export { gBase64 as Base64, VERSION, _atob as atob, atobPolyfill, _btoa as btoa, btoaPolyfill, btou, decode, encode, encodeURI, encodeURI as encodeURL, extendBuiltins, extendString, extendUint8Array, decode as fromBase64, fromUint8Array, isValid, encode as toBase64, toUint8Array, utob, version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-base64",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.2",
|
|
4
4
|
"description": "Yet another Base64 transcoder in pure-JS",
|
|
5
5
|
"main": "base64.js",
|
|
6
6
|
"module": "base64.mjs",
|
|
@@ -26,11 +26,18 @@
|
|
|
26
26
|
"./package.json": "./package.json"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
-
"
|
|
29
|
+
"build": "rollup -c && tsc -p . --declaration --emitDeclarationOnly && node -e \"require('fs').copyFileSync('base64.d.ts','base64.d.mts')\"",
|
|
30
|
+
"clean": "node -e \"['base64.js','base64.mjs','base64.d.ts','base64.d.mts'].forEach(f=>require('fs').rmSync(f,{force:true}))\"",
|
|
31
|
+
"test": "npm run build && mocha",
|
|
32
|
+
"version": "npm run build && node util/sync-version.js && git add base64.js base64.mjs base64.d.ts base64.d.mts README.md"
|
|
30
33
|
},
|
|
31
34
|
"devDependencies": {
|
|
35
|
+
"@rollup/plugin-replace": "^6.0.3",
|
|
36
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
32
37
|
"@types/node": "^20.11.5",
|
|
33
38
|
"mocha": "^10.2.0",
|
|
39
|
+
"rollup": "^4.62.3",
|
|
40
|
+
"tslib": "^2.8.1",
|
|
34
41
|
"typescript": "^5.3.3"
|
|
35
42
|
},
|
|
36
43
|
"repository": "git+https://github.com/dankogai/js-base64.git",
|