ua-parser-js 0.7.20 → 0.7.28

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.

Potentially problematic release.


This version of ua-parser-js might be problematic. Click here for more details.

package/readme.md CHANGED
@@ -1,18 +1,26 @@
1
- # UAParser.js
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/faisalman/ua-parser-js/gh-pages/images/logo.png" width="256" height="256">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://travis-ci.org/faisalman/ua-parser-js"><img src="https://travis-ci.org/faisalman/ua-parser-js.svg?branch=master"></a>
7
+ <a href="https://www.npmjs.com/package/ua-parser-js"><img src="https://img.shields.io/npm/v/ua-parser-js.svg"></a>
8
+ <a href="https://www.npmjs.com/package/ua-parser-js"><img src="https://img.shields.io/npm/dw/ua-parser-js.svg"></a>
9
+ <a href="https://www.jsdelivr.com/package/npm/ua-parser-js"><img src="https://data.jsdelivr.com/v1/package/npm/ua-parser-js/badge"></a>
10
+ <a href="https://cdnjs.com/libraries/UAParser.js"><img src="https://img.shields.io/cdnjs/v/UAParser.js.svg"></a>
11
+ </p>
2
12
 
3
- <img align="right" src="https://raw.githubusercontent.com/faisalman/ua-parser-js/gh-pages/images/logo.png"> A JavaScript-based User-Agent string parser. Can be used either in browser (client-side) or in node.js (server-side) environment. Also available as jQuery/Zepto plugin, Bower/Meteor package, & RequireJS/AMD module. This library aims to identify detailed type of web browser, layout engine, operating system, cpu architecture, and device type/model, entirely from user-agent string with a relatively small footprint (~17KB when minified / ~6KB gzipped). Written in vanilla JavaScript, which means it doesn't require any other library and can be used independently. However, it's not recommended to use this library as browser detection since the result may not be more accurate than using feature detection.
13
+ # UAParser.js
4
14
 
5
- [![Build Status](https://travis-ci.org/faisalman/ua-parser-js.svg?branch=master)](https://travis-ci.org/faisalman/ua-parser-js)
6
- [![NPM downloads](https://img.shields.io/npm/dw/ua-parser-js.svg)](https://www.npmjs.com/package/ua-parser-js)
7
- [![NPM](https://img.shields.io/npm/v/ua-parser-js.svg)](https://www.npmjs.com/package/ua-parser-js)
8
- [![Bower](https://img.shields.io/bower/v/ua-parser-js.svg)](https://bower.io/)
9
- [![CDNJS](https://img.shields.io/cdnjs/v/UAParser.js.svg)](https://cdnjs.com/libraries/UAParser.js)
15
+ JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data with relatively small footprint (~17KB minified, ~6KB gzipped) that can be used either in browser (client-side) or node.js (server-side).
10
16
 
11
17
  * Author : Faisal Salman <<f@faisalman.com>>
12
18
  * Demo : http://faisalman.github.io/ua-parser-js
13
19
  * Source : https://github.com/faisalman/ua-parser-js
14
20
 
15
- # Constructor
21
+ # Documentation
22
+
23
+ ## Constructor
16
24
 
17
25
  * `new UAParser([uastring][,extensions])`
18
26
  * returns new instance
@@ -20,42 +28,44 @@
20
28
  * `UAParser([uastring][,extensions])`
21
29
  * returns result object `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
22
30
 
23
- # Methods
31
+ ## Methods
24
32
 
25
33
  * `getBrowser()`
26
34
  * returns `{ name: '', version: '' }`
27
35
 
28
36
  ```sh
29
37
  # Possible 'browser.name':
30
- 2345Explorer, Amaya, Android Browser, Arora, Avant, BIDUBrowser, Baidu,
31
- Basilisk, Blazer, Bolt, Bowser, Camino, Chimera, Chrome Headless,
32
- Chrome WebView, Chrome, Chromium, Comodo Dragon, Dillo, Dolphin, Doris, Edge,
33
- Epiphany, Facebook, Falkon, Fennec, Firebird, Firefox, Flock, GSA, GoBrowser,
34
- ICE Browser, IE, IEMobile, IceApe, IceCat, IceDragon, Iceape, Iceweasel,
35
- Iridium, Iron, Jasmine, K-Meleon, Kindle, Konqueror, LBBROWSER Line, Links,
36
- Lunascape, Lynx, MIUI Browser, Maemo Browser, Maemo, Maxthon, MetaSr Midori,
37
- Minimo, Mobile Safari, Mosaic, Mozilla, NetFront, NetSurf, Netfront, Netscape,
38
- NokiaBrowser, Oculus Browser, OmniWeb, Opera Coast, Opera Mini, Opera Mobi,
39
- Opera Tablet, Opera, PaleMoon, PhantomJS, Phoenix, Polaris, Puffin, QQ,
40
- QQBrowser, QQBrowserLite, Quark, QupZilla, RockMelt, Safari, Samsung Browser,
41
- SeaMonkey, Silk, Skyfire, Sleipnir, Slim, SlimBrowser, Swiftfox, Tizen Browser,
42
- UCBrowser, Vivaldi, Waterfox, WeChat, Yandex, baidu, iCab, w3m, ...
38
+ 2345Explorer, 360 Browser, Amaya, Android Browser, Arora, Avant, Avast, AVG,
39
+ BIDUBrowser, Baidu, Basilisk, Blazer, Bolt, Brave, Bowser, Camino, Chimera,
40
+ Chrome Headless, Chrome WebView, Chrome, Chromium, Comodo Dragon, Dillo,
41
+ Dolphin, Doris, Edge, Electron, Epiphany, Facebook, Falkon, Fennec, Firebird,
42
+ Firefox [Reality], Flock, Flow, GSA, GoBrowser, ICE Browser, IE, IEMobile, IceApe,
43
+ IceCat, IceDragon, Iceweasel, Instagram, Iridium, Iron, Jasmine, K-Meleon,
44
+ Kindle, Konqueror, LBBROWSER, Line, Links, Lunascape, Lynx, MIUI Browser,
45
+ Maemo Browser, Maemo, Maxthon, MetaSr Midori, Minimo, Mobile Safari, Mosaic,
46
+ Mozilla, NetFront, NetSurf, Netfront, Netscape, NokiaBrowser, Oculus Browser,
47
+ OmniWeb, Opera Coast, Opera [Mini/Mobi/Tablet], PaleMoon, PhantomJS, Phoenix,
48
+ Polaris, Puffin, QQ, QQBrowser, QQBrowserLite, Quark, QupZilla, RockMelt, Safari,
49
+ Sailfish Browser, Samsung Browser, SeaMonkey, Silk, Skyfire, Sleipnir, Slim,
50
+ SlimBrowser, Swiftfox, Tesla, Tizen Browser, UCBrowser, Vivaldi, Waterfox, WeChat,
51
+ Weibo, Yandex, baidu, iCab, w3m, Whale Browser...
43
52
 
44
53
  # 'browser.version' determined dynamically
45
54
  ```
46
55
 
47
56
  * `getDevice()`
48
- * returns `{ model: '', type: '', vendor: '' }`
57
+ * returns `{ model: '', type: '', vendor: '' }`
49
58
 
50
59
  ```sh
51
60
  # Possible 'device.type':
52
61
  console, mobile, tablet, smarttv, wearable, embedded
53
62
 
54
63
  # Possible 'device.vendor':
55
- Acer, Alcatel, Amazon, Apple, Archos, Asus, BenQ, BlackBerry, Dell, Essential,
56
- GeeksPhone, Google, HP, HTC, Huawei, Jolla, Lenovo, LG, Meizu, Microsoft, Motorola,
57
- Nexian, Nintendo, Nokia, Nvidia, OnePlus, Ouya, Palm, Panasonic, Pebble, Polytron,
58
- RIM, Samsung, Sharp, Siemens, Sony[Ericsson], Sprint, Xbox, Xiaomi, ZTE, ...
64
+ Acer, Alcatel, Amazon, Apple, Archos, ASUS, AT&T, BenQ, BlackBerry, Dell,
65
+ Essential, Fairphone, GeeksPhone, Google, HP, HTC, Huawei, Jolla, Lenovo, LG,
66
+ Meizu, Microsoft, Motorola, Nexian, Nintendo, Nokia, Nvidia, OnePlus, OPPO, Ouya,
67
+ Palm, Panasonic, Pebble, Polytron, Realme, RIM, Samsung, Sharp, Siemens,
68
+ Sony[Ericsson], Sprint, Tesla, Vivo, Vodafone, Xbox, Xiaomi, Zebra, ZTE, ...
59
69
 
60
70
  # 'device.model' determined dynamically
61
71
  ```
@@ -65,8 +75,8 @@ RIM, Samsung, Sharp, Siemens, Sony[Ericsson], Sprint, Xbox, Xiaomi, ZTE, ...
65
75
 
66
76
  ```sh
67
77
  # Possible 'engine.name'
68
- Amaya, Blink, EdgeHTML, Gecko, Goanna, iCab, KHTML, Links, Lynx, NetFront, NetSurf,
69
- Presto, Tasman, Trident, w3m, WebKit
78
+ Amaya, Blink, EdgeHTML, Flow, Gecko, Goanna, iCab, KHTML, Links, Lynx, NetFront,
79
+ NetSurf, Presto, Tasman, Trident, w3m, WebKit
70
80
 
71
81
  # 'engine.version' determined dynamically
72
82
  ```
@@ -76,12 +86,13 @@ Presto, Tasman, Trident, w3m, WebKit
76
86
 
77
87
  ```sh
78
88
  # Possible 'os.name'
79
- AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS, Contiki,
80
- Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Fuchsia, Gentoo, GNU, Haiku, Hurd, iOS,
81
- Joli, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo, Minix, Mint, Morph OS, NetBSD,
82
- Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD, PCLinuxOS, Plan9, Playstation, QNX, RedHat,
83
- RIM Tablet OS, RISC OS, Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen,
84
- Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
89
+ AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,
90
+ Contiki, Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Fuchsia, Gentoo, GNU,
91
+ Haiku, Hurd, iOS, Joli, KaiOS, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo,
92
+ Minix, Mint, Morph OS, NetBSD, Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD,
93
+ PCLinuxOS, Plan9, PlayStation, QNX, Raspbian, RedHat, RIM Tablet OS, RISC OS,
94
+ Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen, Ubuntu, Unix,
95
+ VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
85
96
 
86
97
  # 'os.version' determined dynamically
87
98
  ```
@@ -91,7 +102,7 @@ Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
91
102
 
92
103
  ```sh
93
104
  # Possible 'cpu.architecture'
94
- 68k, amd64, arm[64], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]
105
+ 68k, amd64, arm[64/hf], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]
95
106
  ```
96
107
 
97
108
  * `getResult()`
@@ -101,30 +112,30 @@ Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
101
112
  * returns UA string of current instance
102
113
 
103
114
  * `setUA(uastring)`
104
- * set UA string to parse
115
+ * set UA string to be parsed
105
116
  * returns current instance
106
117
 
118
+ # Usage
107
119
 
108
- # Example
120
+ ## Using HTML
109
121
 
110
122
  ```html
111
123
  <!doctype html>
112
124
  <html>
113
125
  <head>
114
- <script type="text/javascript" src="ua-parser.min.js"></script>
115
- <script type="text/javascript">
126
+ <script src="ua-parser.min.js"></script>
127
+ <script>
116
128
 
117
- var parser = new UAParser();
118
-
119
- // by default it takes ua string from current browser's window.navigator.userAgent
129
+ var parser = new UAParser();
120
130
  console.log(parser.getResult());
121
131
  /*
122
- /// this will print an object structured like this:
132
+ /// This will print an object structured like this:
123
133
  {
124
134
  ua: "",
125
135
  browser: {
126
136
  name: "",
127
- version: ""
137
+ version: "",
138
+ major: "" //@deprecated
128
139
  },
129
140
  engine: {
130
141
  name: "",
@@ -144,14 +155,14 @@ Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
144
155
  }
145
156
  }
146
157
  */
158
+ // Default result depends on current window.navigator.userAgent value
147
159
 
148
- // let's test a custom user-agent string as an example
149
- var uastring = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2";
150
- parser.setUA(uastring);
151
-
160
+ // Now let's try a custom user-agent string as an example
161
+ var uastring1 = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2";
162
+ parser.setUA(uastring1);
152
163
  var result = parser.getResult();
153
- // this will also produce the same result (without instantiation):
154
- // var result = UAParser(uastring);
164
+ // You can also use UAParser constructor directly without having to create an instance:
165
+ // var result = UAParser(uastring1);
155
166
 
156
167
  console.log(result.browser); // {name: "Chromium", version: "15.0.874.106"}
157
168
  console.log(result.device); // {model: undefined, type: undefined, vendor: undefined}
@@ -160,7 +171,7 @@ Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
160
171
  console.log(result.engine.name); // "WebKit"
161
172
  console.log(result.cpu.architecture); // "amd64"
162
173
 
163
- // do some other tests
174
+ // Do some other tests
164
175
  var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)";
165
176
  console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror"
166
177
  console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
@@ -199,40 +210,6 @@ http.createServer(function (req, res) {
199
210
  console.log('Server running at http://127.0.0.1:1337/');
200
211
  ```
201
212
 
202
- ## Using requirejs
203
-
204
- ```js
205
- requirejs.config({
206
- baseUrl : 'js/lib', // path to your script directory
207
- paths : {
208
- 'ua-parser-js' : 'ua-parser.min'
209
- }
210
- });
211
-
212
- requirejs(['ua-parser-js'], function(UAParser) {
213
- var parser = new UAParser();
214
- console.log(parser.getResult());
215
- });
216
- ```
217
-
218
- ## Using CDN
219
-
220
- ```html
221
- <script src="https://cdn.jsdelivr.net/npm/ua-parser-js@0/dist/ua-parser.min.js"></script>
222
- ```
223
-
224
- ## Using bower
225
-
226
- ```sh
227
- $ bower install ua-parser-js
228
- ```
229
-
230
- ## Using meteor
231
-
232
- ```sh
233
- $ meteor add faisalman:ua-parser-js
234
- ```
235
-
236
213
  ## Using TypeScript
237
214
 
238
215
  ```sh
@@ -243,18 +220,18 @@ $ npm install --save @types/ua-parser-js
243
220
 
244
221
  ## Using jQuery/Zepto ($.ua)
245
222
 
246
- Although written in vanilla js (which means it doesn't depends on jQuery), this library will automatically detect if jQuery/Zepto is present and create `$.ua` object based on browser's user-agent (although in case you need, `window.UAParser` constructor is still present). To get/set user-agent you can use: `$.ua.get()` / `$.ua.set(uastring)`.
223
+ Although written in vanilla js, this library will automatically detect if jQuery/Zepto is present and create `$.ua` object (with values based on its User-Agent) along with `window.UAParser` constructor. To get/set user-agent you can use: `$.ua.get()` / `$.ua.set(uastring)`.
247
224
 
248
225
  ```js
249
- // In browser with default user-agent: 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0':
226
+ // Say we are in a browser with default user-agent: 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0':
250
227
 
251
- // Do some tests
228
+ // Get the details
252
229
  console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
253
230
  console.log($.ua.os); // {name: "Android", version: "2.3.4"}
254
231
  console.log($.ua.os.name); // "Android"
255
232
  console.log($.ua.get()); // "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0"
256
233
 
257
- // reset to custom user-agent
234
+ // Now lets try to reset to another custom user-agent
258
235
  $.ua.set('Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; Xoom Build/HWI69) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13');
259
236
 
260
237
  // Test again
@@ -268,54 +245,49 @@ console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
268
245
  $('body').addClass('ua-browser-' + $.ua.browser.name + ' ua-devicetype-' + $.ua.device.type);
269
246
  ```
270
247
 
271
- ## Extending regex patterns
248
+ ## Using Extension
272
249
 
273
250
  * `UAParser([uastring,] extensions)`
274
251
 
275
- Pass your own regexes to extend the limited matching rules.
276
-
277
252
  ```js
278
253
  // Example:
279
- var myOwnRegex = [[/(myownbrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]];
280
- var myParser = new UAParser({ browser: myOwnRegex });
281
- var uaString = 'Mozilla/5.0 MyOwnBrowser/1.3';
282
- console.log(myParser.setUA(uaString).getBrowser()); // {name: "MyOwnBrowser", version: "1.3"}
254
+ var myOwnListOfBrowsers = [
255
+ [/(mybrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]
256
+ ];
257
+ var myParser = new UAParser({ browser: myOwnListOfBrowsers });
258
+ var myUA = 'Mozilla/5.0 MyBrowser/1.3';
259
+ console.log(myParser.setUA(myUA).getBrowser()); // {name: "MyBrowser", version: "1.3"}
283
260
  ```
284
261
 
285
-
286
262
  # Development
287
263
 
288
- ## Contribute
264
+ ## Sponsors
289
265
 
290
- * Fork and clone this repository
291
- * Make some changes as required
292
- * Write a unit test to showcase your feature
293
- * Run the test suites to make sure the changes you made didn't break anything `$ npm run test`
294
- * Commit and push to your own repository
295
- * Submit a pull request to this repository under `develop` branch
296
- * Profit? $$$
297
-
298
- ## Build
299
-
300
- Build a minified & packed script
266
+ <a href="https://opencollective.com/ua-parser-js"><img src="https://opencollective.com/ua-parser-js/tiers/backers.svg?avatarHeight=64" height="80"/></a> <a href="https://opencollective.com/ua-parser-js"><img src="https://opencollective.com/ua-parser-js/tiers/sponsors.svg?avatarHeight=64" height="80"/></a>
301
267
 
302
- ```sh
303
- $ npm run build
304
- ```
268
+ <a href="https://www.paypal.me/faisalman/"><img src="https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg" height="40"></a>
305
269
 
270
+ ## Contributors
306
271
 
307
- # Donate
272
+ <a href="https://github.com/faisalman/ua-parser-js/graphs/contributors">
273
+ <img src="https://contrib.rocks/image?repo=faisalman/ua-parser-js" />
274
+ </a>
308
275
 
309
- Do you use & like UAParser.js but you don’t find a way to show some love? If yes, please consider donating to support this project. Otherwise, no worries, regardless of whether there is support or not, I will keep maintaining this project. Still, if you buy me a cup of coffee I would be more than happy though :)
276
+ Made with [contributors-img](https://contrib.rocks).
310
277
 
311
- [![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/faisalman/)
278
+ ## How To Contribute
312
279
 
280
+ * Fork and clone this repository
281
+ * Make some changes as required
282
+ * Write unit test to showcase its functionality
283
+ * Run the test suites to make sure it's not breaking anything `$ npm test`
284
+ * Submit a pull request under `develop` branch
313
285
 
314
286
  # License
315
287
 
316
288
  MIT License
317
289
 
318
- Copyright (c) 2012-2019 Faisal Salman <<f@faisalman.com>>
290
+ Copyright (c) 2012-2021 Faisal Salman <<f@faisalman.com>>
319
291
 
320
292
  Permission is hereby granted, free of charge, to any person obtaining a copy
321
293
  of this software and associated documentation files (the "Software"), to deal