Skip to content

Commit 69916ca

Browse files
committed
Fix String.fromCodePoint.apply in ts and fix outdated .js
- The call to `String.fromCodePoint.apply` was erroring because `CallableFunction.apply` expects a strict Array, but we're passing a Uint8Array, which is just ArrayLike - The .js file was outdated, causing the previous version to not have had any impact whatsoever, so run `tsc` to fix it and apply the latest changes. This means that the minor version of the package had to be bumped as well
1 parent db531b2 commit 69916ca

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ const base64DecodeToBytes = Object.freeze(function (s) {
241241
const base64EncodeFromBytes = Object.freeze(function (...s) {
242242
let binString = '';
243243
for (let i = 0; i < s.length; i++)
244-
binString += String.fromCodePoint(...s[i]);
244+
binString += String.fromCodePoint.apply(undefined,
245+
// [typescript] Uint8Array values are not writable, so they don't
246+
// have push, pop, etc. But we know here we just need it for
247+
// readonly access, so we force-override the type to be able to call
248+
// `apply`.
249+
// See: https://github.com/microsoft/TypeScript/issues/55846
250+
s[i]);
245251
return btoa(binString);
246252
});

index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ const base64EncodeFromBytes = Object.freeze(function(
323323
): string {
324324
let binString = '';
325325
for (let i=0; i < s.length; i++)
326-
binString += String.fromCodePoint.apply(undefined, s[i]);
326+
binString += String.fromCodePoint.apply(undefined,
327+
// [typescript] Uint8Array values are not writable, so they don't
328+
// have push, pop, etc. But we know here we just need it for
329+
// readonly access, so we force-override the type to be able to call
330+
// `apply`.
331+
// See: https://github.com/microsoft/TypeScript/issues/55846
332+
s[i] as unknown as number[]);
327333
return btoa(binString);
328334
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-subtlecrypto-store",
3-
"version": "1.2.2",
3+
"version": "1.3.0",
44
"description": "Svelte writable store using SubtleCrypto API",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)