ua-browser 0.1.4 → 0.1.6
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/index.cjs.js +568 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.esm.mjs +566 -0
- package/dist/index.min.js +1 -0
- package/index.js +2 -2
- package/package.json +16 -6
- package/dist/browser.js +0 -538
- package/dist/browser.min.js +0 -1
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
|
|
5
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
6
|
+
|
|
7
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
|
+
|
|
9
|
+
var version = "0.1.5";
|
|
10
|
+
var NAVIGATOR = {};
|
|
11
|
+
|
|
12
|
+
if (typeof navigator !== 'undefined') {
|
|
13
|
+
NAVIGATOR = navigator;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
var UA = NAVIGATOR.userAgent || '';
|
|
17
|
+
var mimeTypes = NAVIGATOR.mimeTypes;
|
|
18
|
+
var platfrom = NAVIGATOR.platform;
|
|
19
|
+
/** 内核 */
|
|
20
|
+
|
|
21
|
+
var engineRegExp = {
|
|
22
|
+
Trident: /(Trident|NET CLR)/,
|
|
23
|
+
Presto: /Presto/,
|
|
24
|
+
WebKit: /AppleWebKit/,
|
|
25
|
+
Gecko: /Gecko\//,
|
|
26
|
+
KHTML: /KHTML\//
|
|
27
|
+
};
|
|
28
|
+
/** 浏览器 */
|
|
29
|
+
|
|
30
|
+
var browserRegExp = {
|
|
31
|
+
Safari: /Safari/,
|
|
32
|
+
Chrome: /(Chrome|CriOS)/,
|
|
33
|
+
IE: /(MSIE|Trident)/,
|
|
34
|
+
Edge: /(Edge|Edg\/|EdgA|EdgiOS)/,
|
|
35
|
+
Firefox: /(Firefox|FxiOS)/,
|
|
36
|
+
'Firefox Focus': /Focus/,
|
|
37
|
+
Chromium: /Chromium/,
|
|
38
|
+
Opera: /(Opera|OPR|OPT)/,
|
|
39
|
+
Vivaldi: /Vivaldi/,
|
|
40
|
+
Yandex: /YaBrowser/,
|
|
41
|
+
Arora: /Arora/,
|
|
42
|
+
Lunascape: /Lunascape/,
|
|
43
|
+
QupZilla: /QupZilla/,
|
|
44
|
+
'Coc Coc': /coc_coc_browser/,
|
|
45
|
+
Kindle: /(Kindle|Silk\/)/,
|
|
46
|
+
Iceweasel: /Iceweasel/,
|
|
47
|
+
Konqueror: /Konqueror/,
|
|
48
|
+
Iceape: /Iceape/,
|
|
49
|
+
SeaMonkey: /SeaMonkey/,
|
|
50
|
+
Epiphany: /Epiphany/,
|
|
51
|
+
'360': /(QihooBrowser|QHBrowser)/,
|
|
52
|
+
'360EE': /360EE/,
|
|
53
|
+
'360SE': /360SE/,
|
|
54
|
+
UC: /(UCBrowser|UBrowser|UCWEB)/,
|
|
55
|
+
QQBrowser: /QQBrowser/,
|
|
56
|
+
QQ: /QQ\//,
|
|
57
|
+
Baidu: /(Baidu|BIDUBrowser|baidubrowser|baiduboxapp|BaiduHD)/,
|
|
58
|
+
Maxthon: /Maxthon/,
|
|
59
|
+
Sogou: /(MetaSr|Sogou)/,
|
|
60
|
+
Liebao: /(LBBROWSER|LieBaoFast)/,
|
|
61
|
+
'2345Explorer': /2345Explorer/,
|
|
62
|
+
'115Browser': /115Browser/,
|
|
63
|
+
TheWorld: /TheWorld/,
|
|
64
|
+
XiaoMi: /MiuiBrowser/,
|
|
65
|
+
Vivo: /VivoBrowser/,
|
|
66
|
+
Huawei: /HuaweiBrowser/,
|
|
67
|
+
OPPO: /HeyTapBrowser/,
|
|
68
|
+
Quark: /Quark/,
|
|
69
|
+
Qiyu: /Qiyu/,
|
|
70
|
+
Wechat: /MicroMessenger/,
|
|
71
|
+
WechatWork: /wxwork\//,
|
|
72
|
+
Taobao: /AliApp\(TB/,
|
|
73
|
+
Alipay: /AliApp\(AP/,
|
|
74
|
+
Weibo: /Weibo/,
|
|
75
|
+
Douban: /com\.douban\.frodo/,
|
|
76
|
+
Suning: /SNEBUY-APP/,
|
|
77
|
+
iQiYi: /IqiyiApp/,
|
|
78
|
+
DingTalk: /DingTalk/,
|
|
79
|
+
Douyin: /aweme/
|
|
80
|
+
};
|
|
81
|
+
/** 系统或平台 */
|
|
82
|
+
|
|
83
|
+
var osRegExp = {
|
|
84
|
+
Windows: /Windows/,
|
|
85
|
+
Linux: /(Linux|X11)/,
|
|
86
|
+
MacOS: /Macintosh/,
|
|
87
|
+
Android: /(Android|Adr)/,
|
|
88
|
+
HarmonyOS: /HarmonyOS/,
|
|
89
|
+
Ubuntu: /Ubuntu/,
|
|
90
|
+
FreeBSD: /FreeBSD/,
|
|
91
|
+
Debian: /Debian/,
|
|
92
|
+
'Windows Phone': /(IEMobile|Windows Phone)/,
|
|
93
|
+
BlackBerry: /(BlackBerry|RIM)/,
|
|
94
|
+
MeeGo: /MeeGo/,
|
|
95
|
+
Symbian: /Symbian/,
|
|
96
|
+
iOS: /like Mac OS X/,
|
|
97
|
+
'Chrome OS': /CrOS/,
|
|
98
|
+
WebOS: /hpwOS/
|
|
99
|
+
};
|
|
100
|
+
/** 设备 */
|
|
101
|
+
|
|
102
|
+
var deviceRegExp = {
|
|
103
|
+
Mobile: /(Mobi|iPh|480)/,
|
|
104
|
+
Tablet: /(Tablet|Pad|Nexus 7)/
|
|
105
|
+
};
|
|
106
|
+
/** 环境 */
|
|
107
|
+
|
|
108
|
+
var envRegExp = {
|
|
109
|
+
isWebview: /; wv/
|
|
110
|
+
};
|
|
111
|
+
var hash = {
|
|
112
|
+
os: Object.keys(osRegExp),
|
|
113
|
+
device: Object.keys(deviceRegExp),
|
|
114
|
+
engine: Object.keys(engineRegExp),
|
|
115
|
+
browser: Object.keys(browserRegExp)
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
var getMimeType = function getMimeType(value) {
|
|
119
|
+
try {
|
|
120
|
+
return !!mimeTypes.namedItem(value);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
var getValueOf = function getValueOf(values, reg) {
|
|
127
|
+
var ua = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : UA;
|
|
128
|
+
var i = values.length;
|
|
129
|
+
|
|
130
|
+
while (i--) {
|
|
131
|
+
var value = values[i];
|
|
132
|
+
if (reg[value].test(ua)) return value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return 'unknown';
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
var _windowVersion;
|
|
139
|
+
|
|
140
|
+
if (NAVIGATOR === null || NAVIGATOR === void 0 ? void 0 : NAVIGATOR.userAgentData) {
|
|
141
|
+
NAVIGATOR.userAgentData.getHighEntropyValues(['platformVersion']).then(function (ua) {
|
|
142
|
+
if (NAVIGATOR.userAgentData.platform === 'Windows') {
|
|
143
|
+
var majorPlatformVersion = parseInt(ua.platformVersion.split('.')[0]);
|
|
144
|
+
|
|
145
|
+
if (majorPlatformVersion >= 13) {
|
|
146
|
+
_windowVersion = '11';
|
|
147
|
+
} else {
|
|
148
|
+
_windowVersion = '10';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
var getLanguage = function getLanguage() {
|
|
155
|
+
var _a;
|
|
156
|
+
|
|
157
|
+
return (_a = NAVIGATOR.browserLanguage || NAVIGATOR.language) === null || _a === void 0 ? void 0 : _a.replace(/-\w+/g, function (word) {
|
|
158
|
+
return word.toUpperCase();
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
var isWechatMiniapp = function isWechatMiniapp() {
|
|
163
|
+
return typeof __wxjs_environment !== 'undefined' && __wxjs_environment === 'miniprogram';
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
var isWebview = function isWebview(ua) {
|
|
167
|
+
return envRegExp.isWebview.test(ua);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
var UaBrowser = /*#__PURE__*/function () {
|
|
171
|
+
function UaBrowser(ua) {
|
|
172
|
+
var _this = this;
|
|
173
|
+
|
|
174
|
+
_classCallCheck(this, UaBrowser);
|
|
175
|
+
|
|
176
|
+
this.ua = UA;
|
|
177
|
+
this.version = {
|
|
178
|
+
Safari: function Safari() {
|
|
179
|
+
return _this.ua.replace(/^.*Version\/([\d.]+).*$/, '$1');
|
|
180
|
+
},
|
|
181
|
+
Chrome: function Chrome() {
|
|
182
|
+
return _this.ua.replace(/^.*Chrome\/([\d.]+).*$/, '$1').replace(/^.*CriOS\/([\d.]+).*$/, '$1');
|
|
183
|
+
},
|
|
184
|
+
IE: function IE() {
|
|
185
|
+
return _this.ua.replace(/^.*MSIE ([\d.]+).*$/, '$1').replace(/^.*rv:([\d.]+).*$/, '$1');
|
|
186
|
+
},
|
|
187
|
+
Edge: function Edge() {
|
|
188
|
+
return _this.ua.replace(/^.*Edge\/([\d.]+).*$/, '$1').replace(/^.*Edg\/([\d.]+).*$/, '$1').replace(/^.*EdgA\/([\d.]+).*$/, '$1').replace(/^.*EdgiOS\/([\d.]+).*$/, '$1');
|
|
189
|
+
},
|
|
190
|
+
Firefox: function Firefox() {
|
|
191
|
+
return _this.ua.replace(/^.*Firefox\/([\d.]+).*$/, '$1').replace(/^.*FxiOS\/([\d.]+).*$/, '$1');
|
|
192
|
+
},
|
|
193
|
+
'Firefox Focus': function FirefoxFocus() {
|
|
194
|
+
return _this.ua.replace(/^.*Focus\/([\d.]+).*$/, '$1');
|
|
195
|
+
},
|
|
196
|
+
Chromium: function Chromium() {
|
|
197
|
+
return _this.ua.replace(/^.*Chromium\/([\d.]+).*$/, '$1');
|
|
198
|
+
},
|
|
199
|
+
Opera: function Opera() {
|
|
200
|
+
return _this.ua.replace(/^.*Opera\/([\d.]+).*$/, '$1').replace(/^.*OPR\/([\d.]+).*$/, '$1').replace(/^.*OPT\/([\d.]+).*$/, '$1');
|
|
201
|
+
},
|
|
202
|
+
Vivaldi: function Vivaldi() {
|
|
203
|
+
return _this.ua.replace(/^.*Vivaldi\/([\d.]+).*$/, '$1');
|
|
204
|
+
},
|
|
205
|
+
Yandex: function Yandex() {
|
|
206
|
+
return _this.ua.replace(/^.*YaBrowser\/([\d.]+).*$/, '$1');
|
|
207
|
+
},
|
|
208
|
+
Arora: function Arora() {
|
|
209
|
+
return _this.ua.replace(/^.*Arora\/([\d.]+).*$/, '$1');
|
|
210
|
+
},
|
|
211
|
+
Lunascape: function Lunascape() {
|
|
212
|
+
return _this.ua.replace(/^.*Lunascape[\s]([\d.]+).*$/, '$1');
|
|
213
|
+
},
|
|
214
|
+
QupZilla: function QupZilla() {
|
|
215
|
+
return _this.ua.replace(/^.*QupZilla[\s]([\d.]+).*$/, '$1');
|
|
216
|
+
},
|
|
217
|
+
'Coc Coc': function CocCoc() {
|
|
218
|
+
return _this.ua.replace(/^.*coc_coc_browser\/([\d.]+).*$/, '$1');
|
|
219
|
+
},
|
|
220
|
+
Kindle: function Kindle() {
|
|
221
|
+
return _this.ua.replace(/^.*Version\/([\d.]+).*$/, '$1');
|
|
222
|
+
},
|
|
223
|
+
Iceweasel: function Iceweasel() {
|
|
224
|
+
return _this.ua.replace(/^.*Iceweasel\/([\d.]+).*$/, '$1');
|
|
225
|
+
},
|
|
226
|
+
Konqueror: function Konqueror() {
|
|
227
|
+
return _this.ua.replace(/^.*Konqueror\/([\d.]+).*$/, '$1');
|
|
228
|
+
},
|
|
229
|
+
Iceape: function Iceape() {
|
|
230
|
+
return _this.ua.replace(/^.*Iceape\/([\d.]+).*$/, '$1');
|
|
231
|
+
},
|
|
232
|
+
SeaMonkey: function SeaMonkey() {
|
|
233
|
+
return _this.ua.replace(/^.*SeaMonkey\/([\d.]+).*$/, '$1');
|
|
234
|
+
},
|
|
235
|
+
Epiphany: function Epiphany() {
|
|
236
|
+
return _this.ua.replace(/^.*Epiphany\/([\d.]+).*$/, '$1');
|
|
237
|
+
},
|
|
238
|
+
Maxthon: function Maxthon() {
|
|
239
|
+
return _this.ua.replace(/^.*Maxthon\/([\d.]+).*$/, '$1');
|
|
240
|
+
},
|
|
241
|
+
QQBrowser: function QQBrowser() {
|
|
242
|
+
return _this.ua.replace(/^.*QQBrowser\/([\d.]+).*$/, '$1');
|
|
243
|
+
},
|
|
244
|
+
QQ: function QQ() {
|
|
245
|
+
return _this.ua.replace(/^.*QQ\/([\d.]+).*$/, '$1');
|
|
246
|
+
},
|
|
247
|
+
Baidu: function Baidu() {
|
|
248
|
+
return _this.ua.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/, '$1').replace(/^.*baiduboxapp\/([\d.]+).*$/, '$1');
|
|
249
|
+
},
|
|
250
|
+
UC: function UC() {
|
|
251
|
+
return _this.ua.replace(/^.*UC?Browser\/([\d.]+).*$/, '$1');
|
|
252
|
+
},
|
|
253
|
+
Sogou: function Sogou() {
|
|
254
|
+
return _this.ua.replace(/^.*SE ([\d.X]+).*$/, '$1').replace(/^.*SogouMobileBrowser\/([\d.]+).*$/, '$1');
|
|
255
|
+
},
|
|
256
|
+
TheWorld: function TheWorld() {
|
|
257
|
+
return _this.ua.replace(/^.*TheWorld ([\d.]+).*$/, '$1');
|
|
258
|
+
},
|
|
259
|
+
XiaoMi: function XiaoMi() {
|
|
260
|
+
return _this.ua.replace(/^.*MiuiBrowser\/([\d.]+).*$/, '$1');
|
|
261
|
+
},
|
|
262
|
+
Vivo: function Vivo() {
|
|
263
|
+
return _this.ua.replace(/^.*VivoBrowser\/([\d.]+).*$/, '$1');
|
|
264
|
+
},
|
|
265
|
+
OPPO: function OPPO() {
|
|
266
|
+
return _this.ua.replace(/^.*HeyTapBrowser\/([\d.]+).*$/, '$1');
|
|
267
|
+
},
|
|
268
|
+
Quark: function Quark() {
|
|
269
|
+
return _this.ua.replace(/^.*Quark\/([\d.]+).*$/, '$1');
|
|
270
|
+
},
|
|
271
|
+
Qiyu: function Qiyu() {
|
|
272
|
+
return _this.ua.replace(/^.*Qiyu\/([\d.]+).*$/, '$1');
|
|
273
|
+
},
|
|
274
|
+
Wechat: function Wechat() {
|
|
275
|
+
return _this.ua.replace(/^.*MicroMessenger\/([\d.]+).*$/, '$1');
|
|
276
|
+
},
|
|
277
|
+
WechatWork: function WechatWork() {
|
|
278
|
+
return _this.ua.replace(/^.*wxwork\/([\d.]+).*$/, '$1');
|
|
279
|
+
},
|
|
280
|
+
Taobao: function Taobao() {
|
|
281
|
+
return _this.ua.replace(/^.*AliApp\(TB\/([\d.]+).*$/, '$1');
|
|
282
|
+
},
|
|
283
|
+
Alipay: function Alipay() {
|
|
284
|
+
return _this.ua.replace(/^.*AliApp\(AP\/([\d.]+).*$/, '$1');
|
|
285
|
+
},
|
|
286
|
+
Weibo: function Weibo() {
|
|
287
|
+
return _this.ua.replace(/^.*weibo__([\d.]+).*$/, '$1');
|
|
288
|
+
},
|
|
289
|
+
Douban: function Douban() {
|
|
290
|
+
return _this.ua.replace(/^.*com.douban.frodo\/([\d.]+).*$/, '$1');
|
|
291
|
+
},
|
|
292
|
+
Suning: function Suning() {
|
|
293
|
+
return _this.ua.replace(/^.*SNEBUY-APP([\d.]+).*$/, '$1');
|
|
294
|
+
},
|
|
295
|
+
iQiYi: function iQiYi() {
|
|
296
|
+
return _this.ua.replace(/^.*IqiyiVersion\/([\d.]+).*$/, '$1');
|
|
297
|
+
},
|
|
298
|
+
DingTalk: function DingTalk() {
|
|
299
|
+
return _this.ua.replace(/^.*DingTalk\/([\d.]+).*$/, '$1');
|
|
300
|
+
},
|
|
301
|
+
Huawei: function Huawei() {
|
|
302
|
+
return _this.ua.replace(/^.*Version\/([\d.]+).*$/, '$1').replace(/^.*HuaweiBrowser\/([\d.]+).*$/, '$1');
|
|
303
|
+
},
|
|
304
|
+
Douyin: function Douyin() {
|
|
305
|
+
return _this.ua.replace(/^.*app_version\/([\d.]+).*$/, '$1');
|
|
306
|
+
},
|
|
307
|
+
'115Browser': function Browser() {
|
|
308
|
+
return _this.ua.replace(/^.*115Browser\/([\d.]+).*$/, '$1');
|
|
309
|
+
},
|
|
310
|
+
'360': function _() {
|
|
311
|
+
return _this.ua.replace(/^.*QihooBrowser\/([\d.]+).*$/, '$1');
|
|
312
|
+
},
|
|
313
|
+
'360SE': function SE() {
|
|
314
|
+
var vers = _this.getChromeVars();
|
|
315
|
+
|
|
316
|
+
var hash = {
|
|
317
|
+
'108': '14.0',
|
|
318
|
+
'86': '13.0',
|
|
319
|
+
'78': '12.0',
|
|
320
|
+
'69': '11.0',
|
|
321
|
+
'63': '10.0',
|
|
322
|
+
'55': '9.1',
|
|
323
|
+
'45': '8.1',
|
|
324
|
+
'42': '8.0',
|
|
325
|
+
'31': '7.0',
|
|
326
|
+
'21': '6.3'
|
|
327
|
+
};
|
|
328
|
+
return hash[vers] || '';
|
|
329
|
+
},
|
|
330
|
+
'360EE': function EE() {
|
|
331
|
+
var vers = _this.getChromeVars();
|
|
332
|
+
|
|
333
|
+
var hash = {
|
|
334
|
+
'86': '13.0',
|
|
335
|
+
'78': '12.0',
|
|
336
|
+
'69': '11.0',
|
|
337
|
+
'63': '9.5',
|
|
338
|
+
'55': '9.0',
|
|
339
|
+
'50': '8.7',
|
|
340
|
+
'30': '7.5'
|
|
341
|
+
};
|
|
342
|
+
return hash[vers] || '';
|
|
343
|
+
},
|
|
344
|
+
'2345Explorer': function Explorer() {
|
|
345
|
+
var vers = _this.getChromeVars();
|
|
346
|
+
|
|
347
|
+
var hash = {
|
|
348
|
+
'69': '10.0',
|
|
349
|
+
'55': '9.9'
|
|
350
|
+
};
|
|
351
|
+
return hash[vers] || _this.ua.replace(/^.*2345Explorer\/([\d.]+).*$/, '$1').replace(/^.*Mb2345Browser\/([\d.]+).*$/, '$1');
|
|
352
|
+
},
|
|
353
|
+
Liebao: function Liebao() {
|
|
354
|
+
var _version = '';
|
|
355
|
+
|
|
356
|
+
if (/LieBaoFast/.test(_this.ua)) {
|
|
357
|
+
_version = _this.ua.replace(/^.*LieBaoFast\/([\d.]+).*$/, '$1');
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
var vers = _this.getChromeVars();
|
|
361
|
+
|
|
362
|
+
var hash = {
|
|
363
|
+
'57': '6.5',
|
|
364
|
+
'49': '6.0',
|
|
365
|
+
'46': '5.9',
|
|
366
|
+
'42': '5.3',
|
|
367
|
+
'39': '5.2',
|
|
368
|
+
'34': '5.0',
|
|
369
|
+
'29': '4.5',
|
|
370
|
+
'21': '4.0'
|
|
371
|
+
};
|
|
372
|
+
return _version || hash[vers] || '';
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
this.osVersion = {
|
|
376
|
+
Android: function Android() {
|
|
377
|
+
return _this.ua.replace(/^.*Android ([\d.]+);.*$/, '$1');
|
|
378
|
+
},
|
|
379
|
+
iOS: function iOS() {
|
|
380
|
+
return _this.ua.replace(/^.*OS ([\d_]+) like.*$/, '$1').replace(/_/g, '.');
|
|
381
|
+
},
|
|
382
|
+
Debian: function Debian() {
|
|
383
|
+
return _this.ua.replace(/^.*Debian\/([\d.]+).*$/, '$1');
|
|
384
|
+
},
|
|
385
|
+
'Windows Phone': function WindowsPhone() {
|
|
386
|
+
return _this.ua.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/, '$2');
|
|
387
|
+
},
|
|
388
|
+
MacOS: function MacOS() {
|
|
389
|
+
return _this.ua.replace(/^.*Mac OS X -?([\d_]+).*$/, '$1').replace(/_/g, '.');
|
|
390
|
+
},
|
|
391
|
+
WebOS: function WebOS() {
|
|
392
|
+
return _this.ua.replace(/^.*hpwOS\/([\d.]+);.*$/, '$1');
|
|
393
|
+
},
|
|
394
|
+
HarmonyOS: function HarmonyOS() {
|
|
395
|
+
var vers = _this.ua.replace(/^Mozilla.*Android ([\d.]+)[;)].*$/, '$1');
|
|
396
|
+
|
|
397
|
+
var hash = {
|
|
398
|
+
'10': '2'
|
|
399
|
+
};
|
|
400
|
+
return hash[vers] || '';
|
|
401
|
+
},
|
|
402
|
+
Windows: function Windows() {
|
|
403
|
+
var vers = _this.ua.replace(/^Mozilla\/\d.0 \(Windows NT ([\d.]+);.*$/, '$1');
|
|
404
|
+
|
|
405
|
+
var hash = {
|
|
406
|
+
'10': '10',
|
|
407
|
+
'6.4': '10',
|
|
408
|
+
'6.3': '8.1',
|
|
409
|
+
'6.2': '8',
|
|
410
|
+
'6.1': '7',
|
|
411
|
+
'6.0': 'Vista',
|
|
412
|
+
'5.2': 'XP',
|
|
413
|
+
'5.1': 'XP',
|
|
414
|
+
'5.0': '2000'
|
|
415
|
+
};
|
|
416
|
+
return hash[vers] || parseInt(vers).toString();
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
this.getChromeVars = function () {
|
|
421
|
+
return _this.ua.replace(/^.*Chrome\/([\d]+).*$/, '$1');
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
this.setUA(ua);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
_createClass(UaBrowser, [{
|
|
428
|
+
key: "getOs",
|
|
429
|
+
value: function getOs() {
|
|
430
|
+
return getValueOf(hash.os, osRegExp, this.ua);
|
|
431
|
+
}
|
|
432
|
+
}, {
|
|
433
|
+
key: "getEngine",
|
|
434
|
+
value: function getEngine() {
|
|
435
|
+
return getValueOf(hash.engine, engineRegExp, this.ua);
|
|
436
|
+
}
|
|
437
|
+
}, {
|
|
438
|
+
key: "getBrowser",
|
|
439
|
+
value: function getBrowser() {
|
|
440
|
+
return getValueOf(hash.browser, browserRegExp, this.ua);
|
|
441
|
+
}
|
|
442
|
+
}, {
|
|
443
|
+
key: "getDevice",
|
|
444
|
+
value: function getDevice() {
|
|
445
|
+
if (platfrom === 'MacIntel' && NAVIGATOR.maxTouchPoints > 1) {
|
|
446
|
+
return 'Tablet';
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
var device = getValueOf(hash.device, deviceRegExp, this.ua);
|
|
450
|
+
return device === 'unknown' ? 'PC' : device;
|
|
451
|
+
}
|
|
452
|
+
}, {
|
|
453
|
+
key: "setUA",
|
|
454
|
+
value: function setUA(ua) {
|
|
455
|
+
if (typeof ua !== 'string') {
|
|
456
|
+
console.warn('Parameter must be of type string.');
|
|
457
|
+
this.ua = UA;
|
|
458
|
+
} else {
|
|
459
|
+
this.ua = ua;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}, {
|
|
463
|
+
key: "getEnv",
|
|
464
|
+
value: function getEnv(ua) {
|
|
465
|
+
var _a, _b;
|
|
466
|
+
|
|
467
|
+
this.setUA(ua);
|
|
468
|
+
var env = {
|
|
469
|
+
version: 'unknown',
|
|
470
|
+
osVersion: 'unknown',
|
|
471
|
+
engine: this.getEngine(),
|
|
472
|
+
browser: this.getBrowser(),
|
|
473
|
+
os: this.getOs(),
|
|
474
|
+
device: this.getDevice(),
|
|
475
|
+
isWebview: isWebview(this.ua),
|
|
476
|
+
language: (_a = getLanguage()) !== null && _a !== void 0 ? _a : 'unknown',
|
|
477
|
+
platfrom: platfrom !== null && platfrom !== void 0 ? platfrom : 'unknown'
|
|
478
|
+
};
|
|
479
|
+
var browser = env.browser;
|
|
480
|
+
var is360 = false;
|
|
481
|
+
|
|
482
|
+
if (typeof chrome !== 'undefined') {
|
|
483
|
+
var vers = this.getChromeVars();
|
|
484
|
+
|
|
485
|
+
if (chrome.adblock2345 || chrome.common2345) {
|
|
486
|
+
env.browser = '2345Explorer';
|
|
487
|
+
} else if (getMimeType('application/360softmgrplugin') || getMimeType('application/mozilla-npqihooquicklogin') || vers > '36' && typeof showModalDialog !== 'undefined') {
|
|
488
|
+
is360 = true;
|
|
489
|
+
} else if (vers > '45') {
|
|
490
|
+
is360 = getMimeType('application/vnd.chromium.remoting-viewer');
|
|
491
|
+
|
|
492
|
+
if (!is360 && vers >= '69') {
|
|
493
|
+
is360 = getMimeType('application/hwepass2001.installepass2001') || getMimeType('application/asx');
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (env.device === 'Mobile' && /iPad/.test(this.ua)) {
|
|
499
|
+
env.device = 'Tablet';
|
|
500
|
+
} else if (is360) {
|
|
501
|
+
if (getMimeType('application/gameplugin') || !((_b = NAVIGATOR === null || NAVIGATOR === void 0 ? void 0 : NAVIGATOR.connection) === null || _b === void 0 ? void 0 : _b.saveData)) {
|
|
502
|
+
browser = '360SE';
|
|
503
|
+
} else {
|
|
504
|
+
browser = '360EE';
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (hash.browser.indexOf(browser) >= hash.browser.indexOf(env.browser)) {
|
|
509
|
+
env.browser = browser;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (env.browser === 'Baidu' && browserRegExp.Opera.test(this.ua)) {
|
|
513
|
+
env.browser = 'Opera';
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (env.os in this.osVersion) {
|
|
517
|
+
env.osVersion = this.osVersion[env.os]();
|
|
518
|
+
|
|
519
|
+
if (env.osVersion === this.ua) {
|
|
520
|
+
env.osVersion = 'unknown';
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (env.os === 'Windows' && _windowVersion) {
|
|
525
|
+
env.osVersion = _windowVersion;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (env.browser in this.version) {
|
|
529
|
+
env.version = this.version[env.browser]();
|
|
530
|
+
|
|
531
|
+
if (env.version === this.ua) {
|
|
532
|
+
env.version = 'unknown';
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (env.browser === 'Chrome' && this.ua.match(/\S+Browser/)) {
|
|
537
|
+
env.browser = this.ua.match(/\S+Browser/)[0];
|
|
538
|
+
env.version = this.ua.replace(/^.*Browser\/([\d.]+).*$/, '$1');
|
|
539
|
+
} else if (env.browser === 'Firefox' && (typeof clientInformation !== 'undefined' || !(typeof u2f !== 'undefined'))) {
|
|
540
|
+
env.browser = "".concat(env.browser, " Nightly");
|
|
541
|
+
} else if (env.browser === 'Wechat' && isWechatMiniapp()) {
|
|
542
|
+
env.browser = 'Wechat Miniapp';
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
if (env.browser === 'Edge') {
|
|
546
|
+
env.engine = parseInt(env.version) > 75 ? 'Blink' : 'EdgeHTML';
|
|
547
|
+
} else if (browserRegExp.Chrome.test(this.ua) && env.engine === 'WebKit' && parseInt(this.version.Chrome()) > 27 || env.browser === 'Opera' && parseInt(env.version) > 12 || env.browser === 'Yandex') {
|
|
548
|
+
env.engine = 'Blink';
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
return env;
|
|
552
|
+
}
|
|
553
|
+
}]);
|
|
554
|
+
|
|
555
|
+
return UaBrowser;
|
|
556
|
+
}();
|
|
557
|
+
|
|
558
|
+
var instance = new UaBrowser();
|
|
559
|
+
|
|
560
|
+
function Wrap(ua) {
|
|
561
|
+
return instance.getEnv(ua);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
Wrap.isWebview = isWebview;
|
|
565
|
+
Wrap.isWechatMiniapp = isWechatMiniapp;
|
|
566
|
+
Wrap.getLanguage = getLanguage;
|
|
567
|
+
Wrap.VERSION = version;
|
|
568
|
+
module.exports = Wrap;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type HashOptions = Record<string, string>
|
|
2
2
|
|
|
3
|
-
export type OsVersionType =
|
|
3
|
+
export type OsVersionType =
|
|
4
4
|
| 'Android'
|
|
5
5
|
| 'iOS'
|
|
6
6
|
| 'Debian'
|
|
@@ -60,6 +60,7 @@ export type EnvOption = EnvPart & EnvWebview & {
|
|
|
60
60
|
| '2345Explorer'
|
|
61
61
|
| '115Browser'
|
|
62
62
|
| 'TheWorld'
|
|
63
|
+
| 'OPPO'
|
|
63
64
|
| 'XiaoMi'
|
|
64
65
|
| 'Quark'
|
|
65
66
|
| 'Qiyu'
|
|
@@ -76,6 +77,7 @@ export type EnvOption = EnvPart & EnvWebview & {
|
|
|
76
77
|
| 'Vivo'
|
|
77
78
|
| 'Firefox Nightly'
|
|
78
79
|
| 'Wechat Miniapp'
|
|
80
|
+
| 'Douyin'
|
|
79
81
|
| 'unknown'
|
|
80
82
|
os:
|
|
81
83
|
| 'Windows'
|
|
@@ -130,10 +132,9 @@ declare global {
|
|
|
130
132
|
// Navigator
|
|
131
133
|
interface Navigator {
|
|
132
134
|
browserLanguage: string
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
135
|
+
userAgentData: Record<string, any>
|
|
136
|
+
connection: Record<string, any>
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
export {}
|
|
140
|
+
export {}
|