source: imaps-frontend/node_modules/axios/lib/platform/common/utils.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • 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 = hasBrowserEnv &&
23 (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
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
43const origin = hasBrowserEnv && window.location.href || 'http://localhost';
44
45export {
46 hasBrowserEnv,
47 hasStandardBrowserWebWorkerEnv,
48 hasStandardBrowserEnv,
49 _navigator as navigator,
50 origin
51}
Note: See TracBrowser for help on using the repository browser.