Skip to content

Commit

Permalink
chore: simplify env check
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Oct 21, 2024
1 parent b815fcb commit f497863
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 32 deletions.
15 changes: 6 additions & 9 deletions dist/browser/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/browser/constants.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 7 additions & 10 deletions dist/node/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/node/constants.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/types/constants.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Environment } from "./types";
export declare const isBrowser: boolean;
export declare const environment: Environment;
export declare const CHUNK_SIZE: number;
export declare const BUFFER_SIZE = 4096;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@filen/sdk",
"version": "0.1.170",
"version": "0.1.171",
"description": "Filen SDK",
"main": "dist/node/index.js",
"browser": "dist/browser/index.js",
Expand Down
17 changes: 7 additions & 10 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import type { Environment } from "./types"

const env = {
isBrowser:
(typeof window !== "undefined" && typeof window.document !== "undefined") ||
// @ts-expect-error WorkerEnv's are not typed
(typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope) ||
// @ts-expect-error WorkerEnv's are not typed
(typeof ServiceWorkerGlobalScope !== "undefined" && self instanceof ServiceWorkerGlobalScope),
isNode: typeof process !== "undefined" && process.versions !== null && process.versions.node !== null
} as const
export const isBrowser =
(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.navigator !== "undefined") ||
// @ts-expect-error WorkerEnv's are not typed
(typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope) ||
// @ts-expect-error WorkerEnv's are not typed
(typeof ServiceWorkerGlobalScope !== "undefined" && self instanceof ServiceWorkerGlobalScope)

export const environment: Environment = env.isBrowser ? "browser" : "node"
export const environment: Environment = isBrowser ? "browser" : "node"

export const CHUNK_SIZE = 1024 * 1024
export const BUFFER_SIZE = 4096
Expand Down

0 comments on commit f497863

Please sign in to comment.