Skip to content

Commit

Permalink
Fix String.fromCodePoint.apply in ts and fix outdated .js
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
diegommm committed Sep 24, 2023
1 parent db531b2 commit 69916ca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ const base64DecodeToBytes = Object.freeze(function (s) {
const base64EncodeFromBytes = Object.freeze(function (...s) {
let binString = '';
for (let i = 0; i < s.length; i++)
binString += String.fromCodePoint(...s[i]);
binString += String.fromCodePoint.apply(undefined,
// [typescript] Uint8Array values are not writable, so they don't
// have push, pop, etc. But we know here we just need it for
// readonly access, so we force-override the type to be able to call
// `apply`.
// See: https://github.com/microsoft/TypeScript/issues/55846
s[i]);
return btoa(binString);
});
8 changes: 7 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ const base64EncodeFromBytes = Object.freeze(function(
): string {
let binString = '';
for (let i=0; i < s.length; i++)
binString += String.fromCodePoint.apply(undefined, s[i]);
binString += String.fromCodePoint.apply(undefined,
// [typescript] Uint8Array values are not writable, so they don't
// have push, pop, etc. But we know here we just need it for
// readonly access, so we force-override the type to be able to call
// `apply`.
// See: https://github.com/microsoft/TypeScript/issues/55846
s[i] as unknown as number[]);
return btoa(binString);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelte-subtlecrypto-store",
"version": "1.2.2",
"version": "1.3.0",
"description": "Svelte writable store using SubtleCrypto API",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 69916ca

Please sign in to comment.