ua-browser 0.1.7 → 0.1.9

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 CHANGED
@@ -1,23 +1,20 @@
1
1
  'use strict';
2
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
-
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
5
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
6
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
7
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
8
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
9
  var version = "0.1.7";
10
10
  var NAVIGATOR = {};
11
-
12
11
  if (typeof navigator !== 'undefined') {
13
12
  NAVIGATOR = navigator;
14
13
  }
15
-
16
14
  var UA = NAVIGATOR.userAgent || '';
17
15
  var mimeTypes = NAVIGATOR.mimeTypes;
18
16
  var platfrom = NAVIGATOR.platform;
19
17
  /** 内核 */
20
-
21
18
  var engineRegExp = {
22
19
  Trident: /(Trident|NET CLR)/,
23
20
  Presto: /Presto/,
@@ -26,7 +23,6 @@ var engineRegExp = {
26
23
  KHTML: /KHTML\//
27
24
  };
28
25
  /** 浏览器 */
29
-
30
26
  var browserRegExp = {
31
27
  Safari: /Safari/,
32
28
  Chrome: /(Chrome|CriOS)/,
@@ -79,7 +75,6 @@ var browserRegExp = {
79
75
  Douyin: /aweme/
80
76
  };
81
77
  /** 系统或平台 */
82
-
83
78
  var osRegExp = {
84
79
  Windows: /Windows/,
85
80
  Linux: /(Linux|X11)/,
@@ -98,13 +93,11 @@ var osRegExp = {
98
93
  WebOS: /hpwOS/
99
94
  };
100
95
  /** 设备 */
101
-
102
96
  var deviceRegExp = {
103
97
  Mobile: /(Mobi|iPh|480)/,
104
98
  Tablet: /(Tablet|Pad|Nexus 7)/
105
99
  };
106
100
  /** 环境 */
107
-
108
101
  var envRegExp = {
109
102
  isWebview: /; wv/
110
103
  };
@@ -114,7 +107,6 @@ var hash = {
114
107
  engine: Object.keys(engineRegExp),
115
108
  browser: Object.keys(browserRegExp)
116
109
  };
117
-
118
110
  var getMimeType = function getMimeType(value) {
119
111
  try {
120
112
  return !!mimeTypes.namedItem(value);
@@ -122,26 +114,20 @@ var getMimeType = function getMimeType(value) {
122
114
  return false;
123
115
  }
124
116
  };
125
-
126
117
  var getValueOf = function getValueOf(values, reg) {
127
118
  var ua = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : UA;
128
119
  var i = values.length;
129
-
130
120
  while (i--) {
131
121
  var value = values[i];
132
122
  if (reg[value].test(ua)) return value;
133
123
  }
134
-
135
124
  return 'unknown';
136
125
  };
137
-
138
126
  var _windowVersion;
139
-
140
127
  if (NAVIGATOR === null || NAVIGATOR === void 0 ? void 0 : NAVIGATOR.userAgentData) {
141
128
  NAVIGATOR.userAgentData.getHighEntropyValues(['platformVersion']).then(function (ua) {
142
129
  if (NAVIGATOR.userAgentData.platform === 'Windows') {
143
130
  var majorPlatformVersion = parseInt(ua.platformVersion.split('.')[0]);
144
-
145
131
  if (majorPlatformVersion >= 13) {
146
132
  _windowVersion = '11';
147
133
  } else {
@@ -150,29 +136,22 @@ if (NAVIGATOR === null || NAVIGATOR === void 0 ? void 0 : NAVIGATOR.userAgentDat
150
136
  }
151
137
  });
152
138
  }
153
-
154
139
  var getLanguage = function getLanguage() {
155
140
  var _a;
156
-
157
141
  return (_a = NAVIGATOR.browserLanguage || NAVIGATOR.language) === null || _a === void 0 ? void 0 : _a.replace(/-\w+/g, function (word) {
158
142
  return word.toUpperCase();
159
143
  });
160
144
  };
161
-
162
145
  var isWechatMiniapp = function isWechatMiniapp() {
163
146
  return typeof __wxjs_environment !== 'undefined' && __wxjs_environment === 'miniprogram';
164
147
  };
165
-
166
148
  var isWebview = function isWebview(ua) {
167
149
  return envRegExp.isWebview.test(ua);
168
150
  };
169
-
170
151
  var UaBrowser = /*#__PURE__*/function () {
171
152
  function UaBrowser(ua) {
172
153
  var _this = this;
173
-
174
154
  _classCallCheck(this, UaBrowser);
175
-
176
155
  this.ua = UA;
177
156
  this.version = {
178
157
  Safari: function Safari() {
@@ -190,7 +169,7 @@ var UaBrowser = /*#__PURE__*/function () {
190
169
  Firefox: function Firefox() {
191
170
  return _this.ua.replace(/^.*Firefox\/([\d.]+).*$/, '$1').replace(/^.*FxiOS\/([\d.]+).*$/, '$1');
192
171
  },
193
- 'Firefox Focus': function FirefoxFocus() {
172
+ 'Firefox Focus': function Firefox_Focus() {
194
173
  return _this.ua.replace(/^.*Focus\/([\d.]+).*$/, '$1');
195
174
  },
196
175
  Chromium: function Chromium() {
@@ -214,7 +193,7 @@ var UaBrowser = /*#__PURE__*/function () {
214
193
  QupZilla: function QupZilla() {
215
194
  return _this.ua.replace(/^.*QupZilla[\s]([\d.]+).*$/, '$1');
216
195
  },
217
- 'Coc Coc': function CocCoc() {
196
+ 'Coc Coc': function Coc_Coc() {
218
197
  return _this.ua.replace(/^.*coc_coc_browser\/([\d.]+).*$/, '$1');
219
198
  },
220
199
  Kindle: function Kindle() {
@@ -312,7 +291,6 @@ var UaBrowser = /*#__PURE__*/function () {
312
291
  },
313
292
  '360SE': function SE() {
314
293
  var vers = _this.getChromeVars();
315
-
316
294
  var hash = {
317
295
  '108': '14.0',
318
296
  '86': '13.0',
@@ -329,7 +307,6 @@ var UaBrowser = /*#__PURE__*/function () {
329
307
  },
330
308
  '360EE': function EE() {
331
309
  var vers = _this.getChromeVars();
332
-
333
310
  var hash = {
334
311
  '86': '13.0',
335
312
  '78': '12.0',
@@ -343,7 +320,6 @@ var UaBrowser = /*#__PURE__*/function () {
343
320
  },
344
321
  '2345Explorer': function Explorer() {
345
322
  var vers = _this.getChromeVars();
346
-
347
323
  var hash = {
348
324
  '69': '10.0',
349
325
  '55': '9.9'
@@ -352,13 +328,10 @@ var UaBrowser = /*#__PURE__*/function () {
352
328
  },
353
329
  Liebao: function Liebao() {
354
330
  var _version = '';
355
-
356
331
  if (/LieBaoFast/.test(_this.ua)) {
357
332
  _version = _this.ua.replace(/^.*LieBaoFast\/([\d.]+).*$/, '$1');
358
333
  }
359
-
360
334
  var vers = _this.getChromeVars();
361
-
362
335
  var hash = {
363
336
  '57': '6.5',
364
337
  '49': '6.0',
@@ -382,7 +355,7 @@ var UaBrowser = /*#__PURE__*/function () {
382
355
  Debian: function Debian() {
383
356
  return _this.ua.replace(/^.*Debian\/([\d.]+).*$/, '$1');
384
357
  },
385
- 'Windows Phone': function WindowsPhone() {
358
+ 'Windows Phone': function Windows_Phone() {
386
359
  return _this.ua.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/, '$2');
387
360
  },
388
361
  MacOS: function MacOS() {
@@ -393,7 +366,6 @@ var UaBrowser = /*#__PURE__*/function () {
393
366
  },
394
367
  HarmonyOS: function HarmonyOS() {
395
368
  var vers = _this.ua.replace(/^Mozilla.*Android ([\d.]+)[;)].*$/, '$1');
396
-
397
369
  var hash = {
398
370
  '10': '2'
399
371
  };
@@ -401,7 +373,6 @@ var UaBrowser = /*#__PURE__*/function () {
401
373
  },
402
374
  Windows: function Windows() {
403
375
  var vers = _this.ua.replace(/^Mozilla\/\d.0 \(Windows NT ([\d.]+);.*$/, '$1');
404
-
405
376
  var hash = {
406
377
  '10': '10',
407
378
  '6.4': '10',
@@ -416,15 +387,12 @@ var UaBrowser = /*#__PURE__*/function () {
416
387
  return hash[vers] || parseInt(vers).toString();
417
388
  }
418
389
  };
419
-
420
390
  this.getChromeVars = function () {
421
391
  return _this.ua.replace(/^.*Chrome\/([\d]+).*$/, '$1');
422
392
  };
423
-
424
393
  this.setUA(ua);
425
394
  }
426
-
427
- _createClass(UaBrowser, [{
395
+ return _createClass(UaBrowser, [{
428
396
  key: "getOs",
429
397
  value: function getOs() {
430
398
  return getValueOf(hash.os, osRegExp, this.ua);
@@ -445,7 +413,6 @@ var UaBrowser = /*#__PURE__*/function () {
445
413
  if (platfrom === 'MacIntel' && NAVIGATOR.maxTouchPoints > 1) {
446
414
  return 'Tablet';
447
415
  }
448
-
449
416
  var device = getValueOf(hash.device, deviceRegExp, this.ua);
450
417
  return device === 'unknown' ? 'PC' : device;
451
418
  }
@@ -458,7 +425,6 @@ var UaBrowser = /*#__PURE__*/function () {
458
425
  if (typeof ua !== 'undefined') {
459
426
  console.warn('`ua` must be of type string.');
460
427
  }
461
-
462
428
  this.ua = UA;
463
429
  }
464
430
  }
@@ -466,7 +432,6 @@ var UaBrowser = /*#__PURE__*/function () {
466
432
  key: "getEnv",
467
433
  value: function getEnv(ua) {
468
434
  var _a, _b;
469
-
470
435
  this.setUA(ua);
471
436
  var env = {
472
437
  version: 'unknown',
@@ -481,23 +446,19 @@ var UaBrowser = /*#__PURE__*/function () {
481
446
  };
482
447
  var browser = env.browser;
483
448
  var is360 = false;
484
-
485
449
  if (typeof chrome !== 'undefined') {
486
450
  var vers = this.getChromeVars();
487
-
488
451
  if (chrome.adblock2345 || chrome.common2345) {
489
452
  env.browser = '2345Explorer';
490
453
  } else if (getMimeType('application/360softmgrplugin') || getMimeType('application/mozilla-npqihooquicklogin') || vers > '36' && typeof showModalDialog !== 'undefined') {
491
454
  is360 = true;
492
455
  } else if (vers > '45') {
493
456
  is360 = getMimeType('application/vnd.chromium.remoting-viewer');
494
-
495
457
  if (!is360 && vers >= '69') {
496
458
  is360 = getMimeType('application/hwepass2001.installepass2001') || getMimeType('application/asx');
497
459
  }
498
460
  }
499
461
  }
500
-
501
462
  if (env.device === 'Mobile' && /iPad/.test(this.ua)) {
502
463
  env.device = 'Tablet';
503
464
  } else if (is360) {
@@ -507,35 +468,27 @@ var UaBrowser = /*#__PURE__*/function () {
507
468
  browser = '360EE';
508
469
  }
509
470
  }
510
-
511
471
  if (hash.browser.indexOf(browser) >= hash.browser.indexOf(env.browser)) {
512
472
  env.browser = browser;
513
473
  }
514
-
515
474
  if (env.browser === 'Baidu' && browserRegExp.Opera.test(this.ua)) {
516
475
  env.browser = 'Opera';
517
476
  }
518
-
519
477
  if (env.os in this.osVersion) {
520
478
  env.osVersion = this.osVersion[env.os]();
521
-
522
479
  if (env.osVersion === this.ua) {
523
480
  env.osVersion = 'unknown';
524
481
  }
525
482
  }
526
-
527
483
  if (env.os === 'Windows' && _windowVersion) {
528
484
  env.osVersion = _windowVersion;
529
485
  }
530
-
531
486
  if (env.browser in this.version) {
532
487
  env.version = this.version[env.browser]();
533
-
534
488
  if (env.version === this.ua) {
535
489
  env.version = 'unknown';
536
490
  }
537
491
  }
538
-
539
492
  if (env.browser === 'Chrome' && this.ua.match(/\S+Browser/)) {
540
493
  env.browser = this.ua.match(/\S+Browser/)[0];
541
494
  env.version = this.ua.replace(/^.*Browser\/([\d.]+).*$/, '$1');
@@ -544,26 +497,19 @@ var UaBrowser = /*#__PURE__*/function () {
544
497
  } else if (env.browser === 'Wechat' && isWechatMiniapp()) {
545
498
  env.browser = 'Wechat Miniapp';
546
499
  }
547
-
548
500
  if (env.browser === 'Edge') {
549
501
  env.engine = parseInt(env.version) > 75 ? 'Blink' : 'EdgeHTML';
550
502
  } 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') {
551
503
  env.engine = 'Blink';
552
504
  }
553
-
554
505
  return env;
555
506
  }
556
507
  }]);
557
-
558
- return UaBrowser;
559
508
  }();
560
-
561
509
  var instance = new UaBrowser();
562
-
563
510
  function Wrap(ua) {
564
511
  return instance.getEnv(ua);
565
512
  }
566
-
567
513
  Wrap.isWebview = isWebview;
568
514
  Wrap.isWechatMiniapp = isWechatMiniapp;
569
515
  Wrap.getLanguage = getLanguage;
package/dist/index.d.ts CHANGED
@@ -1,140 +1,140 @@
1
- export type HashOptions = Record<string, string>
2
-
3
- export type OsVersionType =
4
- | 'Android'
5
- | 'iOS'
6
- | 'Debian'
7
- | 'Windows Phone'
8
- | 'MacOS'
9
- | 'WebOS'
10
- | 'HarmonyOS'
11
- | 'Windows'
12
-
13
- export type EnvWebview = {
14
- isWebview: boolean
15
- }
16
-
17
- export type EnvPart = Record<'version' | 'osVersion' | 'platfrom' | 'languge', string>
18
-
19
- export type EnvOption = EnvPart & EnvWebview & {
20
- engine:
21
- | 'Trident'
22
- | 'Presto'
23
- | 'WebKit'
24
- | 'Gecko'
25
- | 'KHTML'
26
- | 'Blink'
27
- | 'EdgeHTML'
28
- | 'unknown'
29
- browser:
30
- | 'Safari'
31
- | 'Chrome'
32
- | 'IE'
33
- | 'Edge'
34
- | 'Firefox'
35
- | 'Firefox Focus'
36
- | 'Chromium'
37
- | 'Opera'
38
- | 'Vivaldi'
39
- | 'Yandex'
40
- | 'Arora'
41
- | 'Lunascape'
42
- | 'QupZilla'
43
- | 'Coc Coc'
44
- | 'Kindle'
45
- | 'Iceweasel'
46
- | 'Konqueror'
47
- | 'Iceape'
48
- | 'SeaMonkey'
49
- | 'Epiphany'
50
- | '360'
51
- | '360EE'
52
- | '360SE'
53
- | 'UC'
54
- | 'QQBrowser'
55
- | 'QQ'
56
- | 'Baidu'
57
- | 'Maxthon'
58
- | 'Sogou'
59
- | 'Liebao'
60
- | '2345Explorer'
61
- | '115Browser'
62
- | 'TheWorld'
63
- | 'OPPO'
64
- | 'XiaoMi'
65
- | 'Quark'
66
- | 'Qiyu'
67
- | 'Wechat'
68
- | 'WechatWork'
69
- | 'Taobao'
70
- | 'Alipay'
71
- | 'Weibo'
72
- | 'Douban'
73
- | 'Suning'
74
- | 'iQiYi'
75
- | 'DingTalk'
76
- | 'Huawei'
77
- | 'Vivo'
78
- | 'Firefox Nightly'
79
- | 'Wechat Miniapp'
80
- | 'Douyin'
81
- | 'unknown'
82
- os:
83
- | 'Windows'
84
- | 'Linux'
85
- | 'MacOS'
86
- | 'Android'
87
- | 'HarmonyOS'
88
- | 'Ubuntu'
89
- | 'FreeBSD'
90
- | 'Debian'
91
- | 'Windows Phone'
92
- | 'BlackBerry'
93
- | 'MeeGo'
94
- | 'Symbian'
95
- | 'iOS'
96
- | 'Chrome OS'
97
- | 'WebOS'
98
- | 'unknown'
99
- device:
100
- | 'Mobile'
101
- | 'Tablet'
102
- | 'Pc'
103
- }
104
-
105
- declare function uaBrowser(ua?: string): EnvOption
106
-
107
- declare namespace uaBrowser {
108
- /** 检查 `webview` 浏览环境,仅支持 `android` */
109
- function isWebview(ua: string): boolean
110
- /** 检查微信小程序 */
111
- function isWechatMiniapp(): boolean
112
- /** 浏览器语言 */
113
- function getLanguage(): string
114
- /** 当前版本 */
115
- const VERSION: string
116
- }
117
-
118
- export default uaBrowser
119
-
120
- declare global {
121
- const __wxjs_environment: string
122
-
123
- const chrome: {
124
- adblock2345: any
125
- common2345: any
126
- }
127
-
128
- const showModalDialog: any
129
-
130
- const u2f: any
131
-
132
- // Navigator
133
- interface Navigator {
134
- browserLanguage: string
135
- userAgentData: Record<string, any>
136
- connection: Record<string, any>
137
- }
138
- }
139
-
140
- export {}
1
+ export type HashOptions = Record<string, string>
2
+
3
+ export type OsVersionType =
4
+ | 'Android'
5
+ | 'iOS'
6
+ | 'Debian'
7
+ | 'Windows Phone'
8
+ | 'MacOS'
9
+ | 'WebOS'
10
+ | 'HarmonyOS'
11
+ | 'Windows'
12
+
13
+ export type EnvWebview = {
14
+ isWebview: boolean
15
+ }
16
+
17
+ export type EnvPart = Record<'version' | 'osVersion' | 'platfrom' | 'languge', string>
18
+
19
+ export type EnvOption = EnvPart & EnvWebview & {
20
+ engine:
21
+ | 'Trident'
22
+ | 'Presto'
23
+ | 'WebKit'
24
+ | 'Gecko'
25
+ | 'KHTML'
26
+ | 'Blink'
27
+ | 'EdgeHTML'
28
+ | 'unknown'
29
+ browser:
30
+ | 'Safari'
31
+ | 'Chrome'
32
+ | 'IE'
33
+ | 'Edge'
34
+ | 'Firefox'
35
+ | 'Firefox Focus'
36
+ | 'Chromium'
37
+ | 'Opera'
38
+ | 'Vivaldi'
39
+ | 'Yandex'
40
+ | 'Arora'
41
+ | 'Lunascape'
42
+ | 'QupZilla'
43
+ | 'Coc Coc'
44
+ | 'Kindle'
45
+ | 'Iceweasel'
46
+ | 'Konqueror'
47
+ | 'Iceape'
48
+ | 'SeaMonkey'
49
+ | 'Epiphany'
50
+ | '360'
51
+ | '360EE'
52
+ | '360SE'
53
+ | 'UC'
54
+ | 'QQBrowser'
55
+ | 'QQ'
56
+ | 'Baidu'
57
+ | 'Maxthon'
58
+ | 'Sogou'
59
+ | 'Liebao'
60
+ | '2345Explorer'
61
+ | '115Browser'
62
+ | 'TheWorld'
63
+ | 'OPPO'
64
+ | 'XiaoMi'
65
+ | 'Quark'
66
+ | 'Qiyu'
67
+ | 'Wechat'
68
+ | 'WechatWork'
69
+ | 'Taobao'
70
+ | 'Alipay'
71
+ | 'Weibo'
72
+ | 'Douban'
73
+ | 'Suning'
74
+ | 'iQiYi'
75
+ | 'DingTalk'
76
+ | 'Huawei'
77
+ | 'Vivo'
78
+ | 'Firefox Nightly'
79
+ | 'Wechat Miniapp'
80
+ | 'Douyin'
81
+ | 'unknown'
82
+ os:
83
+ | 'Windows'
84
+ | 'Linux'
85
+ | 'MacOS'
86
+ | 'Android'
87
+ | 'HarmonyOS'
88
+ | 'Ubuntu'
89
+ | 'FreeBSD'
90
+ | 'Debian'
91
+ | 'Windows Phone'
92
+ | 'BlackBerry'
93
+ | 'MeeGo'
94
+ | 'Symbian'
95
+ | 'iOS'
96
+ | 'Chrome OS'
97
+ | 'WebOS'
98
+ | 'unknown'
99
+ device:
100
+ | 'Mobile'
101
+ | 'Tablet'
102
+ | 'Pc'
103
+ }
104
+
105
+ declare function uaBrowser(ua?: string): EnvOption
106
+
107
+ declare namespace uaBrowser {
108
+ /** 检查 `webview` 浏览环境,仅支持 `android` */
109
+ function isWebview(ua: string): boolean
110
+ /** 检查微信小程序 */
111
+ function isWechatMiniapp(): boolean
112
+ /** 浏览器语言 */
113
+ function getLanguage(): string
114
+ /** 当前版本 */
115
+ const VERSION: string
116
+ }
117
+
118
+ export default uaBrowser
119
+
120
+ declare global {
121
+ const __wxjs_environment: string
122
+
123
+ const chrome: {
124
+ adblock2345: any
125
+ common2345: any
126
+ }
127
+
128
+ const showModalDialog: any
129
+
130
+ const u2f: any
131
+
132
+ // Navigator
133
+ interface Navigator {
134
+ browserLanguage: string
135
+ userAgentData: Record<string, any>
136
+ connection: Record<string, any>
137
+ }
138
+ }
139
+
140
+ export {}