Skip to content

Commit 2dea20b

Browse files
authored
fix: use global btoa, support services worker, close #258 (#259)
1 parent adaece9 commit 2dea20b

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

benchmark/data.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ class Chunk {
135135
}
136136
}
137137
}
138-
let btoa = () => {
139-
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
138+
let _btoa = () => {
139+
throw new Error("Unsupported environment: `btoa` or `Buffer` should be supported.");
140140
};
141-
if (typeof window !== "undefined" && typeof window.btoa === "function") {
142-
btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
143-
} else if (typeof Buffer === "function") {
144-
btoa = (str) => Buffer.from(str, "utf-8").toString("base64");
141+
if (typeof Buffer === "function") {
142+
_btoa = (str) => Buffer.from(str, "utf-8").toString("base64");
143+
} else if (typeof btoa === "function") {
144+
_btoa = btoa;
145145
}
146146
class SourceMap {
147147
constructor(properties) {
@@ -156,7 +156,7 @@ class SourceMap {
156156
return JSON.stringify(this);
157157
}
158158
toUrl() {
159-
return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
159+
return "data:application/json;charset=utf-8;base64," + _btoa(this.toString());
160160
}
161161
}
162162
function guessIndent(code) {

0 commit comments

Comments
 (0)