source: frontend/node_modules/axios/lib/platform/common/utils.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

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