[d24f17c] | 1 | const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | * Determine if we're running in a standard browser environment
|
---|
| 5 | *
|
---|
| 6 | * This allows axios to run in a web worker, and react-native.
|
---|
| 7 | * Both environments support XMLHttpRequest, but not fully standard globals.
|
---|
| 8 | *
|
---|
| 9 | * web workers:
|
---|
| 10 | * typeof window -> undefined
|
---|
| 11 | * typeof document -> undefined
|
---|
| 12 | *
|
---|
| 13 | * react-native:
|
---|
| 14 | * navigator.product -> 'ReactNative'
|
---|
| 15 | * nativescript
|
---|
| 16 | * navigator.product -> 'NativeScript' or 'NS'
|
---|
| 17 | *
|
---|
| 18 | * @returns {boolean}
|
---|
| 19 | */
|
---|
| 20 | const hasStandardBrowserEnv = (
|
---|
| 21 | (product) => {
|
---|
| 22 | return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
|
---|
| 23 | })(typeof navigator !== 'undefined' && navigator.product);
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | * Determine if we're running in a standard browser webWorker environment
|
---|
| 27 | *
|
---|
| 28 | * Although the `isStandardBrowserEnv` method indicates that
|
---|
| 29 | * `allows axios to run in a web worker`, the WebWorker will still be
|
---|
| 30 | * filtered out due to its judgment standard
|
---|
| 31 | * `typeof window !== 'undefined' && typeof document !== 'undefined'`.
|
---|
| 32 | * This leads to a problem when axios post `FormData` in webWorker
|
---|
| 33 | */
|
---|
| 34 | const hasStandardBrowserWebWorkerEnv = (() => {
|
---|
| 35 | return (
|
---|
| 36 | typeof WorkerGlobalScope !== 'undefined' &&
|
---|
| 37 | // eslint-disable-next-line no-undef
|
---|
| 38 | self instanceof WorkerGlobalScope &&
|
---|
| 39 | typeof self.importScripts === 'function'
|
---|
| 40 | );
|
---|
| 41 | })();
|
---|
| 42 |
|
---|
| 43 | export {
|
---|
| 44 | hasBrowserEnv,
|
---|
| 45 | hasStandardBrowserWebWorkerEnv,
|
---|
| 46 | hasStandardBrowserEnv
|
---|
| 47 | }
|
---|