Skip to content

Commit 18e8a39

Browse files
authored
This closes #34, using globalThis instead of all global and window for allow to work in web workers (#35)
1 parent e920d00 commit 18e8a39

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
if (typeof window === 'undefined') {
2-
!global.crypto && (global.crypto = {
1+
if (typeof globalThis.navigator === 'undefined') {
2+
!globalThis.crypto && (globalThis.crypto = {
33
async getRandomValues(b) {
44
const { randomFillSync } = await import('crypto');
55
randomFillSync(b);
66
}
77
});
8-
!global.performance && (global.performance = {
8+
!globalThis.performance && (globalThis.performance = {
99
now() {
1010
const [sec, nsec] = process.hrtime();
1111
return sec * 1000 + nsec / 1000000;
@@ -572,19 +572,18 @@ import pako from 'pako';
572572
export async function init(wasmPath) {
573573
const go = new Go();
574574
var buffer;
575-
if (typeof window === 'undefined') {
576-
global.excelize = {};
575+
if (typeof globalThis.navigator === 'undefined') {
576+
globalThis.excelize = {};
577577
const fs = await import('fs');
578578
buffer = pako.ungzip(fs.readFileSync(wasmPath));
579579
} else {
580-
window.excelize = {};
580+
globalThis.excelize = {};
581581
buffer = pako.ungzip(await (await fetch(wasmPath)).arrayBuffer());
582582
}
583583
if (buffer[0] === 0x1f && buffer[1] === 0x8b) {
584-
buffer = pako.ungzip(buffer);
584+
buffer = pako.ungzip(buffer);
585585
}
586586
const result = await WebAssembly.instantiate(buffer, go.importObject);
587587
go.run(result.instance);
588588
return excelize;
589589
};
590-

0 commit comments

Comments
 (0)