2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

added proper detection of react-native in isStandardBrowserEnv function

This commit is contained in:
Viktor
2017-02-25 12:14:43 +01:00
parent 68ec2abc4a
commit 603bd2f66c
+6 -3
View File
@@ -169,19 +169,22 @@ function trim(str) {
* *
* This allows axios to run in a web worker, and react-native. * This allows axios to run in a web worker, and react-native.
* Both environments support XMLHttpRequest, but not fully standard globals. * Both environments support XMLHttpRequest, but not fully standard globals.
* As of react-native 0.13, it can be identified from navigator.product.
* *
* web workers: * web workers:
* typeof window -> undefined * typeof window -> undefined
* typeof document -> undefined * typeof document -> undefined
* *
* react-native: * react-native:
* typeof document.createElement -> undefined * navigator.product -> 'ReactNative'
*/ */
function isStandardBrowserEnv() { function isStandardBrowserEnv() {
if (typeof navigator.product !== 'undefined' && navigator.product === 'ReactNative') {
return false;
}
return ( return (
typeof window !== 'undefined' && typeof window !== 'undefined' &&
typeof document !== 'undefined' && typeof document !== 'undefined'
typeof document.createElement === 'function'
); );
} }