Skip to content

Commit

Permalink
fix error String.fromCharCode on bun
Browse files Browse the repository at this point in the history
  • Loading branch information
nurliman committed May 10, 2024
1 parent f1bbb4f commit 1dfac91
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-pears-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nurliman/base85": patch
---

fix error `String.fromCharCode` on bun
4 changes: 3 additions & 1 deletion src/decode.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { charCodeArrayToString } from "./utils.ts";

/**
* Decodes a string from ASCII85
*
Expand Down Expand Up @@ -59,5 +61,5 @@ export function decodeBase85(input: string): string {
}

// Convert the array of decoded bytes to a string and return it
return String.fromCharCode(...decodedBytes);
return charCodeArrayToString(decodedBytes);
}
4 changes: 3 additions & 1 deletion src/encode.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { charCodeArrayToString } from "./utils.ts";

/**
* `EncodeOptions` is an object that can be passed to the encode function to customize its behavior.
*/
Expand Down Expand Up @@ -61,7 +63,7 @@ export function encodeBase85(input: string, { wrap = true }: EncodeOptions = {})
encodedArray.splice(-paddingCharacters.length);
}

const encodedString = String.fromCharCode(...encodedArray);
const encodedString = charCodeArrayToString(encodedArray);
const output = wrap ? `<~${encodedString}~>` : encodedString;

return output;
Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function charCodeArrayToString(charCodes: number[]) {
let output = "";
for (let i = 0; i < charCodes.length; i++) {
output += String.fromCharCode(charCodes[i]);
}
return output;
}

0 comments on commit 1dfac91

Please sign in to comment.