-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathenv.ts
31 lines (26 loc) · 1.67 KB
/
env.ts
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
export const id = Symbol.for("id");
declare const WorkerGlobalScope: Function | undefined;
declare const DedicatedWorkerGlobalScope: Function | undefined;
declare const ServiceWorkerGlobalScope: Function | undefined;
declare const SharedWorkerGlobalScope: Function | undefined;
export const isBrowserWindow = typeof window === "object"
&& typeof window.document === "object"
&& typeof window.matchMedia === "function";
export const isServiceWorker = typeof ServiceWorkerGlobalScope === "function"
&& globalThis instanceof ServiceWorkerGlobalScope;
export const isSharedWorker = typeof SharedWorkerGlobalScope === "function"
&& globalThis instanceof SharedWorkerGlobalScope;
export const isDedicatedWorker = typeof DedicatedWorkerGlobalScope === "function"
&& globalThis instanceof DedicatedWorkerGlobalScope;
export const isWorker = isServiceWorker || isSharedWorker || isDedicatedWorker;
export const isDeno = typeof Deno === "object" && !!Deno.version?.deno;
export const isBun = typeof Bun === "object" && !!Bun.version;
export const isNodeLike = typeof process === "object" && !!process.versions?.node && !isDeno;
export const isNode: boolean = isNodeLike && !isDeno && !isBun;
export const isNodeBelow14 = isNode && parseInt(process.version.slice(1)) < 14;
export const isNodeBelow16 = isNode && parseInt(process.version.slice(1)) < 16;
export const isNodeBelow20 = isNode && parseInt(process.version.slice(1)) < 20;
const isNodeWorkerThread = isNode
&& ((process.abort as any).disabled === true || process.argv.includes("--worker-thread"));
export const isMainThread = !isNodeWorkerThread
&& (isBun ? (Bun.isMainThread as boolean) : typeof WorkerGlobalScope === "undefined");