fetch-detector
Advanced tools
Comparing version 1.0.0 to 1.0.1
44
index.js
@@ -1,26 +0,28 @@ | ||
// 检测浏览器版本,并设置 window.__disableNativeFetch 来决定是否开启 fetch | ||
var userAgent = navigator.userAgent || ""; | ||
var appVersion = navigator.appVersion || ""; | ||
var vendor = navigator.vendor || ""; | ||
if (navigator && navigator.userAgent) { | ||
// 检测浏览器版本,并设置 window.__disableNativeFetch 来决定是否开启 fetch | ||
var userAgent = navigator.userAgent || ""; | ||
var appVersion = navigator.appVersion || ""; | ||
var vendor = navigator.vendor || ""; | ||
var ua = (userAgent + ' ' + appVersion + ' ' + vendor).toLowerCase(); | ||
var ua = (userAgent + ' ' + appVersion + ' ' + vendor).toLowerCase(); | ||
var match = /(chrome)[ \/]([\w.]+)/.exec(ua) | ||
|| /(webkit)[ \/]([\w.]+)/.exec(ua) | ||
|| /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) | ||
|| /(msie) ([\w.]+)/.exec(ua) | ||
|| /(trident)(?:.*? rv:([\w.]+)|)/.exec(ua) | ||
|| ua.indexOf("compatible") < 0 | ||
&& /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || []; | ||
var match = /(chrome)[ \/]([\w.]+)/.exec(ua) | ||
|| /(webkit)[ \/]([\w.]+)/.exec(ua) | ||
|| /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) | ||
|| /(msie) ([\w.]+)/.exec(ua) | ||
|| /(trident)(?:.*? rv:([\w.]+)|)/.exec(ua) | ||
|| ua.indexOf("compatible") < 0 | ||
&& /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || []; | ||
var engine = match[0]; | ||
var mainVersion = match[2].split('.')[0]; | ||
var engine = match[0]; | ||
var mainVersion = match[2].split('.')[0]; | ||
// chrome 内核版本大于 46, firefox 版本大于39 才开启 fetch | ||
if (engine.indexOf('chrome') === 0 && mainVersion >= 46) { | ||
window.__disableNativeFetch = false; | ||
} else if (engine.indexOf('mozilla') === 0 && mainVersion >= 39) { | ||
window.__disableNativeFetch = false; | ||
} else { | ||
window.__disableNativeFetch = true; | ||
// chrome 内核版本大于 46, firefox 版本大于39 才开启 fetch | ||
if (engine.indexOf('chrome') === 0 && mainVersion >= 46) { | ||
window.__disableNativeFetch = false; | ||
} else if (engine.indexOf('mozilla') === 0 && mainVersion >= 39) { | ||
window.__disableNativeFetch = false; | ||
} else { | ||
window.__disableNativeFetch = true; | ||
} | ||
} |
{ | ||
"name": "fetch-detector", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Detector fetch based on browser version", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
## Fetch Detector | ||
有些浏览器虽然支持 Fetch API 但不完整,如 Chrome 45 和 Firefox 33 版本 response | ||
中的[中文会乱码](https://lists.w3.org/Archives/Public/public-webapps-github/2015Aug/0218.html)。本库的作用是只在 Chrome >= 46,Firefox >= 39 时才开启原生 | ||
中的[中文会乱码](https://code.google.com/p/chromium/issues/detail?id=511289)[2](https://code.google.com/p/chromium/issues/detail?id=516931)。本库的作用是只在 Chrome >= 46,Firefox >= 39 时才开启原生 | ||
Fetch,否则使用 XHR polyfill。 | ||
@@ -9,3 +9,5 @@ | ||
``` | ||
npm install 'fetch-detector' | ||
``` | ||
@@ -16,3 +18,3 @@ ## Usage | ||
``` | ||
```js | ||
import 'fetch-detector' | ||
@@ -22,1 +24,3 @@ import 'fetch-ie8' | ||
## License | ||
MIT |
Possible typosquat attack
Supply chain riskThere is a package with a similar name that is downloaded much more often.
Did you mean |
---|
watch-detector |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2239
24
24
1