Skip to content

Commit

Permalink
fix: detecting execution environment, when browser have declared glob…
Browse files Browse the repository at this point in the history
…al property.
  • Loading branch information
dawidgil committed Oct 1, 2021
1 parent c387f21 commit 4d11e58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/api/modules/utils_detectEnvironment.md
Expand Up @@ -14,8 +14,8 @@

### detectExecutionEnvironment

`Const` **detectExecutionEnvironment**(): `any`
`Const` **detectExecutionEnvironment**(): `ExecutionEnvironment`

#### Returns

`any`
`ExecutionEnvironment`
6 changes: 3 additions & 3 deletions src/utils/detectEnvironment.ts
Expand Up @@ -4,8 +4,8 @@ export enum ExecutionEnvironment {
}

export const detectExecutionEnvironment = () =>
(isNode() && ExecutionEnvironment.NODE) || (isBrowser() && ExecutionEnvironment.BROWSER);
isNode() && !isBrowser() ? ExecutionEnvironment.NODE : ExecutionEnvironment.BROWSER;

const isNode = new Function("try { return this === global } catch(e) { return false; }");
const isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;

const isBrowser = new Function("try { return this === window } catch(e) { return false; }");
const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";

0 comments on commit 4d11e58

Please sign in to comment.