@shgysk8zer0/polyfills 0.3.12 → 0.3.14
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/CHANGELOG.md +10 -0
- package/all.min.js +2 -2
- package/all.min.js.map +1 -1
- package/array.js +16 -3
- package/package.json +1 -1
package/array.js
CHANGED
|
@@ -280,7 +280,10 @@ if (! (Array.isTemplateObject instanceof Function)) {
|
|
|
280
280
|
*/
|
|
281
281
|
if (! (Uint8Array.prototype.toHex instanceof Function)) {
|
|
282
282
|
Uint8Array.prototype.toHex = function toHex() {
|
|
283
|
-
return Array.from(
|
|
283
|
+
return Array.from(
|
|
284
|
+
this,
|
|
285
|
+
n => n.toString(16).padStart('0', 2)
|
|
286
|
+
).join('');
|
|
284
287
|
};
|
|
285
288
|
}
|
|
286
289
|
|
|
@@ -288,7 +291,16 @@ if (! (Uint8Array.prototype.toBase64 instanceof Function)) {
|
|
|
288
291
|
Uint8Array.prototype.toBase64 = function toBase64({ alphabet = 'base64' } = {}) {
|
|
289
292
|
if (alphabet === 'base64') {
|
|
290
293
|
// @todo Figure out encoding specifics
|
|
291
|
-
return btoa(String.fromCodePoint(...this));
|
|
294
|
+
//return btoa(String.fromCodePoint(...this));
|
|
295
|
+
const chunkSize = 0x8000; // 32,768 bytes per chunk
|
|
296
|
+
let str = '';
|
|
297
|
+
|
|
298
|
+
for (let i = 0; i < this.length; i += chunkSize) {
|
|
299
|
+
const chunk = this.subarray(i, i + chunkSize);
|
|
300
|
+
str += String.fromCharCode.apply(null, chunk);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return btoa(str);
|
|
292
304
|
// return btoa(new TextDecoder().decode(this));
|
|
293
305
|
} else if (alphabet === 'base64url') {
|
|
294
306
|
return this.toBase64({ alphabet: 'base64' }).replaceAll('+', '-').replaceAll('/', '_');
|
|
@@ -349,7 +361,8 @@ if (! (Uint8Array.fromBase64 instanceof Function)) {
|
|
|
349
361
|
// Already checked for valid `lastChunkHandling`
|
|
350
362
|
}
|
|
351
363
|
} else {
|
|
352
|
-
return new TextEncoder().encode(atob(str));
|
|
364
|
+
// return new TextEncoder().encode(atob(str));
|
|
365
|
+
return Uint8Array.from(atob(str), char => char.charCodeAt(0));
|
|
353
366
|
}
|
|
354
367
|
} else {
|
|
355
368
|
return Uint8Array.fromBase64(
|