ua-browser 0.1.2 → 0.1.3

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 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.1";
15
- var UA = navigator.userAgent;
16
- var mimeTypes = navigator.mimeTypes;
17
- var platfrom = navigator.platform;
14
+ var version = "0.1.2";
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 = {
@@ -133,13 +139,15 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
133
139
  };
134
140
 
135
141
  var getLanguage = function getLanguage() {
136
- return (navigator.browserLanguage || navigator.language).replace(/-\w+/g, function (word) {
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 '__wxjs_environment' in window && window.__wxjs_environment === 'miniprogram';
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' && navigator.maxTouchPoints > 1) {
423
+ if (platfrom === 'MacIntel' && NAVIGATOR.maxTouchPoints > 1) {
416
424
  return 'Tablet';
417
425
  }
418
426
 
@@ -443,13 +451,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
443
451
  };
444
452
  var is360 = false;
445
453
 
446
- if ('chrome' in window) {
447
- var chrome = window.chrome;
454
+ if (typeof chrome !== 'undefined') {
448
455
  var vers = this.ua.replace(/^.*Chrome\/([\d]+).*$/, '$1');
449
456
 
450
457
  if (chrome.adblock2345 || chrome.common2345) {
451
458
  env.browser = '2345Explorer';
452
- } else if (getMimeType('application/360softmgrplugin') || getMimeType('application/mozilla-npqihooquicklogin') || vers > '36' && window.showModalDialog) {
459
+ } else if (getMimeType('application/360softmgrplugin') || getMimeType('application/mozilla-npqihooquicklogin') || vers > '36' && typeof showModalDialog !== 'undefined') {
453
460
  is360 = true;
454
461
  } else if (vers > '45') {
455
462
  is360 = getMimeType('application/vnd.chromium.remoting-viewer');
@@ -463,7 +470,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
463
470
  if (env.device === 'Mobile' && /iPad/.test(this.ua)) {
464
471
  env.device = 'Tablet';
465
472
  } else if (is360) {
466
- if (getMimeType('application/gameplugin') || !((_b = navigator === null || navigator === void 0 ? void 0 : navigator.connection) === null || _b === void 0 ? void 0 : _b.saveData)) {
473
+ if (getMimeType('application/gameplugin') || !((_b = NAVIGATOR === null || NAVIGATOR === void 0 ? void 0 : NAVIGATOR.connection) === null || _b === void 0 ? void 0 : _b.saveData)) {
467
474
  env.browser = '360SE';
468
475
  } else {
469
476
  env.browser = '360EE';
@@ -493,7 +500,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
493
500
  if (env.browser === 'Chrome' && this.ua.match(/\S+Browser/)) {
494
501
  env.browser = this.ua.match(/\S+Browser/)[0];
495
502
  env.version = this.ua.replace(/^.*Browser\/([\d.]+).*$/, '$1');
496
- } else if (env.browser === 'Firefox' && ('clientInformation' in window || !('u2f' in window))) {
503
+ } else if (env.browser === 'Firefox' && (typeof clientInformation !== 'undefined' || !(typeof u2f !== 'undefined'))) {
497
504
  env.browser = "".concat(env.browser, " Nightly");
498
505
  } else if (env.browser === 'Wechat' && isWechatMiniapp()) {
499
506
  env.browser = 'Wechat Miniapp';
@@ -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.1",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=["Mobile","Tablet"],l=["Windows","Linux","MacOS","Android","HarmonyOS","Ubuntu","FreeBSD","Debian","Windows Phone","BlackBerry","MeeGo","Symbian","iOS","Chrome OS","WebOS"],p=["Trident","Presto","WebKit","Gecko","KHTML"],d=["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"],f=function(e){try{return!!n.namedItem(e)}catch(e){return!1}},$=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"},w=function(){var r;return null===(r=e.browserLanguage||e.language)||void 0===r?void 0:r.replace(/-\w+/g,(function(e){return e.toUpperCase()}))},h=function(){return"undefined"!=typeof __wxjs_environment&&"miniprogram"===__wxjs_environment},b=function(e){return c.isWebview.test(e)},g=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 $(l,u,this.ua)}},{key:"getEngine",value:function(){return $(p,i,this.ua)}},{key:"getBrowser",value:function(){return $(d,a,this.ua)}},{key:"getDevice",value:function(){if("MacIntel"===o&&e.maxTouchPoints>1)return"Tablet";var r=$(s,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:b(this.ua),language:null!==(i=w())&&void 0!==i?i:"unknown",platfrom:null!=o?o:"unknown"},c=!1;if("undefined"!=typeof chrome){var s=this.ua.replace(/^.*Chrome\/([\d]+).*$/,"$1");chrome.adblock2345||chrome.common2345?t.browser="2345Explorer":f("application/360softmgrplugin")||f("application/mozilla-npqihooquicklogin")||s>"36"&&"undefined"!=typeof showModalDialog?c=!0:s>"45"&&!(c=f("application/vnd.chromium.remoting-viewer"))&&s>="69"&&(c=f("application/hwepass2001.installepass2001")||f("application/asx"))}return"Mobile"===t.device&&/iPad/.test(this.ua)?t.device="Tablet":c&&(f("application/gameplugin")||!(null===(u=null==e?void 0:e.connection)||void 0===u?void 0:u.saveData)?t.browser="360SE":t.browser="360EE"),"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&&h()&&(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 m(e){return g.getEnv(e)}return m.isWebview=b,m.isWechatMiniapp=h,m.getLanguage=w,m.VERSION="0.1.2",m}));
package/dist/index.d.ts CHANGED
@@ -116,16 +116,17 @@ declare namespace uaBrowser {
116
116
  export default uaBrowser
117
117
 
118
118
  declare global {
119
- // Window
120
- interface Window {
121
- __wxjs_environment: string
122
- showModalDialog: any
123
- chrome: {
124
- adblock2345: any
125
- common2345: any
126
- }
119
+ const __wxjs_environment: string
120
+
121
+ const chrome: {
122
+ adblock2345: any
123
+ common2345: any
127
124
  }
128
125
 
126
+ const showModalDialog: any
127
+
128
+ const u2f: any
129
+
129
130
  // Navigator
130
131
  interface Navigator {
131
132
  browserLanguage: string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ua-browser",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "uaBrowser - 通过 useragent和浏览器环境变量检测浏览器、系统及设备类型工具",
5
5
  "main": "index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,8 +8,8 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "build": "rimraf dist && rollup --config rollup.config.ts --configPlugin typescript && shx cp src/types.d.ts dist/index.d.ts && shx cp index.js dist/index.js",
12
- "test": "echo \"Error: no test specified\" && exit 1"
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
13
  },
14
14
  "repository": {
15
15
  "type": "git",
package/dist/index.js DELETED
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.ENV_NODE === 'production') {
4
- module.exports = require('./dist/browser.min.js')
5
- } else {
6
- module.exports = require('./dist/browser.js')
7
- }