js-base64 3.8.1 → 3.9.1
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 +3 -3
- package/base64.d.mts +2 -2
- package/base64.d.ts +2 -2
- package/base64.js +12 -25
- package/base64.mjs +12 -25
- package/package.json +1 -1
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.
|
|
29
|
+
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.9.1/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.
|
|
52
|
+
import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.9.1/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.
|
|
59
|
+
import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.9.1/base64.mjs';
|
|
60
60
|
</script>
|
|
61
61
|
```
|
|
62
62
|
|
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 = "3.
|
|
12
|
+
declare const version = "3.9.1";
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated use lowercase `version`.
|
|
15
15
|
*/
|
|
16
|
-
declare const VERSION = "3.
|
|
16
|
+
declare const VERSION = "3.9.1";
|
|
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 = "3.
|
|
12
|
+
declare const version = "3.9.1";
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated use lowercase `version`.
|
|
15
15
|
*/
|
|
16
|
-
declare const VERSION = "3.
|
|
16
|
+
declare const VERSION = "3.9.1";
|
|
17
17
|
/**
|
|
18
18
|
* polyfill version of `btoa`
|
|
19
19
|
*/
|
package/base64.js
CHANGED
|
@@ -37,12 +37,11 @@
|
|
|
37
37
|
*
|
|
38
38
|
* @author Dan Kogai (https://github.com/dankogai)
|
|
39
39
|
*/
|
|
40
|
-
var version = '3.
|
|
40
|
+
var version = '3.9.1';
|
|
41
41
|
/**
|
|
42
42
|
* @deprecated use lowercase `version`.
|
|
43
43
|
*/
|
|
44
44
|
var VERSION = version;
|
|
45
|
-
var _hasBuffer = typeof Buffer === 'function';
|
|
46
45
|
var _TD = typeof TextDecoder === 'function' ? new TextDecoder('utf-8', { ignoreBOM: true }) : undefined;
|
|
47
46
|
var _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
|
|
48
47
|
var b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
@@ -86,14 +85,8 @@
|
|
|
86
85
|
* @returns {string} Base64-encoded string
|
|
87
86
|
*/
|
|
88
87
|
var _btoa = typeof btoa === 'function' ? function (bin) { return btoa(bin); }
|
|
89
|
-
:
|
|
90
|
-
|
|
91
|
-
throw new TypeError('invalid character found');
|
|
92
|
-
return Buffer.from(bin, 'binary').toString('base64');
|
|
93
|
-
}
|
|
94
|
-
: btoaPolyfill;
|
|
95
|
-
var _fromUint8Array = _hasBuffer
|
|
96
|
-
? function (u8a) { return Buffer.from(u8a).toString('base64'); }
|
|
88
|
+
: btoaPolyfill;
|
|
89
|
+
var _fromUint8Array = typeof Uint8Array.prototype.toBase64 === 'function' ? function (u8a) { return u8a.toBase64(); }
|
|
97
90
|
: function (u8a) {
|
|
98
91
|
// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
|
|
99
92
|
var maxargs = 0x1000;
|
|
@@ -143,11 +136,9 @@
|
|
|
143
136
|
*/
|
|
144
137
|
var utob = function (u) { return u.replace(re_utob, cb_utob); };
|
|
145
138
|
//
|
|
146
|
-
var _encode =
|
|
147
|
-
? function (s) { return
|
|
148
|
-
:
|
|
149
|
-
? function (s) { return _fromUint8Array(_TE.encode(s)); }
|
|
150
|
-
: function (s) { return _btoa(utob(s)); };
|
|
139
|
+
var _encode = _TE
|
|
140
|
+
? function (s) { return _fromUint8Array(_TE.encode(s)); }
|
|
141
|
+
: function (s) { return _btoa(utob(s)); };
|
|
151
142
|
/**
|
|
152
143
|
* converts a UTF-8-encoded string to a Base64 string.
|
|
153
144
|
* @param {boolean} [urlsafe] if `true` make the result URL-safe
|
|
@@ -226,22 +217,18 @@
|
|
|
226
217
|
* @returns {string} binary string
|
|
227
218
|
*/
|
|
228
219
|
var _atob = typeof atob === 'function' ? function (asc) { return atob(_tidyB64(asc)); }
|
|
229
|
-
:
|
|
230
|
-
: atobPolyfill;
|
|
220
|
+
: atobPolyfill;
|
|
231
221
|
//
|
|
232
|
-
var _toUint8Array =
|
|
233
|
-
? function (a) { return _U8Afrom(
|
|
234
|
-
: function (a) { return _U8Afrom(_atob(a).split('').map(function (c) { return c.charCodeAt(0); })); };
|
|
222
|
+
var _toUint8Array = typeof Uint8Array.fromBase64 === 'function'
|
|
223
|
+
? function (a) { return Uint8Array.fromBase64(a); } : function (a) { return _U8Afrom(_atob(a).split('').map(function (c) { return c.charCodeAt(0); })); };
|
|
235
224
|
/**
|
|
236
225
|
* converts a Base64 string to a Uint8Array.
|
|
237
226
|
*/
|
|
238
227
|
var toUint8Array = function (a) { return _toUint8Array(_unURI(a)); };
|
|
239
228
|
//
|
|
240
|
-
var _decode =
|
|
241
|
-
? function (a) { return
|
|
242
|
-
:
|
|
243
|
-
? function (a) { return _TD.decode(_toUint8Array(a)); }
|
|
244
|
-
: function (a) { return btou(_atob(a)); };
|
|
229
|
+
var _decode = _TD
|
|
230
|
+
? function (a) { return _TD.decode(_toUint8Array(a)); }
|
|
231
|
+
: function (a) { return btou(_atob(a)); };
|
|
245
232
|
var _unURI = function (a) { return _tidyB64(a.replace(/[-_]/g, function (m0) { return m0 == '-' ? '+' : '/'; })); };
|
|
246
233
|
/**
|
|
247
234
|
* converts a Base64 string to a UTF-8 string.
|
package/base64.mjs
CHANGED
|
@@ -9,12 +9,11 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @author Dan Kogai (https://github.com/dankogai)
|
|
11
11
|
*/
|
|
12
|
-
const version = '3.
|
|
12
|
+
const version = '3.9.1';
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated use lowercase `version`.
|
|
15
15
|
*/
|
|
16
16
|
const VERSION = version;
|
|
17
|
-
const _hasBuffer = typeof Buffer === 'function';
|
|
18
17
|
const _TD = typeof TextDecoder === 'function' ? new TextDecoder('utf-8', { ignoreBOM: true }) : undefined;
|
|
19
18
|
const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
|
|
20
19
|
const b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
@@ -58,14 +57,8 @@ const btoaPolyfill = (bin) => {
|
|
|
58
57
|
* @returns {string} Base64-encoded string
|
|
59
58
|
*/
|
|
60
59
|
const _btoa = typeof btoa === 'function' ? (bin) => btoa(bin)
|
|
61
|
-
:
|
|
62
|
-
|
|
63
|
-
throw new TypeError('invalid character found');
|
|
64
|
-
return Buffer.from(bin, 'binary').toString('base64');
|
|
65
|
-
}
|
|
66
|
-
: btoaPolyfill;
|
|
67
|
-
const _fromUint8Array = _hasBuffer
|
|
68
|
-
? (u8a) => Buffer.from(u8a).toString('base64')
|
|
60
|
+
: btoaPolyfill;
|
|
61
|
+
const _fromUint8Array = typeof Uint8Array.prototype.toBase64 === 'function' ? (u8a) => u8a.toBase64()
|
|
69
62
|
: (u8a) => {
|
|
70
63
|
// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
|
|
71
64
|
const maxargs = 0x1000;
|
|
@@ -112,11 +105,9 @@ const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
|
112
105
|
*/
|
|
113
106
|
const utob = (u) => u.replace(re_utob, cb_utob);
|
|
114
107
|
//
|
|
115
|
-
const _encode =
|
|
116
|
-
? (s) =>
|
|
117
|
-
:
|
|
118
|
-
? (s) => _fromUint8Array(_TE.encode(s))
|
|
119
|
-
: (s) => _btoa(utob(s));
|
|
108
|
+
const _encode = _TE
|
|
109
|
+
? (s) => _fromUint8Array(_TE.encode(s))
|
|
110
|
+
: (s) => _btoa(utob(s));
|
|
120
111
|
/**
|
|
121
112
|
* converts a UTF-8-encoded string to a Base64 string.
|
|
122
113
|
* @param {boolean} [urlsafe] if `true` make the result URL-safe
|
|
@@ -192,22 +183,18 @@ const atobPolyfill = (asc) => {
|
|
|
192
183
|
* @returns {string} binary string
|
|
193
184
|
*/
|
|
194
185
|
const _atob = typeof atob === 'function' ? (asc) => atob(_tidyB64(asc))
|
|
195
|
-
:
|
|
196
|
-
: atobPolyfill;
|
|
186
|
+
: atobPolyfill;
|
|
197
187
|
//
|
|
198
|
-
const _toUint8Array =
|
|
199
|
-
? (a) => _U8Afrom(
|
|
200
|
-
: (a) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));
|
|
188
|
+
const _toUint8Array = typeof Uint8Array.fromBase64 === 'function'
|
|
189
|
+
? (a) => Uint8Array.fromBase64(a) : (a) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));
|
|
201
190
|
/**
|
|
202
191
|
* converts a Base64 string to a Uint8Array.
|
|
203
192
|
*/
|
|
204
193
|
const toUint8Array = (a) => _toUint8Array(_unURI(a));
|
|
205
194
|
//
|
|
206
|
-
const _decode =
|
|
207
|
-
? (a) =>
|
|
208
|
-
:
|
|
209
|
-
? (a) => _TD.decode(_toUint8Array(a))
|
|
210
|
-
: (a) => btou(_atob(a));
|
|
195
|
+
const _decode = _TD
|
|
196
|
+
? (a) => _TD.decode(_toUint8Array(a))
|
|
197
|
+
: (a) => btou(_atob(a));
|
|
211
198
|
const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));
|
|
212
199
|
/**
|
|
213
200
|
* converts a Base64 string to a UTF-8 string.
|