File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change 1
- const isBrowser =
2
- ( typeof window !== 'undefined' && typeof window . document !== 'undefined' ) ||
3
- // eslint-disable-next-line no-restricted-globals
4
- ( typeof self === 'object' &&
5
- // eslint-disable-next-line no-restricted-globals
6
- self . constructor &&
1
+ const isStandardBrowserEnv = ( ) =>
2
+ typeof window !== 'undefined' && typeof window . document !== 'undefined'
3
+
4
+ const isWebWorkerEnv = ( ) =>
5
+ Boolean (
7
6
// eslint-disable-next-line no-restricted-globals
8
- self . constructor . name === 'DedicatedWorkerGlobalScope' ) || // is web worker
9
- ( typeof navigator !== 'undefined' && navigator . product === 'ReactNative' ) // while navigator.product is deprecated
7
+ typeof self === 'object' &&
8
+ // eslint-disable-next-line no-restricted-globals
9
+ self ?. constructor ?. name ?. includes ( 'WorkerGlobalScope' ) ,
10
+ )
11
+
12
+ const isReactNativeEnv = ( ) =>
13
+ typeof navigator !== 'undefined' && navigator . product === 'ReactNative'
14
+
15
+ const isBrowser =
16
+ isStandardBrowserEnv ( ) || isWebWorkerEnv ( ) || isReactNativeEnv ( )
10
17
11
18
export default isBrowser
You can’t perform that action at this time.
0 commit comments