js-base64 3.9.0 → 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 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.0/base64.min.js"></script>
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.9.0/base64.mjs';
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.9.0/base64.mjs';
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.9.0";
12
+ declare const version = "3.9.1";
13
13
  /**
14
14
  * @deprecated use lowercase `version`.
15
15
  */
16
- declare const VERSION = "3.9.0";
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.9.0";
12
+ declare const version = "3.9.1";
13
13
  /**
14
14
  * @deprecated use lowercase `version`.
15
15
  */
16
- declare const VERSION = "3.9.0";
16
+ declare const VERSION = "3.9.1";
17
17
  /**
18
18
  * polyfill version of `btoa`
19
19
  */
package/base64.js CHANGED
@@ -37,7 +37,7 @@
37
37
  *
38
38
  * @author Dan Kogai (https://github.com/dankogai)
39
39
  */
40
- var version = '3.9.0';
40
+ var version = '3.9.1';
41
41
  /**
42
42
  * @deprecated use lowercase `version`.
43
43
  */
@@ -86,15 +86,16 @@
86
86
  */
87
87
  var _btoa = typeof btoa === 'function' ? function (bin) { return btoa(bin); }
88
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
- };
89
+ var _fromUint8Array = typeof Uint8Array.prototype.toBase64 === 'function' ? function (u8a) { return u8a.toBase64(); }
90
+ : function (u8a) {
91
+ // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
92
+ var maxargs = 0x1000;
93
+ var strs = [];
94
+ for (var i = 0, l = u8a.length; i < l; i += maxargs) {
95
+ strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
96
+ }
97
+ return _btoa(strs.join(''));
98
+ };
98
99
  /**
99
100
  * converts a Uint8Array to a Base64 string.
100
101
  * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
@@ -218,7 +219,8 @@
218
219
  var _atob = typeof atob === 'function' ? function (asc) { return atob(_tidyB64(asc)); }
219
220
  : atobPolyfill;
220
221
  //
221
- var _toUint8Array = 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); })); };
222
224
  /**
223
225
  * converts a Base64 string to a Uint8Array.
224
226
  */
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.0';
12
+ const version = '3.9.1';
13
13
  /**
14
14
  * @deprecated use lowercase `version`.
15
15
  */
@@ -58,15 +58,16 @@ const btoaPolyfill = (bin) => {
58
58
  */
59
59
  const _btoa = typeof btoa === 'function' ? (bin) => btoa(bin)
60
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
- };
61
+ const _fromUint8Array = typeof Uint8Array.prototype.toBase64 === 'function' ? (u8a) => u8a.toBase64()
62
+ : (u8a) => {
63
+ // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
64
+ const maxargs = 0x1000;
65
+ let strs = [];
66
+ for (let i = 0, l = u8a.length; i < l; i += maxargs) {
67
+ strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
68
+ }
69
+ return _btoa(strs.join(''));
70
+ };
70
71
  /**
71
72
  * converts a Uint8Array to a Base64 string.
72
73
  * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
@@ -184,7 +185,8 @@ const atobPolyfill = (asc) => {
184
185
  const _atob = typeof atob === 'function' ? (asc) => atob(_tidyB64(asc))
185
186
  : atobPolyfill;
186
187
  //
187
- const _toUint8Array = (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)));
188
190
  /**
189
191
  * converts a Base64 string to a Uint8Array.
190
192
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-base64",
3
- "version": "3.9.0",
3
+ "version": "3.9.1",
4
4
  "description": "Yet another Base64 transcoder in pure-JS",
5
5
  "main": "base64.js",
6
6
  "module": "base64.mjs",