ua-browser 0.1.1 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +27 -15
- package/dist/browser.min.js +1 -1
- package/dist/index.d.ts +13 -10
- package/package.json +53 -53
- package/dist/index.js +0 -7
package/dist/browser.js
CHANGED
|
@@ -11,10 +11,16 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
11
11
|
})(this, function () {
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
var version = "0.1.
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
var version = "0.1.4";
|
|
15
|
+
var NAVIGATOR = {};
|
|
16
|
+
|
|
17
|
+
if (typeof navigator !== 'undefined') {
|
|
18
|
+
NAVIGATOR = navigator;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var UA = NAVIGATOR.userAgent;
|
|
22
|
+
var mimeTypes = NAVIGATOR.mimeTypes;
|
|
23
|
+
var platfrom = NAVIGATOR.platform;
|
|
18
24
|
/** 内核 */
|
|
19
25
|
|
|
20
26
|
var engineRegExp = {
|
|
@@ -55,7 +61,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
55
61
|
QQ: /QQ\//,
|
|
56
62
|
Baidu: /(Baidu|BIDUBrowser|baidubrowser|baiduboxapp|BaiduHD)/,
|
|
57
63
|
Maxthon: /Maxthon/,
|
|
58
|
-
Sogou: /(
|
|
64
|
+
Sogou: /(MetaSr|Sogou)/,
|
|
59
65
|
Liebao: /(LBBROWSER|LieBaoFast)/,
|
|
60
66
|
'2345Explorer': /2345Explorer/,
|
|
61
67
|
'115Browser': /115Browser/,
|
|
@@ -133,13 +139,15 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
133
139
|
};
|
|
134
140
|
|
|
135
141
|
var getLanguage = function getLanguage() {
|
|
136
|
-
|
|
142
|
+
var _a;
|
|
143
|
+
|
|
144
|
+
return (_a = NAVIGATOR.browserLanguage || NAVIGATOR.language) === null || _a === void 0 ? void 0 : _a.replace(/-\w+/g, function (word) {
|
|
137
145
|
return word.toUpperCase();
|
|
138
146
|
});
|
|
139
147
|
};
|
|
140
148
|
|
|
141
149
|
var isWechatMiniapp = function isWechatMiniapp() {
|
|
142
|
-
return
|
|
150
|
+
return typeof __wxjs_environment !== 'undefined' && __wxjs_environment === 'miniprogram';
|
|
143
151
|
};
|
|
144
152
|
|
|
145
153
|
var isWebview = function isWebview(ua) {
|
|
@@ -412,7 +420,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
412
420
|
}, {
|
|
413
421
|
key: "getDevice",
|
|
414
422
|
value: function getDevice() {
|
|
415
|
-
if (platfrom === 'MacIntel' &&
|
|
423
|
+
if (platfrom === 'MacIntel' && NAVIGATOR.maxTouchPoints > 1) {
|
|
416
424
|
return 'Tablet';
|
|
417
425
|
}
|
|
418
426
|
|
|
@@ -441,15 +449,15 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
441
449
|
language: (_a = getLanguage()) !== null && _a !== void 0 ? _a : 'unknown',
|
|
442
450
|
platfrom: platfrom !== null && platfrom !== void 0 ? platfrom : 'unknown'
|
|
443
451
|
};
|
|
452
|
+
var browser = env.browser;
|
|
444
453
|
var is360 = false;
|
|
445
454
|
|
|
446
|
-
if (
|
|
447
|
-
var chrome = window.chrome;
|
|
455
|
+
if (typeof chrome !== 'undefined') {
|
|
448
456
|
var vers = this.ua.replace(/^.*Chrome\/([\d]+).*$/, '$1');
|
|
449
457
|
|
|
450
458
|
if (chrome.adblock2345 || chrome.common2345) {
|
|
451
459
|
env.browser = '2345Explorer';
|
|
452
|
-
} else if (getMimeType('application/360softmgrplugin') || getMimeType('application/mozilla-npqihooquicklogin') || vers > '36' &&
|
|
460
|
+
} else if (getMimeType('application/360softmgrplugin') || getMimeType('application/mozilla-npqihooquicklogin') || vers > '36' && typeof showModalDialog !== 'undefined') {
|
|
453
461
|
is360 = true;
|
|
454
462
|
} else if (vers > '45') {
|
|
455
463
|
is360 = getMimeType('application/vnd.chromium.remoting-viewer');
|
|
@@ -463,13 +471,17 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
463
471
|
if (env.device === 'Mobile' && /iPad/.test(this.ua)) {
|
|
464
472
|
env.device = 'Tablet';
|
|
465
473
|
} else if (is360) {
|
|
466
|
-
if (getMimeType('application/gameplugin') || !((_b =
|
|
467
|
-
|
|
474
|
+
if (getMimeType('application/gameplugin') || !((_b = NAVIGATOR === null || NAVIGATOR === void 0 ? void 0 : NAVIGATOR.connection) === null || _b === void 0 ? void 0 : _b.saveData)) {
|
|
475
|
+
browser = '360SE';
|
|
468
476
|
} else {
|
|
469
|
-
|
|
477
|
+
browser = '360EE';
|
|
470
478
|
}
|
|
471
479
|
}
|
|
472
480
|
|
|
481
|
+
if (hash.browser.indexOf(browser) >= hash.browser.indexOf(env.browser)) {
|
|
482
|
+
env.browser = browser;
|
|
483
|
+
}
|
|
484
|
+
|
|
473
485
|
if (env.browser === 'Baidu' && browserRegExp.Opera.test(this.ua)) {
|
|
474
486
|
env.browser = 'Opera';
|
|
475
487
|
}
|
|
@@ -493,7 +505,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
493
505
|
if (env.browser === 'Chrome' && this.ua.match(/\S+Browser/)) {
|
|
494
506
|
env.browser = this.ua.match(/\S+Browser/)[0];
|
|
495
507
|
env.version = this.ua.replace(/^.*Browser\/([\d.]+).*$/, '$1');
|
|
496
|
-
} else if (env.browser === 'Firefox' && (
|
|
508
|
+
} else if (env.browser === 'Firefox' && (typeof clientInformation !== 'undefined' || !(typeof u2f !== 'undefined'))) {
|
|
497
509
|
env.browser = "".concat(env.browser, " Nightly");
|
|
498
510
|
} else if (env.browser === 'Wechat' && isWechatMiniapp()) {
|
|
499
511
|
env.browser = 'Wechat Miniapp';
|
package/dist/browser.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var n=0;n<r.length;n++){var o=r[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function _createClass(e,r,n){return r&&_defineProperties(e.prototype,r),n&&_defineProperties(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}!function(e,r){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).uaBrowser=r()}(this,(function(){"use strict";var e=navigator.userAgent,r=navigator.mimeTypes,n=navigator.platform,o={Trident:/(Trident|NET CLR)/,Presto:/Presto/,WebKit:/AppleWebKit/,Gecko:/Gecko\//,KHTML:/KHTML\//},i={Safari:/Safari/,Chrome:/(Chrome|CriOS)/,IE:/(MSIE|Trident)/,Edge:/(Edge|Edg\/|EdgA|EdgiOS)/,Firefox:/(Firefox|FxiOS)/,"Firefox Focus":/Focus/,Chromium:/Chromium/,Opera:/(Opera|OPR|OPT)/,Vivaldi:/Vivaldi/,Yandex:/YaBrowser/,Arora:/Arora/,Lunascape:/Lunascape/,QupZilla:/QupZilla/,"Coc Coc":/coc_coc_browser/,Kindle:/(Kindle|Silk\/)/,Iceweasel:/Iceweasel/,Konqueror:/Konqueror/,Iceape:/Iceape/,SeaMonkey:/SeaMonkey/,Epiphany:/Epiphany/,360:/(QihooBrowser|QHBrowser)/,"360EE":/360EE/,"360SE":/360SE/,UC:/(UCBrowser|UBrowser|UCWEB)/,QQBrowser:/QQBrowser/,QQ:/QQ\//,Baidu:/(Baidu|BIDUBrowser|baidubrowser|baiduboxapp|BaiduHD)/,Maxthon:/Maxthon/,Sogou:/(Metasr|Sogou)/,Liebao:/(LBBROWSER|LieBaoFast)/,"2345Explorer":/2345Explorer/,"115Browser":/115Browser/,TheWorld:/TheWorld/,XiaoMi:/MiuiBrowser/,Quark:/Quark/,Qiyu:/Qiyu/,Wechat:/MicroMessenger/,WechatWork:/wxwork\//,Taobao:/AliApp\(TB/,Alipay:/AliApp\(AP/,Weibo:/Weibo/,Douban:/com\.douban\.frodo/,Suning:/SNEBUY-APP/,iQiYi:/IqiyiAp/,DingTalk:/DingTalk/,Huawei:/(HuaweiBrowser|HUAWEI\/|HONOR)/,Vivo:/VivoBrowser/},a={Windows:/Windows/,Linux:/(Linux|X11)/,MacOS:/Macintosh/,Android:/(Android|Adr)/,HarmonyOS:/HarmonyOS/,Ubuntu:/Ubuntu/,FreeBSD:/FreeBSD/,Debian:/Debian/,"Windows Phone":/(IEMobile|Windows Phone)/,BlackBerry:/(BlackBerry|RIM)/,MeeGo:/MeeGo/,Symbian:/Symbian/,iOS:/like Mac OS X/,"Chrome OS":/CrOS/,WebOS:/hpwOS/},u={Mobile:/(Mobi|iPh|480)/,Tablet:/(Tablet|Pad|Nexus 7)/},t={isWebview:/; wv/},c=["Mobile","Tablet"],s=["Windows","Linux","MacOS","Android","HarmonyOS","Ubuntu","FreeBSD","Debian","Windows Phone","BlackBerry","MeeGo","Symbian","iOS","Chrome OS","WebOS"],l=["Trident","Presto","WebKit","Gecko","KHTML"],p=["Safari","Chrome","IE","Edge","Firefox","Firefox Focus","Chromium","Opera","Vivaldi","Yandex","Arora","Lunascape","QupZilla","Coc Coc","Kindle","Iceweasel","Konqueror","Iceape","SeaMonkey","Epiphany","360","360EE","360SE","UC","QQBrowser","QQ","Baidu","Maxthon","Sogou","Liebao","2345Explorer","115Browser","TheWorld","XiaoMi","Quark","Qiyu","Wechat","WechatWork","Taobao","Alipay","Weibo","Douban","Suning","iQiYi","DingTalk","Huawei","Vivo"],d=function(e){try{return!!r.namedItem(e)}catch(e){return!1}},$=function(r,n){for(var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e,i=r.length;i--;){var a=r[i];if(n[a].test(o))return a}return"unknown"},f=function(){return(navigator.browserLanguage||navigator.language).replace(/-\w+/g,(function(e){return e.toUpperCase()}))},w=function(){return"__wxjs_environment"in window&&"miniprogram"===window.__wxjs_environment},h=function(e){return t.isWebview.test(e)},b=new(function(){function r(n){var o=this;_classCallCheck(this,r),this.ua=e,this.version={Safari:function(){return o.ua.replace(/^.*Version\/([\d.]+).*$/,"$1")},Chrome:function(){return o.ua.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1")},IE:function(){return o.ua.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1")},Edge:function(){return o.ua.replace(/^.*Edge\/([\d.]+).*$/,"$1").replace(/^.*Edg\/([\d.]+).*$/,"$1").replace(/^.*EdgA\/([\d.]+).*$/,"$1").replace(/^.*EdgiOS\/([\d.]+).*$/,"$1")},Firefox:function(){return o.ua.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1")},"Firefox Focus":function(){return o.ua.replace(/^.*Focus\/([\d.]+).*$/,"$1")},Chromium:function(){return o.ua.replace(/^.*Chromium\/([\d.]+).*$/,"$1")},Opera:function(){return o.ua.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1").replace(/^.*OPT\/([\d.]+).*$/,"$1")},Vivaldi:function(){return o.ua.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1")},Yandex:function(){return o.ua.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1")},Arora:function(){return o.ua.replace(/^.*Arora\/([\d.]+).*$/,"$1")},Lunascape:function(){return o.ua.replace(/^.*Lunascape[\s]([\d.]+).*$/,"$1")},QupZilla:function(){return o.ua.replace(/^.*QupZilla[\s]([\d.]+).*$/,"$1")},"Coc Coc":function(){return o.ua.replace(/^.*coc_coc_browser\/([\d.]+).*$/,"$1")},Kindle:function(){return o.ua.replace(/^.*Version\/([\d.]+).*$/,"$1")},Iceweasel:function(){return o.ua.replace(/^.*Iceweasel\/([\d.]+).*$/,"$1")},Konqueror:function(){return o.ua.replace(/^.*Konqueror\/([\d.]+).*$/,"$1")},Iceape:function(){return o.ua.replace(/^.*Iceape\/([\d.]+).*$/,"$1")},SeaMonkey:function(){return o.ua.replace(/^.*SeaMonkey\/([\d.]+).*$/,"$1")},Epiphany:function(){return o.ua.replace(/^.*Epiphany\/([\d.]+).*$/,"$1")},Maxthon:function(){return o.ua.replace(/^.*Maxthon\/([\d.]+).*$/,"$1")},QQBrowser:function(){return o.ua.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1")},QQ:function(){return o.ua.replace(/^.*QQ\/([\d.]+).*$/,"$1")},Baidu:function(){return o.ua.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1").replace(/^.*baiduboxapp\/([\d.]+).*$/,"$1")},UC:function(){return o.ua.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1")},Sogou:function(){return o.ua.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1")},TheWorld:function(){return o.ua.replace(/^.*TheWorld ([\d.]+).*$/,"$1")},XiaoMi:function(){return o.ua.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1")},Vivo:function(){return o.ua.replace(/^.*VivoBrowser\/([\d.]+).*$/,"$1")},Quark:function(){return o.ua.replace(/^.*Quark\/([\d.]+).*$/,"$1")},Qiyu:function(){return o.ua.replace(/^.*Qiyu\/([\d.]+).*$/,"$1")},Wechat:function(){return o.ua.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1")},WechatWork:function(){return o.ua.replace(/^.*wxwork\/([\d.]+).*$/,"$1")},Taobao:function(){return o.ua.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1")},Alipay:function(){return o.ua.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1")},Weibo:function(){return o.ua.replace(/^.*weibo__([\d.]+).*$/,"$1")},Douban:function(){return o.ua.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1")},Suning:function(){return o.ua.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1")},iQiYi:function(){return o.ua.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")},DingTalk:function(){return o.ua.replace(/^.*DingTalk\/([\d.]+).*$/,"$1")},Huawei:function(){return o.ua.replace(/^.*Version\/([\d.]+).*$/,"$1").replace(/^.*HuaweiBrowser\/([\d.]+).*$/,"$1")},"115Browser":function(){return o.ua.replace(/^.*115Browser\/([\d.]+).*$/,"$1")},360:function(){return o.ua.replace(/^.*QihooBrowser\/([\d.]+).*$/,"$1")},"360SE":function(){return{86:"13.0",78:"12.0",69:"11.0",63:"10.0",55:"9.1",45:"8.1",42:"8.0",31:"7.0",21:"6.3"}[o.ua.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||""},"360EE":function(){return{86:"13.0",78:"12.0",69:"11.0",63:"9.5",55:"9.0",50:"8.7",30:"7.5"}[o.ua.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||""},"2345Explorer":function(){return{69:"10.0",55:"9.9"}[o.ua.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||o.ua.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1").replace(/^.*Mb2345Browser\/([\d.]+).*$/,"$1")},Liebao:function(){var e="";/LieBaoFast/.test(o.ua)&&(e=o.ua.replace(/^.*LieBaoFast\/([\d.]+).*$/,"$1"));var r=o.ua.replace(/^.*Chrome\/([\d]+).*$/,"$1");return e||{57:"6.5",49:"6.0",46:"5.9",42:"5.3",39:"5.2",34:"5.0",29:"4.5",21:"4.0"}[r]||""}},this.osVersion={Android:function(){return o.ua.replace(/^.*Android ([\d.]+);.*$/,"$1")},iOS:function(){return o.ua.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,".")},Debian:function(){return o.ua.replace(/^.*Debian\/([\d.]+).*$/,"$1")},"Windows Phone":function(){return o.ua.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2")},MacOS:function(){return o.ua.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,".")},WebOS:function(){return o.ua.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")},HarmonyOS:function(){return{10:"2"}[o.ua.replace(/^Mozilla.*Android ([\d.]+)[;)].*$/,"$1")]||""},Windows:function(){var e=o.ua.replace(/^Mozilla\/\d.0 \(Windows NT ([\d.]+);.*$/,"$1");return{10:"10",6.4:"10",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.2:"XP",5.1:"XP","5.0":"2000"}[e]||e}},n&&(this.ua=n)}return _createClass(r,[{key:"getOs",value:function(){return $(s,a,this.ua)}},{key:"getEngine",value:function(){return $(l,o,this.ua)}},{key:"getBrowser",value:function(){return $(p,i,this.ua)}},{key:"getDevice",value:function(){if("MacIntel"===n&&navigator.maxTouchPoints>1)return"Tablet";var e=$(c,u,this.ua);return"unknown"===e?"PC":e}},{key:"getEnv",value:function(r){var o,a;this.ua=r||e;var u={version:"unknown",osVersion:"unknown",engine:this.getEngine(),browser:this.getBrowser(),os:this.getOs(),device:this.getDevice(),isWebview:h(this.ua),language:null!==(o=f())&&void 0!==o?o:"unknown",platfrom:null!=n?n:"unknown"},t=!1;if("chrome"in window){var c=window.chrome,s=this.ua.replace(/^.*Chrome\/([\d]+).*$/,"$1");c.adblock2345||c.common2345?u.browser="2345Explorer":d("application/360softmgrplugin")||d("application/mozilla-npqihooquicklogin")||s>"36"&&window.showModalDialog?t=!0:s>"45"&&!(t=d("application/vnd.chromium.remoting-viewer"))&&s>="69"&&(t=d("application/hwepass2001.installepass2001")||d("application/asx"))}return"Mobile"===u.device&&/iPad/.test(this.ua)?u.device="Tablet":t&&(d("application/gameplugin")||!(null===(a=null===navigator||void 0===navigator?void 0:navigator.connection)||void 0===a?void 0:a.saveData)?u.browser="360SE":u.browser="360EE"),"Baidu"===u.browser&&i.Opera.test(this.ua)&&(u.browser="Opera"),u.os in this.osVersion&&(u.osVersion=this.osVersion[u.os](),u.osVersion===this.ua&&(u.osVersion="unknown")),u.browser in this.version&&(u.version=this.version[u.browser](),u.version===this.ua&&(u.version="unknown")),"Chrome"===u.browser&&this.ua.match(/\S+Browser/)?(u.browser=this.ua.match(/\S+Browser/)[0],u.version=this.ua.replace(/^.*Browser\/([\d.]+).*$/,"$1")):"Firefox"!==u.browser||!("clientInformation"in window)&&"u2f"in window?"Wechat"===u.browser&&w()&&(u.browser="Wechat Miniapp"):u.browser="".concat(u.browser," Nightly"),"Edge"===u.browser?u.engine=parseInt(u.version)>75?"Blink":"EdgeHTML":(i.Chrome.test(this.ua)&&"WebKit"===u.engine&&parseInt(this.version.Chrome())>27||"Opera"===u.browser&&parseInt(u.version)>12||"Yandex"===u.browser)&&(u.engine="Blink"),u}}]),r}());function g(e){return b.getEnv(e)}return g.isWebview=h,g.isWechatMiniapp=w,g.getLanguage=f,g.VERSION="0.1.0",g}));
|
|
1
|
+
function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var n=0;n<r.length;n++){var o=r[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function _createClass(e,r,n){return r&&_defineProperties(e.prototype,r),n&&_defineProperties(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}!function(e,r){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).uaBrowser=r()}(this,(function(){"use strict";var e={};"undefined"!=typeof navigator&&(e=navigator);var r=e.userAgent,n=e.mimeTypes,o=e.platform,i={Trident:/(Trident|NET CLR)/,Presto:/Presto/,WebKit:/AppleWebKit/,Gecko:/Gecko\//,KHTML:/KHTML\//},a={Safari:/Safari/,Chrome:/(Chrome|CriOS)/,IE:/(MSIE|Trident)/,Edge:/(Edge|Edg\/|EdgA|EdgiOS)/,Firefox:/(Firefox|FxiOS)/,"Firefox Focus":/Focus/,Chromium:/Chromium/,Opera:/(Opera|OPR|OPT)/,Vivaldi:/Vivaldi/,Yandex:/YaBrowser/,Arora:/Arora/,Lunascape:/Lunascape/,QupZilla:/QupZilla/,"Coc Coc":/coc_coc_browser/,Kindle:/(Kindle|Silk\/)/,Iceweasel:/Iceweasel/,Konqueror:/Konqueror/,Iceape:/Iceape/,SeaMonkey:/SeaMonkey/,Epiphany:/Epiphany/,360:/(QihooBrowser|QHBrowser)/,"360EE":/360EE/,"360SE":/360SE/,UC:/(UCBrowser|UBrowser|UCWEB)/,QQBrowser:/QQBrowser/,QQ:/QQ\//,Baidu:/(Baidu|BIDUBrowser|baidubrowser|baiduboxapp|BaiduHD)/,Maxthon:/Maxthon/,Sogou:/(MetaSr|Sogou)/,Liebao:/(LBBROWSER|LieBaoFast)/,"2345Explorer":/2345Explorer/,"115Browser":/115Browser/,TheWorld:/TheWorld/,XiaoMi:/MiuiBrowser/,Quark:/Quark/,Qiyu:/Qiyu/,Wechat:/MicroMessenger/,WechatWork:/wxwork\//,Taobao:/AliApp\(TB/,Alipay:/AliApp\(AP/,Weibo:/Weibo/,Douban:/com\.douban\.frodo/,Suning:/SNEBUY-APP/,iQiYi:/IqiyiAp/,DingTalk:/DingTalk/,Huawei:/(HuaweiBrowser|HUAWEI\/|HONOR)/,Vivo:/VivoBrowser/},u={Windows:/Windows/,Linux:/(Linux|X11)/,MacOS:/Macintosh/,Android:/(Android|Adr)/,HarmonyOS:/HarmonyOS/,Ubuntu:/Ubuntu/,FreeBSD:/FreeBSD/,Debian:/Debian/,"Windows Phone":/(IEMobile|Windows Phone)/,BlackBerry:/(BlackBerry|RIM)/,MeeGo:/MeeGo/,Symbian:/Symbian/,iOS:/like Mac OS X/,"Chrome OS":/CrOS/,WebOS:/hpwOS/},t={Mobile:/(Mobi|iPh|480)/,Tablet:/(Tablet|Pad|Nexus 7)/},c={isWebview:/; wv/},s={device:["Mobile","Tablet"],os:["Windows","Linux","MacOS","Android","HarmonyOS","Ubuntu","FreeBSD","Debian","Windows Phone","BlackBerry","MeeGo","Symbian","iOS","Chrome OS","WebOS"],engine:["Trident","Presto","WebKit","Gecko","KHTML"],browser:["Safari","Chrome","IE","Edge","Firefox","Firefox Focus","Chromium","Opera","Vivaldi","Yandex","Arora","Lunascape","QupZilla","Coc Coc","Kindle","Iceweasel","Konqueror","Iceape","SeaMonkey","Epiphany","360","360EE","360SE","UC","QQBrowser","QQ","Baidu","Maxthon","Sogou","Liebao","2345Explorer","115Browser","TheWorld","XiaoMi","Quark","Qiyu","Wechat","WechatWork","Taobao","Alipay","Weibo","Douban","Suning","iQiYi","DingTalk","Huawei","Vivo"]},l=function(e){try{return!!n.namedItem(e)}catch(e){return!1}},p=function(e,n){for(var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r,i=e.length;i--;){var a=e[i];if(n[a].test(o))return a}return"unknown"},d=function(){var r;return null===(r=e.browserLanguage||e.language)||void 0===r?void 0:r.replace(/-\w+/g,(function(e){return e.toUpperCase()}))},f=function(){return"undefined"!=typeof __wxjs_environment&&"miniprogram"===__wxjs_environment},$=function(e){return c.isWebview.test(e)},w=new(function(){function n(e){var o=this;_classCallCheck(this,n),this.ua=r,this.version={Safari:function(){return o.ua.replace(/^.*Version\/([\d.]+).*$/,"$1")},Chrome:function(){return o.ua.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1")},IE:function(){return o.ua.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1")},Edge:function(){return o.ua.replace(/^.*Edge\/([\d.]+).*$/,"$1").replace(/^.*Edg\/([\d.]+).*$/,"$1").replace(/^.*EdgA\/([\d.]+).*$/,"$1").replace(/^.*EdgiOS\/([\d.]+).*$/,"$1")},Firefox:function(){return o.ua.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1")},"Firefox Focus":function(){return o.ua.replace(/^.*Focus\/([\d.]+).*$/,"$1")},Chromium:function(){return o.ua.replace(/^.*Chromium\/([\d.]+).*$/,"$1")},Opera:function(){return o.ua.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1").replace(/^.*OPT\/([\d.]+).*$/,"$1")},Vivaldi:function(){return o.ua.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1")},Yandex:function(){return o.ua.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1")},Arora:function(){return o.ua.replace(/^.*Arora\/([\d.]+).*$/,"$1")},Lunascape:function(){return o.ua.replace(/^.*Lunascape[\s]([\d.]+).*$/,"$1")},QupZilla:function(){return o.ua.replace(/^.*QupZilla[\s]([\d.]+).*$/,"$1")},"Coc Coc":function(){return o.ua.replace(/^.*coc_coc_browser\/([\d.]+).*$/,"$1")},Kindle:function(){return o.ua.replace(/^.*Version\/([\d.]+).*$/,"$1")},Iceweasel:function(){return o.ua.replace(/^.*Iceweasel\/([\d.]+).*$/,"$1")},Konqueror:function(){return o.ua.replace(/^.*Konqueror\/([\d.]+).*$/,"$1")},Iceape:function(){return o.ua.replace(/^.*Iceape\/([\d.]+).*$/,"$1")},SeaMonkey:function(){return o.ua.replace(/^.*SeaMonkey\/([\d.]+).*$/,"$1")},Epiphany:function(){return o.ua.replace(/^.*Epiphany\/([\d.]+).*$/,"$1")},Maxthon:function(){return o.ua.replace(/^.*Maxthon\/([\d.]+).*$/,"$1")},QQBrowser:function(){return o.ua.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1")},QQ:function(){return o.ua.replace(/^.*QQ\/([\d.]+).*$/,"$1")},Baidu:function(){return o.ua.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1").replace(/^.*baiduboxapp\/([\d.]+).*$/,"$1")},UC:function(){return o.ua.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1")},Sogou:function(){return o.ua.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1")},TheWorld:function(){return o.ua.replace(/^.*TheWorld ([\d.]+).*$/,"$1")},XiaoMi:function(){return o.ua.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1")},Vivo:function(){return o.ua.replace(/^.*VivoBrowser\/([\d.]+).*$/,"$1")},Quark:function(){return o.ua.replace(/^.*Quark\/([\d.]+).*$/,"$1")},Qiyu:function(){return o.ua.replace(/^.*Qiyu\/([\d.]+).*$/,"$1")},Wechat:function(){return o.ua.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1")},WechatWork:function(){return o.ua.replace(/^.*wxwork\/([\d.]+).*$/,"$1")},Taobao:function(){return o.ua.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1")},Alipay:function(){return o.ua.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1")},Weibo:function(){return o.ua.replace(/^.*weibo__([\d.]+).*$/,"$1")},Douban:function(){return o.ua.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1")},Suning:function(){return o.ua.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1")},iQiYi:function(){return o.ua.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")},DingTalk:function(){return o.ua.replace(/^.*DingTalk\/([\d.]+).*$/,"$1")},Huawei:function(){return o.ua.replace(/^.*Version\/([\d.]+).*$/,"$1").replace(/^.*HuaweiBrowser\/([\d.]+).*$/,"$1")},"115Browser":function(){return o.ua.replace(/^.*115Browser\/([\d.]+).*$/,"$1")},360:function(){return o.ua.replace(/^.*QihooBrowser\/([\d.]+).*$/,"$1")},"360SE":function(){return{86:"13.0",78:"12.0",69:"11.0",63:"10.0",55:"9.1",45:"8.1",42:"8.0",31:"7.0",21:"6.3"}[o.ua.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||""},"360EE":function(){return{86:"13.0",78:"12.0",69:"11.0",63:"9.5",55:"9.0",50:"8.7",30:"7.5"}[o.ua.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||""},"2345Explorer":function(){return{69:"10.0",55:"9.9"}[o.ua.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||o.ua.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1").replace(/^.*Mb2345Browser\/([\d.]+).*$/,"$1")},Liebao:function(){var e="";/LieBaoFast/.test(o.ua)&&(e=o.ua.replace(/^.*LieBaoFast\/([\d.]+).*$/,"$1"));var r=o.ua.replace(/^.*Chrome\/([\d]+).*$/,"$1");return e||{57:"6.5",49:"6.0",46:"5.9",42:"5.3",39:"5.2",34:"5.0",29:"4.5",21:"4.0"}[r]||""}},this.osVersion={Android:function(){return o.ua.replace(/^.*Android ([\d.]+);.*$/,"$1")},iOS:function(){return o.ua.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,".")},Debian:function(){return o.ua.replace(/^.*Debian\/([\d.]+).*$/,"$1")},"Windows Phone":function(){return o.ua.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2")},MacOS:function(){return o.ua.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,".")},WebOS:function(){return o.ua.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")},HarmonyOS:function(){return{10:"2"}[o.ua.replace(/^Mozilla.*Android ([\d.]+)[;)].*$/,"$1")]||""},Windows:function(){var e=o.ua.replace(/^Mozilla\/\d.0 \(Windows NT ([\d.]+);.*$/,"$1");return{10:"10",6.4:"10",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.2:"XP",5.1:"XP","5.0":"2000"}[e]||e}},e&&(this.ua=e)}return _createClass(n,[{key:"getOs",value:function(){return p(s.os,u,this.ua)}},{key:"getEngine",value:function(){return p(s.engine,i,this.ua)}},{key:"getBrowser",value:function(){return p(s.browser,a,this.ua)}},{key:"getDevice",value:function(){if("MacIntel"===o&&e.maxTouchPoints>1)return"Tablet";var r=p(s.device,t,this.ua);return"unknown"===r?"PC":r}},{key:"getEnv",value:function(n){var i,u;this.ua=n||r;var t={version:"unknown",osVersion:"unknown",engine:this.getEngine(),browser:this.getBrowser(),os:this.getOs(),device:this.getDevice(),isWebview:$(this.ua),language:null!==(i=d())&&void 0!==i?i:"unknown",platfrom:null!=o?o:"unknown"},c=t.browser,p=!1;if("undefined"!=typeof chrome){var w=this.ua.replace(/^.*Chrome\/([\d]+).*$/,"$1");chrome.adblock2345||chrome.common2345?t.browser="2345Explorer":l("application/360softmgrplugin")||l("application/mozilla-npqihooquicklogin")||w>"36"&&"undefined"!=typeof showModalDialog?p=!0:w>"45"&&!(p=l("application/vnd.chromium.remoting-viewer"))&&w>="69"&&(p=l("application/hwepass2001.installepass2001")||l("application/asx"))}return"Mobile"===t.device&&/iPad/.test(this.ua)?t.device="Tablet":p&&(c=l("application/gameplugin")||!(null===(u=null==e?void 0:e.connection)||void 0===u?void 0:u.saveData)?"360SE":"360EE"),s.browser.indexOf(c)>=s.browser.indexOf(t.browser)&&(t.browser=c),"Baidu"===t.browser&&a.Opera.test(this.ua)&&(t.browser="Opera"),t.os in this.osVersion&&(t.osVersion=this.osVersion[t.os](),t.osVersion===this.ua&&(t.osVersion="unknown")),t.browser in this.version&&(t.version=this.version[t.browser](),t.version===this.ua&&(t.version="unknown")),"Chrome"===t.browser&&this.ua.match(/\S+Browser/)?(t.browser=this.ua.match(/\S+Browser/)[0],t.version=this.ua.replace(/^.*Browser\/([\d.]+).*$/,"$1")):"Firefox"!==t.browser||"undefined"==typeof clientInformation&&"undefined"!=typeof u2f?"Wechat"===t.browser&&f()&&(t.browser="Wechat Miniapp"):t.browser="".concat(t.browser," Nightly"),"Edge"===t.browser?t.engine=parseInt(t.version)>75?"Blink":"EdgeHTML":(a.Chrome.test(this.ua)&&"WebKit"===t.engine&&parseInt(this.version.Chrome())>27||"Opera"===t.browser&&parseInt(t.version)>12||"Yandex"===t.browser)&&(t.engine="Blink"),t}}]),n}());function h(e){return w.getEnv(e)}return h.isWebview=$,h.isWechatMiniapp=f,h.getLanguage=d,h.VERSION="0.1.4",h}));
|
package/dist/index.d.ts
CHANGED
|
@@ -100,9 +100,9 @@ export type EnvOption = EnvPart & EnvWebview & {
|
|
|
100
100
|
| 'Pc'
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
declare function uaBrowser(ua?: string): EnvOption
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
declare namespace uaBrowser {
|
|
106
106
|
/** 检查 `webview` 浏览环境,仅支持 `android` */
|
|
107
107
|
function isWebview(ua: string): boolean
|
|
108
108
|
/** 检查微信小程序 */
|
|
@@ -113,17 +113,20 @@ export namespace uaBrowser {
|
|
|
113
113
|
const VERSION: string
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
export default uaBrowser
|
|
117
|
+
|
|
116
118
|
declare global {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
adblock2345: any
|
|
123
|
-
common2345: any
|
|
124
|
-
}
|
|
119
|
+
const __wxjs_environment: string
|
|
120
|
+
|
|
121
|
+
const chrome: {
|
|
122
|
+
adblock2345: any
|
|
123
|
+
common2345: any
|
|
125
124
|
}
|
|
126
125
|
|
|
126
|
+
const showModalDialog: any
|
|
127
|
+
|
|
128
|
+
const u2f: any
|
|
129
|
+
|
|
127
130
|
// Navigator
|
|
128
131
|
interface Navigator {
|
|
129
132
|
browserLanguage: string
|
package/package.json
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ua-browser",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "uaBrowser - 通过 useragent和浏览器环境变量检测浏览器、系统及设备类型工具",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "
|
|
12
|
-
"test": "
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/yangtianxia/ua-browser.git"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
"uaBrowser",
|
|
20
|
-
"userAgent",
|
|
21
|
-
"typescript"
|
|
22
|
-
],
|
|
23
|
-
"author": "yangtianxia",
|
|
24
|
-
"license": "MIT",
|
|
25
|
-
"bugs": {
|
|
26
|
-
"url": "https://github.com/yangtianxia/ua-browser/issues"
|
|
27
|
-
},
|
|
28
|
-
"homepage": "https://github.com/yangtianxia/ua-browser#readme",
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"@babel/core": "^7.14.6",
|
|
31
|
-
"@babel/polyfill": "^7.12.1",
|
|
32
|
-
"@babel/preset-env": "^7.14.7",
|
|
33
|
-
"@rollup/plugin-babel": "^5.3.1",
|
|
34
|
-
"@rollup/plugin-commonjs": "^21.1.0",
|
|
35
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
36
|
-
"@rollup/plugin-node-resolve": "^13.2.1",
|
|
37
|
-
"@rollup/plugin-typescript": "^8.3.2",
|
|
38
|
-
"@types/node": "^17.0.25",
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "^5.20.0",
|
|
40
|
-
"@typescript-eslint/parser": "^5.20.0",
|
|
41
|
-
"babel-preset-env": "^1.7.0",
|
|
42
|
-
"core-js": "^3.22.2",
|
|
43
|
-
"eslint": "^8.13.0",
|
|
44
|
-
"eslint-plugin-import": "^2.26.0",
|
|
45
|
-
"rollup": "^2.70.2",
|
|
46
|
-
"rollup-plugin-dts": "^4.2.1",
|
|
47
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
48
|
-
"shx": "^0.3.4",
|
|
49
|
-
"tslib": "^2.3.1",
|
|
50
|
-
"typescript": "^4.6.3"
|
|
51
|
-
},
|
|
52
|
-
"dependencies": {}
|
|
53
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ua-browser",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "uaBrowser - 通过 useragent和浏览器环境变量检测浏览器、系统及设备类型工具",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "shx rm -rf dist && rollup --config rollup.config.ts --configPlugin typescript && shx cp src/types.d.ts dist/index.d.ts",
|
|
12
|
+
"test": "node example/index.js"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/yangtianxia/ua-browser.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"uaBrowser",
|
|
20
|
+
"userAgent",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"author": "yangtianxia",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/yangtianxia/ua-browser/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/yangtianxia/ua-browser#readme",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@babel/core": "^7.14.6",
|
|
31
|
+
"@babel/polyfill": "^7.12.1",
|
|
32
|
+
"@babel/preset-env": "^7.14.7",
|
|
33
|
+
"@rollup/plugin-babel": "^5.3.1",
|
|
34
|
+
"@rollup/plugin-commonjs": "^21.1.0",
|
|
35
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^13.2.1",
|
|
37
|
+
"@rollup/plugin-typescript": "^8.3.2",
|
|
38
|
+
"@types/node": "^17.0.25",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.20.0",
|
|
40
|
+
"@typescript-eslint/parser": "^5.20.0",
|
|
41
|
+
"babel-preset-env": "^1.7.0",
|
|
42
|
+
"core-js": "^3.22.2",
|
|
43
|
+
"eslint": "^8.13.0",
|
|
44
|
+
"eslint-plugin-import": "^2.26.0",
|
|
45
|
+
"rollup": "^2.70.2",
|
|
46
|
+
"rollup-plugin-dts": "^4.2.1",
|
|
47
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
48
|
+
"shx": "^0.3.4",
|
|
49
|
+
"tslib": "^2.3.1",
|
|
50
|
+
"typescript": "^4.6.3"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {}
|
|
53
|
+
}
|