Skip to content

Commit

Permalink
feat: support Web Workers by using the global btoa (#269)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
curran and antfu authored Jan 31, 2024
1 parent 5bfb56d commit 8679648
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"globals": {
"DEBUG": true,
"process": true,
"Buffer": true
"Buffer": true,
"globalThis": true,
},
"extends": "eslint:recommended",
"parserOptions": {
Expand Down
4 changes: 2 additions & 2 deletions src/SourceMap.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { encode } from '@jridgewell/sourcemap-codec';

function getBtoa() {
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
return (str) => window.btoa(unescape(encodeURIComponent(str)));
if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
} else if (typeof Buffer === 'function') {
return (str) => Buffer.from(str, 'utf-8').toString('base64');
} else {
Expand Down

0 comments on commit 8679648

Please sign in to comment.