js-base64 3.8.0 → 3.9.0
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 -3
- package/base64.d.mts +2 -2
- package/base64.d.ts +2 -2
- package/base64.js +19 -30
- package/base64.mjs +19 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
[](https://github.com/dankogai/js-base64/actions/workflows/node.js.yml)
|
|
2
|
+
[](https://github.com/dankogai/js-base64/actions/workflows/bun.yml)
|
|
2
3
|
|
|
3
4
|
# base64.js
|
|
4
5
|
|
|
@@ -25,7 +26,7 @@ Locally…
|
|
|
25
26
|
… or Directly from CDN. In which case you don't even need to install.
|
|
26
27
|
|
|
27
28
|
```html
|
|
28
|
-
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.
|
|
29
|
+
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.9.0/base64.min.js"></script>
|
|
29
30
|
```
|
|
30
31
|
|
|
31
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`.
|
|
@@ -48,14 +49,14 @@ or even remotely.
|
|
|
48
49
|
```html
|
|
49
50
|
<script type="module">
|
|
50
51
|
// note jsdelivr.net does not automatically minify .mjs
|
|
51
|
-
import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.
|
|
52
|
+
import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.9.0/base64.mjs';
|
|
52
53
|
</script>
|
|
53
54
|
```
|
|
54
55
|
|
|
55
56
|
```html
|
|
56
57
|
<script type="module">
|
|
57
58
|
// or if you prefer no Base64 namespace
|
|
58
|
-
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.0/base64.mjs';
|
|
59
60
|
</script>
|
|
60
61
|
```
|
|
61
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.0";
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated use lowercase `version`.
|
|
15
15
|
*/
|
|
16
|
-
declare const VERSION = "3.
|
|
16
|
+
declare const VERSION = "3.9.0";
|
|
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.0";
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated use lowercase `version`.
|
|
15
15
|
*/
|
|
16
|
-
declare const VERSION = "3.
|
|
16
|
+
declare const VERSION = "3.9.0";
|
|
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.0';
|
|
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,19 +85,16 @@
|
|
|
86
85
|
* @returns {string} Base64-encoded string
|
|
87
86
|
*/
|
|
88
87
|
var _btoa = typeof btoa === 'function' ? function (bin) { return btoa(bin); }
|
|
89
|
-
:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
return _btoa(strs.join(''));
|
|
101
|
-
};
|
|
88
|
+
: btoaPolyfill;
|
|
89
|
+
var _fromUint8Array = function (u8a) {
|
|
90
|
+
// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
|
|
91
|
+
var maxargs = 0x1000;
|
|
92
|
+
var strs = [];
|
|
93
|
+
for (var i = 0, l = u8a.length; i < l; i += maxargs) {
|
|
94
|
+
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
|
|
95
|
+
}
|
|
96
|
+
return _btoa(strs.join(''));
|
|
97
|
+
};
|
|
102
98
|
/**
|
|
103
99
|
* converts a Uint8Array to a Base64 string.
|
|
104
100
|
* @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
|
|
@@ -139,11 +135,9 @@
|
|
|
139
135
|
*/
|
|
140
136
|
var utob = function (u) { return u.replace(re_utob, cb_utob); };
|
|
141
137
|
//
|
|
142
|
-
var _encode =
|
|
143
|
-
? function (s) { return
|
|
144
|
-
:
|
|
145
|
-
? function (s) { return _fromUint8Array(_TE.encode(s)); }
|
|
146
|
-
: function (s) { return _btoa(utob(s)); };
|
|
138
|
+
var _encode = _TE
|
|
139
|
+
? function (s) { return _fromUint8Array(_TE.encode(s)); }
|
|
140
|
+
: function (s) { return _btoa(utob(s)); };
|
|
147
141
|
/**
|
|
148
142
|
* converts a UTF-8-encoded string to a Base64 string.
|
|
149
143
|
* @param {boolean} [urlsafe] if `true` make the result URL-safe
|
|
@@ -222,22 +216,17 @@
|
|
|
222
216
|
* @returns {string} binary string
|
|
223
217
|
*/
|
|
224
218
|
var _atob = typeof atob === 'function' ? function (asc) { return atob(_tidyB64(asc)); }
|
|
225
|
-
:
|
|
226
|
-
: atobPolyfill;
|
|
219
|
+
: atobPolyfill;
|
|
227
220
|
//
|
|
228
|
-
var _toUint8Array =
|
|
229
|
-
? function (a) { return _U8Afrom(Buffer.from(a, 'base64')); }
|
|
230
|
-
: function (a) { return _U8Afrom(_atob(a).split('').map(function (c) { return c.charCodeAt(0); })); };
|
|
221
|
+
var _toUint8Array = function (a) { return _U8Afrom(_atob(a).split('').map(function (c) { return c.charCodeAt(0); })); };
|
|
231
222
|
/**
|
|
232
223
|
* converts a Base64 string to a Uint8Array.
|
|
233
224
|
*/
|
|
234
225
|
var toUint8Array = function (a) { return _toUint8Array(_unURI(a)); };
|
|
235
226
|
//
|
|
236
|
-
var _decode =
|
|
237
|
-
? function (a) { return
|
|
238
|
-
:
|
|
239
|
-
? function (a) { return _TD.decode(_toUint8Array(a)); }
|
|
240
|
-
: function (a) { return btou(_atob(a)); };
|
|
227
|
+
var _decode = _TD
|
|
228
|
+
? function (a) { return _TD.decode(_toUint8Array(a)); }
|
|
229
|
+
: function (a) { return btou(_atob(a)); };
|
|
241
230
|
var _unURI = function (a) { return _tidyB64(a.replace(/[-_]/g, function (m0) { return m0 == '-' ? '+' : '/'; })); };
|
|
242
231
|
/**
|
|
243
232
|
* 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.0';
|
|
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,19 +57,16 @@ 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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
return _btoa(strs.join(''));
|
|
73
|
-
};
|
|
60
|
+
: btoaPolyfill;
|
|
61
|
+
const _fromUint8Array = (u8a) => {
|
|
62
|
+
// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
|
|
63
|
+
const maxargs = 0x1000;
|
|
64
|
+
let strs = [];
|
|
65
|
+
for (let i = 0, l = u8a.length; i < l; i += maxargs) {
|
|
66
|
+
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
|
|
67
|
+
}
|
|
68
|
+
return _btoa(strs.join(''));
|
|
69
|
+
};
|
|
74
70
|
/**
|
|
75
71
|
* converts a Uint8Array to a Base64 string.
|
|
76
72
|
* @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
|
|
@@ -108,11 +104,9 @@ const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
|
108
104
|
*/
|
|
109
105
|
const utob = (u) => u.replace(re_utob, cb_utob);
|
|
110
106
|
//
|
|
111
|
-
const _encode =
|
|
112
|
-
? (s) =>
|
|
113
|
-
:
|
|
114
|
-
? (s) => _fromUint8Array(_TE.encode(s))
|
|
115
|
-
: (s) => _btoa(utob(s));
|
|
107
|
+
const _encode = _TE
|
|
108
|
+
? (s) => _fromUint8Array(_TE.encode(s))
|
|
109
|
+
: (s) => _btoa(utob(s));
|
|
116
110
|
/**
|
|
117
111
|
* converts a UTF-8-encoded string to a Base64 string.
|
|
118
112
|
* @param {boolean} [urlsafe] if `true` make the result URL-safe
|
|
@@ -188,22 +182,17 @@ const atobPolyfill = (asc) => {
|
|
|
188
182
|
* @returns {string} binary string
|
|
189
183
|
*/
|
|
190
184
|
const _atob = typeof atob === 'function' ? (asc) => atob(_tidyB64(asc))
|
|
191
|
-
:
|
|
192
|
-
: atobPolyfill;
|
|
185
|
+
: atobPolyfill;
|
|
193
186
|
//
|
|
194
|
-
const _toUint8Array =
|
|
195
|
-
? (a) => _U8Afrom(Buffer.from(a, 'base64'))
|
|
196
|
-
: (a) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));
|
|
187
|
+
const _toUint8Array = (a) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));
|
|
197
188
|
/**
|
|
198
189
|
* converts a Base64 string to a Uint8Array.
|
|
199
190
|
*/
|
|
200
191
|
const toUint8Array = (a) => _toUint8Array(_unURI(a));
|
|
201
192
|
//
|
|
202
|
-
const _decode =
|
|
203
|
-
? (a) =>
|
|
204
|
-
:
|
|
205
|
-
? (a) => _TD.decode(_toUint8Array(a))
|
|
206
|
-
: (a) => btou(_atob(a));
|
|
193
|
+
const _decode = _TD
|
|
194
|
+
? (a) => _TD.decode(_toUint8Array(a))
|
|
195
|
+
: (a) => btou(_atob(a));
|
|
207
196
|
const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));
|
|
208
197
|
/**
|
|
209
198
|
* converts a Base64 string to a UTF-8 string.
|