source: node_modules/axios/lib/platform/common/utils.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1const 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 */
20const 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 */
34const 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
43export {
44 hasBrowserEnv,
45 hasStandardBrowserWebWorkerEnv,
46 hasStandardBrowserEnv
47}
Note: See TracBrowser for help on using the repository browser.