forked from Streampay-Org/StreamPay-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.polyfills.js
More file actions
80 lines (72 loc) · 2.94 KB
/
Copy pathjest.polyfills.js
File metadata and controls
80 lines (72 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const crypto = require("crypto");
const { TextEncoder, TextDecoder } = require("util");
const streamWeb = require("stream/web");
if (typeof globalThis.setImmediate === "undefined") {
globalThis.setImmediate = (fn, ...args) => setTimeout(fn, 0, ...args);
globalThis.clearImmediate = (id) => clearTimeout(id);
}
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.randomUUID === "undefined") {
const gCrypto = globalThis.crypto || {};
gCrypto.randomUUID = gCrypto.randomUUID || crypto.randomUUID;
globalThis.crypto = gCrypto;
}
if (typeof globalThis.structuredClone === "undefined") {
globalThis.structuredClone = (val) => (val === undefined ? undefined : JSON.parse(JSON.stringify(val)));
}
if (typeof globalThis.TextEncoder === "undefined") {
globalThis.TextEncoder = TextEncoder;
globalThis.TextDecoder = TextDecoder;
}
if (streamWeb) {
for (const key of Object.keys(streamWeb)) {
if (typeof globalThis[key] === "undefined") {
globalThis[key] = streamWeb[key];
}
}
}
if (typeof window !== "undefined") {
window.setImmediate = window.setImmediate || globalThis.setImmediate;
window.clearImmediate = window.clearImmediate || globalThis.clearImmediate;
window.crypto = window.crypto || globalThis.crypto;
if (!window.crypto.randomUUID) {
window.crypto.randomUUID = crypto.randomUUID;
}
window.structuredClone = window.structuredClone || globalThis.structuredClone;
window.TextEncoder = window.TextEncoder || TextEncoder;
window.TextDecoder = window.TextDecoder || TextDecoder;
if (streamWeb) {
for (const key of Object.keys(streamWeb)) {
window[key] = window[key] || streamWeb[key];
}
}
}
if (typeof global !== "undefined") {
global.setImmediate = global.setImmediate || globalThis.setImmediate;
global.clearImmediate = global.clearImmediate || globalThis.clearImmediate;
global.crypto = global.crypto || globalThis.crypto;
if (!global.crypto.randomUUID) {
global.crypto.randomUUID = crypto.randomUUID;
}
global.structuredClone = global.structuredClone || globalThis.structuredClone;
global.TextEncoder = global.TextEncoder || TextEncoder;
global.TextDecoder = global.TextDecoder || TextDecoder;
if (streamWeb) {
for (const key of Object.keys(streamWeb)) {
global[key] = global[key] || streamWeb[key];
}
}
}
const edgePrimitives = require("next/dist/compiled/@edge-runtime/primitives");
if (edgePrimitives) {
const G = typeof window !== "undefined" ? window : globalThis;
G.Request = G.Request || edgePrimitives.Request;
G.Response = G.Response || edgePrimitives.Response;
G.Headers = G.Headers || edgePrimitives.Headers;
G.fetch = G.fetch || edgePrimitives.fetch;
if (typeof global !== "undefined") {
global.Request = global.Request || edgePrimitives.Request;
global.Response = global.Response || edgePrimitives.Response;
global.Headers = global.Headers || edgePrimitives.Headers;
global.fetch = global.fetch || edgePrimitives.fetch;
}
}