js-base64 3.8.1 → 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 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.8.1/base64.min.js"></script>
29
+ <script src="https://cdn.jsdelivr.net/npm/js-base64@3.9.0/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.8.1/base64.mjs';
52
+ import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.9.0/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.8.1/base64.mjs';
59
+ import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.9.0/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.8.1";
12
+ declare const version = "3.9.0";
13
13
  /**
14
14
  * @deprecated use lowercase `version`.
15
15
  */
16
- declare const VERSION = "3.8.1";
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.8.1";
12
+ declare const version = "3.9.0";
13
13
  /**
14
14
  * @deprecated use lowercase `version`.
15
15
  */
16
- declare const VERSION = "3.8.1";
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.8.1';
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,23 +85,16 @@
86
85
  * @returns {string} Base64-encoded string
87
86
  */
88
87
  var _btoa = typeof btoa === 'function' ? function (bin) { return btoa(bin); }
89
- : _hasBuffer ? function (bin) {
90
- if (/[^\x00-\xff]/.test(bin))
91
- throw new TypeError('invalid character found');
92
- return Buffer.from(bin, 'binary').toString('base64');
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)));
93
95
  }
94
- : btoaPolyfill;
95
- var _fromUint8Array = _hasBuffer
96
- ? function (u8a) { return Buffer.from(u8a).toString('base64'); }
97
- : function (u8a) {
98
- // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
99
- var maxargs = 0x1000;
100
- var strs = [];
101
- for (var i = 0, l = u8a.length; i < l; i += maxargs) {
102
- strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
103
- }
104
- return _btoa(strs.join(''));
105
- };
96
+ return _btoa(strs.join(''));
97
+ };
106
98
  /**
107
99
  * converts a Uint8Array to a Base64 string.
108
100
  * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
@@ -143,11 +135,9 @@
143
135
  */
144
136
  var utob = function (u) { return u.replace(re_utob, cb_utob); };
145
137
  //
146
- var _encode = _hasBuffer
147
- ? function (s) { return Buffer.from(s, 'utf8').toString('base64'); }
148
- : _TE
149
- ? function (s) { return _fromUint8Array(_TE.encode(s)); }
150
- : 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)); };
151
141
  /**
152
142
  * converts a UTF-8-encoded string to a Base64 string.
153
143
  * @param {boolean} [urlsafe] if `true` make the result URL-safe
@@ -226,22 +216,17 @@
226
216
  * @returns {string} binary string
227
217
  */
228
218
  var _atob = typeof atob === 'function' ? function (asc) { return atob(_tidyB64(asc)); }
229
- : _hasBuffer ? function (asc) { return Buffer.from(asc, 'base64').toString('binary'); }
230
- : atobPolyfill;
219
+ : atobPolyfill;
231
220
  //
232
- var _toUint8Array = _hasBuffer
233
- ? function (a) { return _U8Afrom(Buffer.from(a, 'base64')); }
234
- : 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); })); };
235
222
  /**
236
223
  * converts a Base64 string to a Uint8Array.
237
224
  */
238
225
  var toUint8Array = function (a) { return _toUint8Array(_unURI(a)); };
239
226
  //
240
- var _decode = _hasBuffer
241
- ? function (a) { return Buffer.from(a, 'base64').toString('utf8'); }
242
- : _TD
243
- ? function (a) { return _TD.decode(_toUint8Array(a)); }
244
- : 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)); };
245
230
  var _unURI = function (a) { return _tidyB64(a.replace(/[-_]/g, function (m0) { return m0 == '-' ? '+' : '/'; })); };
246
231
  /**
247
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.8.1';
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,23 +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
- : _hasBuffer ? (bin) => {
62
- if (/[^\x00-\xff]/.test(bin))
63
- throw new TypeError('invalid character found');
64
- return Buffer.from(bin, 'binary').toString('base64');
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)));
65
67
  }
66
- : btoaPolyfill;
67
- const _fromUint8Array = _hasBuffer
68
- ? (u8a) => Buffer.from(u8a).toString('base64')
69
- : (u8a) => {
70
- // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
71
- const maxargs = 0x1000;
72
- let strs = [];
73
- for (let i = 0, l = u8a.length; i < l; i += maxargs) {
74
- strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
75
- }
76
- return _btoa(strs.join(''));
77
- };
68
+ return _btoa(strs.join(''));
69
+ };
78
70
  /**
79
71
  * converts a Uint8Array to a Base64 string.
80
72
  * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
@@ -112,11 +104,9 @@ const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
112
104
  */
113
105
  const utob = (u) => u.replace(re_utob, cb_utob);
114
106
  //
115
- const _encode = _hasBuffer
116
- ? (s) => Buffer.from(s, 'utf8').toString('base64')
117
- : _TE
118
- ? (s) => _fromUint8Array(_TE.encode(s))
119
- : (s) => _btoa(utob(s));
107
+ const _encode = _TE
108
+ ? (s) => _fromUint8Array(_TE.encode(s))
109
+ : (s) => _btoa(utob(s));
120
110
  /**
121
111
  * converts a UTF-8-encoded string to a Base64 string.
122
112
  * @param {boolean} [urlsafe] if `true` make the result URL-safe
@@ -192,22 +182,17 @@ const atobPolyfill = (asc) => {
192
182
  * @returns {string} binary string
193
183
  */
194
184
  const _atob = typeof atob === 'function' ? (asc) => atob(_tidyB64(asc))
195
- : _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary')
196
- : atobPolyfill;
185
+ : atobPolyfill;
197
186
  //
198
- const _toUint8Array = _hasBuffer
199
- ? (a) => _U8Afrom(Buffer.from(a, 'base64'))
200
- : (a) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));
187
+ const _toUint8Array = (a) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));
201
188
  /**
202
189
  * converts a Base64 string to a Uint8Array.
203
190
  */
204
191
  const toUint8Array = (a) => _toUint8Array(_unURI(a));
205
192
  //
206
- const _decode = _hasBuffer
207
- ? (a) => Buffer.from(a, 'base64').toString('utf8')
208
- : _TD
209
- ? (a) => _TD.decode(_toUint8Array(a))
210
- : (a) => btou(_atob(a));
193
+ const _decode = _TD
194
+ ? (a) => _TD.decode(_toUint8Array(a))
195
+ : (a) => btou(_atob(a));
211
196
  const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));
212
197
  /**
213
198
  * converts a Base64 string to a UTF-8 string.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-base64",
3
- "version": "3.8.1",
3
+ "version": "3.9.0",
4
4
  "description": "Yet another Base64 transcoder in pure-JS",
5
5
  "main": "base64.js",
6
6
  "module": "base64.mjs",