Skip to content

Commit 666ba71

Browse files
rohan-deshpandeflexdinesh
authored andcommittedJun 25, 2020
Added isJsDom function to check for jsdom environments
1 parent dd3970e commit 666ba71

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed
 

‎src/index.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
/* global window self */
22

3-
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
3+
const isBrowser =
4+
typeof window !== "undefined" && typeof window.document !== "undefined";
45

56
/* eslint-disable no-restricted-globals */
67
const isWebWorker =
7-
typeof self === 'object' &&
8+
typeof self === "object" &&
89
self.constructor &&
9-
self.constructor.name === 'DedicatedWorkerGlobalScope';
10+
self.constructor.name === "DedicatedWorkerGlobalScope";
1011
/* eslint-enable no-restricted-globals */
1112

1213
const isNode =
13-
typeof process !== 'undefined' &&
14+
typeof process !== "undefined" &&
1415
process.versions != null &&
1516
process.versions.node != null;
1617

17-
export {
18-
isBrowser,
19-
isWebWorker,
20-
isNode
21-
};
18+
/**
19+
* @see https://github.com/jsdom/jsdom/releases/tag/12.0.0
20+
* @see https://github.com/jsdom/jsdom/issues/1537
21+
*/
22+
const isJsDom = () =>
23+
(typeof window !== "undefined" && window.name === "nodejs") ||
24+
navigator.userAgent.includes("Node.js") ||
25+
navigator.userAgent.includes("jsdom");
26+
27+
export { isBrowser, isWebWorker, isNode, isJsDom };

0 commit comments

Comments
 (0)
Please sign in to comment.