js-base64 3.7.6 → 3.7.8
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 +4 -4
- package/base64.d.ts +4 -4
- package/base64.js +15 -10
- package/base64.mjs +15 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Locally…
|
|
|
25
25
|
… or Directly from CDN. In which case you don't even need to install.
|
|
26
26
|
|
|
27
27
|
```html
|
|
28
|
-
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.7.
|
|
28
|
+
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.7.8/base64.min.js"></script>
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
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 +48,14 @@ or even remotely.
|
|
|
48
48
|
```html
|
|
49
49
|
<script type="module">
|
|
50
50
|
// note jsdelivr.net does not automatically minify .mjs
|
|
51
|
-
import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.7.
|
|
51
|
+
import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.7.8/base64.mjs';
|
|
52
52
|
</script>
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
```html
|
|
56
56
|
<script type="module">
|
|
57
57
|
// or if you prefer no Base64 namespace
|
|
58
|
-
import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.7.
|
|
58
|
+
import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.7.8/base64.mjs';
|
|
59
59
|
</script>
|
|
60
60
|
```
|
|
61
61
|
|
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.7.
|
|
12
|
+
declare const version = "3.7.8";
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated use lowercase `version`.
|
|
15
15
|
*/
|
|
16
|
-
declare const VERSION = "3.7.
|
|
16
|
+
declare const VERSION = "3.7.8";
|
|
17
17
|
/**
|
|
18
18
|
* polyfill version of `btoa`
|
|
19
19
|
*/
|
|
@@ -77,7 +77,7 @@ declare const decode: (src: string) => string;
|
|
|
77
77
|
* check if a value is a valid Base64 string
|
|
78
78
|
* @param {String} src a value to check
|
|
79
79
|
*/
|
|
80
|
-
declare const isValid: (src:
|
|
80
|
+
declare const isValid: (src: unknown) => boolean;
|
|
81
81
|
/**
|
|
82
82
|
* extend String.prototype with relevant methods
|
|
83
83
|
*/
|
|
@@ -105,7 +105,7 @@ declare const gBase64: {
|
|
|
105
105
|
utob: (u: string) => string;
|
|
106
106
|
btou: (b: string) => string;
|
|
107
107
|
decode: (src: string) => string;
|
|
108
|
-
isValid: (src:
|
|
108
|
+
isValid: (src: unknown) => boolean;
|
|
109
109
|
fromUint8Array: (u8a: Uint8Array, urlsafe?: boolean) => string;
|
|
110
110
|
toUint8Array: (a: string) => Uint8Array;
|
|
111
111
|
extendString: () => void;
|
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.7.
|
|
12
|
+
declare const version = "3.7.8";
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated use lowercase `version`.
|
|
15
15
|
*/
|
|
16
|
-
declare const VERSION = "3.7.
|
|
16
|
+
declare const VERSION = "3.7.8";
|
|
17
17
|
/**
|
|
18
18
|
* polyfill version of `btoa`
|
|
19
19
|
*/
|
|
@@ -77,7 +77,7 @@ declare const decode: (src: string) => string;
|
|
|
77
77
|
* check if a value is a valid Base64 string
|
|
78
78
|
* @param {String} src a value to check
|
|
79
79
|
*/
|
|
80
|
-
declare const isValid: (src:
|
|
80
|
+
declare const isValid: (src: unknown) => boolean;
|
|
81
81
|
/**
|
|
82
82
|
* extend String.prototype with relevant methods
|
|
83
83
|
*/
|
|
@@ -105,7 +105,7 @@ declare const gBase64: {
|
|
|
105
105
|
utob: (u: string) => string;
|
|
106
106
|
btou: (b: string) => string;
|
|
107
107
|
decode: (src: string) => string;
|
|
108
|
-
isValid: (src:
|
|
108
|
+
isValid: (src: unknown) => boolean;
|
|
109
109
|
fromUint8Array: (u8a: Uint8Array, urlsafe?: boolean) => string;
|
|
110
110
|
toUint8Array: (a: string) => Uint8Array;
|
|
111
111
|
extendString: () => void;
|
package/base64.js
CHANGED
|
@@ -37,13 +37,11 @@
|
|
|
37
37
|
*
|
|
38
38
|
* @author Dan Kogai (https://github.com/dankogai)
|
|
39
39
|
*/
|
|
40
|
-
var version = '3.7.
|
|
40
|
+
var version = '3.7.8';
|
|
41
41
|
/**
|
|
42
42
|
* @deprecated use lowercase `version`.
|
|
43
43
|
*/
|
|
44
44
|
var VERSION = version;
|
|
45
|
-
var _hasatob = typeof atob === 'function';
|
|
46
|
-
var _hasbtoa = typeof btoa === 'function';
|
|
47
45
|
var _hasBuffer = typeof Buffer === 'function';
|
|
48
46
|
var _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
|
|
49
47
|
var _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
|
|
@@ -87,7 +85,7 @@
|
|
|
87
85
|
* @param {String} bin binary string
|
|
88
86
|
* @returns {string} Base64-encoded string
|
|
89
87
|
*/
|
|
90
|
-
var _btoa =
|
|
88
|
+
var _btoa = typeof btoa === 'function' ? function (bin) { return btoa(bin); }
|
|
91
89
|
: _hasBuffer ? function (bin) { return Buffer.from(bin, 'binary').toString('base64'); }
|
|
92
90
|
: btoaPolyfill;
|
|
93
91
|
var _fromUint8Array = _hasBuffer
|
|
@@ -199,24 +197,31 @@
|
|
|
199
197
|
if (!b64re.test(asc))
|
|
200
198
|
throw new TypeError('malformed base64.');
|
|
201
199
|
asc += '=='.slice(2 - (asc.length & 3));
|
|
202
|
-
var u24,
|
|
200
|
+
var u24, r1, r2;
|
|
201
|
+
var binArray = []; // use array to avoid minor gc in loop
|
|
203
202
|
for (var i = 0; i < asc.length;) {
|
|
204
203
|
u24 = b64tab[asc.charAt(i++)] << 18
|
|
205
204
|
| b64tab[asc.charAt(i++)] << 12
|
|
206
205
|
| (r1 = b64tab[asc.charAt(i++)]) << 6
|
|
207
206
|
| (r2 = b64tab[asc.charAt(i++)]);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
if (r1 === 64) {
|
|
208
|
+
binArray.push(_fromCC(u24 >> 16 & 255));
|
|
209
|
+
}
|
|
210
|
+
else if (r2 === 64) {
|
|
211
|
+
binArray.push(_fromCC(u24 >> 16 & 255, u24 >> 8 & 255));
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
binArray.push(_fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255));
|
|
215
|
+
}
|
|
211
216
|
}
|
|
212
|
-
return
|
|
217
|
+
return binArray.join('');
|
|
213
218
|
};
|
|
214
219
|
/**
|
|
215
220
|
* does what `window.atob` of web browsers do.
|
|
216
221
|
* @param {String} asc Base64-encoded string
|
|
217
222
|
* @returns {string} binary string
|
|
218
223
|
*/
|
|
219
|
-
var _atob =
|
|
224
|
+
var _atob = typeof atob === 'function' ? function (asc) { return atob(_tidyB64(asc)); }
|
|
220
225
|
: _hasBuffer ? function (asc) { return Buffer.from(asc, 'base64').toString('binary'); }
|
|
221
226
|
: atobPolyfill;
|
|
222
227
|
//
|
package/base64.mjs
CHANGED
|
@@ -9,13 +9,11 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @author Dan Kogai (https://github.com/dankogai)
|
|
11
11
|
*/
|
|
12
|
-
const version = '3.7.
|
|
12
|
+
const version = '3.7.8';
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated use lowercase `version`.
|
|
15
15
|
*/
|
|
16
16
|
const VERSION = version;
|
|
17
|
-
const _hasatob = typeof atob === 'function';
|
|
18
|
-
const _hasbtoa = typeof btoa === 'function';
|
|
19
17
|
const _hasBuffer = typeof Buffer === 'function';
|
|
20
18
|
const _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
|
|
21
19
|
const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
|
|
@@ -59,7 +57,7 @@ const btoaPolyfill = (bin) => {
|
|
|
59
57
|
* @param {String} bin binary string
|
|
60
58
|
* @returns {string} Base64-encoded string
|
|
61
59
|
*/
|
|
62
|
-
const _btoa =
|
|
60
|
+
const _btoa = typeof btoa === 'function' ? (bin) => btoa(bin)
|
|
63
61
|
: _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64')
|
|
64
62
|
: btoaPolyfill;
|
|
65
63
|
const _fromUint8Array = _hasBuffer
|
|
@@ -165,24 +163,31 @@ const atobPolyfill = (asc) => {
|
|
|
165
163
|
if (!b64re.test(asc))
|
|
166
164
|
throw new TypeError('malformed base64.');
|
|
167
165
|
asc += '=='.slice(2 - (asc.length & 3));
|
|
168
|
-
let u24,
|
|
166
|
+
let u24, r1, r2;
|
|
167
|
+
let binArray = []; // use array to avoid minor gc in loop
|
|
169
168
|
for (let i = 0; i < asc.length;) {
|
|
170
169
|
u24 = b64tab[asc.charAt(i++)] << 18
|
|
171
170
|
| b64tab[asc.charAt(i++)] << 12
|
|
172
171
|
| (r1 = b64tab[asc.charAt(i++)]) << 6
|
|
173
172
|
| (r2 = b64tab[asc.charAt(i++)]);
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
if (r1 === 64) {
|
|
174
|
+
binArray.push(_fromCC(u24 >> 16 & 255));
|
|
175
|
+
}
|
|
176
|
+
else if (r2 === 64) {
|
|
177
|
+
binArray.push(_fromCC(u24 >> 16 & 255, u24 >> 8 & 255));
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
binArray.push(_fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255));
|
|
181
|
+
}
|
|
177
182
|
}
|
|
178
|
-
return
|
|
183
|
+
return binArray.join('');
|
|
179
184
|
};
|
|
180
185
|
/**
|
|
181
186
|
* does what `window.atob` of web browsers do.
|
|
182
187
|
* @param {String} asc Base64-encoded string
|
|
183
188
|
* @returns {string} binary string
|
|
184
189
|
*/
|
|
185
|
-
const _atob =
|
|
190
|
+
const _atob = typeof atob === 'function' ? (asc) => atob(_tidyB64(asc))
|
|
186
191
|
: _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary')
|
|
187
192
|
: atobPolyfill;
|
|
188
193
|
//
|