ua-browser 0.1.0 → 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/README.md CHANGED
@@ -0,0 +1,204 @@
1
+ # uaBrowser - 浏览器检测
2
+
3
+ 通过userAgent和浏览器环境变量检测浏览器、系统及设备类型的常用工具
4
+
5
+ ## npm安装
6
+
7
+ ```javascript
8
+ npm i ua-browser
9
+ ```
10
+
11
+ ## browser安装
12
+
13
+ ```javascript
14
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ua-browser/dist/browser.min.js"></script>
15
+ <script type="text/javascript">
16
+ window.load = function() {
17
+ var ua = uaBrowser()
18
+ }
19
+ </script>
20
+ ```
21
+
22
+ ## method
23
+
24
+ ```typescript
25
+ import { uaBrowser } from 'ua-browser'
26
+
27
+ /** 浏览器解析 */
28
+ uaBrowser(ua?: string): {
29
+ version: string;
30
+ osVersion: string;
31
+ engine: string;
32
+ browser: string;
33
+ os: string;
34
+ device: string;
35
+ isWebview: boolean;
36
+ language: string;
37
+ platfrom: string;
38
+ }
39
+
40
+ /** 检查 `webview` 浏览环境,仅支持 `android` */
41
+ uaBrowser.isWebview(ua: string): boolean
42
+
43
+ /** 检查微信小程序 */
44
+ uaBrowser.isWechatMiniapp(): boolean
45
+
46
+ /** 浏览器语言 */
47
+ uaBrowser.getLanguage(): string
48
+
49
+ /** 当前版本 */
50
+ uaBrowser.VERSION: string
51
+ ```
52
+
53
+ ## 浏览器
54
+ ```typescript
55
+ type browser =
56
+ | 'Safari'
57
+ | 'Chrome'
58
+ | 'IE'
59
+ | 'Edge'
60
+ | 'Firefox'
61
+ | 'Firefox Focus'
62
+ | 'Chromium'
63
+ | 'Opera'
64
+ | 'Vivaldi'
65
+ | 'Yandex'
66
+ | 'Arora'
67
+ | 'Lunascape'
68
+ | 'QupZilla'
69
+ | 'Coc Coc'
70
+ | 'Kindle'
71
+ | 'Iceweasel'
72
+ | 'Konqueror'
73
+ | 'Iceape'
74
+ | 'SeaMonkey'
75
+ | 'Epiphany'
76
+ | '360'
77
+ | '360EE'
78
+ | '360SE'
79
+ | 'UC'
80
+ | 'QQBrowser'
81
+ | 'QQ'
82
+ | 'Baidu'
83
+ | 'Maxthon'
84
+ | 'Sogou'
85
+ | 'Liebao'
86
+ | '2345Explorer'
87
+ | '115Browser'
88
+ | 'TheWorld'
89
+ | 'XiaoMi'
90
+ | 'Quark'
91
+ | 'Qiyu'
92
+ | 'Wechat'
93
+ | 'WechatWork'
94
+ | 'Taobao'
95
+ | 'Alipay'
96
+ | 'Weibo'
97
+ | 'Douban'
98
+ | 'Suning'
99
+ | 'iQiYi'
100
+ | 'DingTalk'
101
+ | 'Huawei'
102
+ | 'Vivo'
103
+ | 'Firefox Nightly'
104
+ | 'Wechat Miniapp'
105
+ ```
106
+
107
+ ## 内核
108
+
109
+ ```typescript
110
+ type engine =
111
+ | 'Trident'
112
+ | 'Presto'
113
+ | 'WebKit'
114
+ | 'Gecko'
115
+ | 'KHTML'
116
+ | 'Blink'
117
+ | 'EdgeHTML'
118
+ ```
119
+
120
+ ## 系统或平台
121
+
122
+ ```typescript
123
+ type os =
124
+ | 'Windows'
125
+ | 'Linux'
126
+ | 'MacOS'
127
+ | 'Android'
128
+ | 'HarmonyOS'
129
+ | 'Ubuntu'
130
+ | 'FreeBSD'
131
+ | 'Debian'
132
+ | 'Windows Phone'
133
+ | 'BlackBerry'
134
+ | 'MeeGo'
135
+ | 'Symbian'
136
+ | 'iOS'
137
+ | 'Chrome OS'
138
+ | 'WebOS'
139
+ ```
140
+
141
+ ## 设备类型
142
+
143
+ ```typescript
144
+ type device =
145
+ | 'Mobile'
146
+ | 'Tablet'
147
+ | 'Pc'
148
+ ```
149
+
150
+ ## 浏览器支持
151
+
152
+ | 浏览器 | 标识 |
153
+ | :-- | :-- |
154
+ | 苹果系统默认浏览器 | `Safari` |
155
+ | 谷歌浏览器 | `Chrome` |
156
+ | 微软IE浏览器 | `IE` |
157
+ | 微软新一代浏览器 | `Edge` |
158
+ | 火狐浏览器 | `Firefox` |
159
+ | 火狐浏览器 | `Firefox Focus` |
160
+ | 谷歌浏览器开源版 | `Chromium` |
161
+ | Opera浏览器 | `Opera` |
162
+ | Opera联合创始人发布 | `Vivaldi` |
163
+ | 俄罗斯最大搜索引擎Yandex出品 | `Yandex` |
164
+ | 基于webkit和Qt的轻量级浏览器 | `Arora` |
165
+ | 来自日本的三引擎浏览器 | `Lunascape` |
166
+ | 轻量级跨平台浏览器 | `QupZilla` |
167
+ | 越南搜索引擎浏览器 | `Coc Coc` |
168
+ | 亚马逊电子书 | `Kindle` |
169
+ | Firefox浏览器的Debian再发布版 | `Iceweasel` |
170
+ | Konqueror | `Konqueror` |
171
+ | Iceape | `Iceape` |
172
+ | SeaMonkey | `SeaMonkey` |
173
+ | Epiphany | `Epiphany` |
174
+ | 360浏览器(手机版) | `360` |
175
+ | 360安全浏览器 | `360EE` |
176
+ | 360极速浏览器 | `360SE` |
177
+ | UC浏览器 | `UC` |
178
+ | QQ浏览器 | `QQBrowser` |
179
+ | QQ客户端 | `QQ` |
180
+ | 百度浏览器 | `Baidu` |
181
+ | 傲游浏览器 | `Maxthon` |
182
+ | 搜狗浏览器 | `Sogou` |
183
+ | 猎豹浏览器 | `Liebao` |
184
+ | 2345浏览器 | `2345Explorer` |
185
+ | 115浏览器 | `115Browser` |
186
+ | 世界之窗浏览器 | `TheWorld` |
187
+ | 小米浏览器 | `XiaoMi` |
188
+ | 夸克浏览器 | `Quark` |
189
+ | 旗鱼浏览器 | `Qiyu` |
190
+ | 微信手机客户端 | `Wechat` |
191
+ | 企业微信客户端 | `WechatWork` |
192
+ | 淘宝手机客户端 | `Taobao` |
193
+ | 支付宝手机客户端 | `Alipay` |
194
+ | 微博手机客户端 | `Weibo` |
195
+ | 豆瓣手机客户端 | `Douban` |
196
+ | 苏宁易购手机客户端 | `Suning` |
197
+ | 爱奇艺手机客户端 | `iQiYi` |
198
+ | 钉钉手机客户端 | `DingTalk` |
199
+ | 华为浏览器 | `Huawei` |
200
+ | Vivo浏览器 | `Vivo` |
201
+ | Firefox 下一代网络浏览器Nightly | `Firefox Nightly` |
202
+ | 微信小程序 | `Wechat Miniapp` |
203
+
204
+
@@ -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 = "1.0.0";
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="1.0.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=["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
@@ -100,9 +100,9 @@ export type EnvOption = EnvPart & EnvWebview & {
100
100
  | 'Pc'
101
101
  }
102
102
 
103
- export function uaBrowser(ua?: string): EnvOption
103
+ declare function uaBrowser(ua?: string): EnvOption
104
104
 
105
- export namespace uaBrowser {
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
- // Window
118
- interface Window {
119
- __wxjs_environment: string
120
- showModalDialog: any
121
- chrome: {
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,6 +1,6 @@
1
1
  {
2
2
  "name": "ua-browser",
3
- "version": "0.1.0",
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
- }