Skip to content

Commit

Permalink
fix: use global btoa, support services worker, close #258 (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 29, 2023
1 parent adaece9 commit 2dea20b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions benchmark/data.js
Expand Up @@ -135,13 +135,13 @@ class Chunk {
}
}
}
let btoa = () => {
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
let _btoa = () => {
throw new Error("Unsupported environment: `btoa` or `Buffer` should be supported.");
};
if (typeof window !== "undefined" && typeof window.btoa === "function") {
btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
} else if (typeof Buffer === "function") {
btoa = (str) => Buffer.from(str, "utf-8").toString("base64");
if (typeof Buffer === "function") {
_btoa = (str) => Buffer.from(str, "utf-8").toString("base64");
} else if (typeof btoa === "function") {
_btoa = btoa;
}
class SourceMap {
constructor(properties) {
Expand All @@ -156,7 +156,7 @@ class SourceMap {
return JSON.stringify(this);
}
toUrl() {
return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
return "data:application/json;charset=utf-8;base64," + _btoa(this.toString());
}
}
function guessIndent(code) {
Expand Down

0 comments on commit 2dea20b

Please sign in to comment.