ua-parser-js 0.7.22 → 1.0.2

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
@@ -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
- * Demo : http://faisalman.github.io/ua-parser-js
18
+ * Demo : https://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,43 +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, 360 Browser, Amaya, Android Browser, Arora, Avant, Avast, AVG,
31
- BIDUBrowser, Baidu, Basilisk, Blazer, Bolt, Brave, Bowser, Camino, Chimera,
32
- Chrome Headless, Chrome WebView, Chrome, Chromium, Comodo Dragon, Dillo,
33
- Dolphin, Doris, Edge, Epiphany, Facebook, Falkon, Fennec, Firebird, Firefox,
34
- Flock, GSA, GoBrowser, ICE Browser, IE, IEMobile, IceApe, IceCat, IceDragon,
35
- Iceape, Iceweasel, Iridium, Iron, Jasmine, K-Meleon, Kindle, Konqueror,
36
- LBBROWSER Line, Links, Lunascape, Lynx, MIUI Browser, Maemo Browser, Maemo,
37
- Maxthon, MetaSr Midori, Minimo, Mobile Safari, Mosaic, Mozilla, NetFront,
38
- NetSurf, Netfront, Netscape, NokiaBrowser, Oculus Browser, OmniWeb,
39
- Opera Coast, Opera Mini, Opera Mobi, Opera Tablet, Opera, PaleMoon, PhantomJS,
40
- Phoenix, Polaris, Puffin, QQ, QQBrowser, QQBrowserLite, Quark, QupZilla,
41
- RockMelt, Safari, Sailfish Browser, Samsung Browser, SeaMonkey, Silk, Skyfire,
42
- Sleipnir, Slim, SlimBrowser, Swiftfox, Tizen Browser, UCBrowser, Vivaldi,
43
- 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, Klar, 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, Obigo, 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, UP.Browser, Vivaldi,
51
+ Waterfox, WeChat, Weibo, Yandex, baidu, iCab, w3m, Whale Browser...
44
52
 
45
53
  # 'browser.version' determined dynamically
46
54
  ```
47
55
 
48
56
  * `getDevice()`
49
- * returns `{ model: '', type: '', vendor: '' }`
57
+ * returns `{ model: '', type: '', vendor: '' }`
50
58
 
51
59
  ```sh
52
60
  # Possible 'device.type':
53
61
  console, mobile, tablet, smarttv, wearable, embedded
54
62
 
55
63
  # Possible 'device.vendor':
56
- Acer, Alcatel, Amazon, Apple, Archos, Asus, BenQ, BlackBerry, Dell, Essential,
57
- GeeksPhone, Google, HP, HTC, Huawei, Jolla, Lenovo, LG, Meizu, Microsoft, Motorola,
58
- Nexian, Nintendo, Nokia, Nvidia, OnePlus, Ouya, Palm, Panasonic, Pebble, Polytron,
59
- 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, Roku, Samsung, Sharp, Siemens,
68
+ Sony[Ericsson], Sprint, Tesla, Vivo, Vodafone, Xbox, Xiaomi, Zebra, ZTE, ...
60
69
 
61
70
  # 'device.model' determined dynamically
62
71
  ```
@@ -66,7 +75,7 @@ RIM, Samsung, Sharp, Siemens, Sony[Ericsson], Sprint, Xbox, Xiaomi, ZTE, ...
66
75
 
67
76
  ```sh
68
77
  # Possible 'engine.name'
69
- Amaya, Blink, EdgeHTML, Gecko, Goanna, iCab, KHTML, Links, Lynx, NetFront,
78
+ Amaya, Blink, EdgeHTML, Flow, Gecko, Goanna, iCab, KHTML, Links, Lynx, NetFront,
70
79
  NetSurf, Presto, Tasman, Trident, w3m, WebKit
71
80
 
72
81
  # 'engine.version' determined dynamically
@@ -77,13 +86,13 @@ NetSurf, Presto, Tasman, Trident, w3m, WebKit
77
86
 
78
87
  ```sh
79
88
  # Possible 'os.name'
80
- AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,
81
- Contiki, Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Fuchsia, Gentoo, GNU,
82
- Haiku, Hurd, iOS, Joli, KaiOS, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo,
83
- Minix, Mint, Morph OS, NetBSD, Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD,
84
- PCLinuxOS, Plan9, Playstation, QNX, RedHat, RIM Tablet OS, RISC OS, Sailfish,
85
- Series40, Slackware, Solaris, SUSE, Symbian, Tizen, Ubuntu, Unix, VectorLinux,
86
- WebOS, Windows [Phone/Mobile], Zenwalk, ...
89
+ AIX, Amiga OS, Android[-x86], Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,
90
+ Contiki, Fedora, Firefox OS, FreeBSD, Debian, Deepin, DragonFly, elementary OS,
91
+ Fuchsia, Gentoo, GhostBSD, GNU, Haiku, HP-UX, Hurd, iOS, Joli, KaiOS, Linpus, Linspire,
92
+ Linux, Mac OS, Maemo, Mageia, Mandriva, Manjaro, MeeGo, Minix, Mint, Morph OS, NetBSD,
93
+ Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD, PCLinuxOS, Plan9, PlayStation, QNX,
94
+ Raspbian, RedHat, RIM Tablet OS, RISC OS, Sabayon, Sailfish, Series40, Slackware, Solaris,
95
+ SUSE, Symbian, Tizen, Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
87
96
 
88
97
  # 'os.version' determined dynamically
89
98
  ```
@@ -93,7 +102,7 @@ WebOS, Windows [Phone/Mobile], Zenwalk, ...
93
102
 
94
103
  ```sh
95
104
  # Possible 'cpu.architecture'
96
- 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]
97
106
  ```
98
107
 
99
108
  * `getResult()`
@@ -103,11 +112,12 @@ WebOS, Windows [Phone/Mobile], Zenwalk, ...
103
112
  * returns UA string of current instance
104
113
 
105
114
  * `setUA(uastring)`
106
- * set UA string to parse
115
+ * set UA string to be parsed
107
116
  * returns current instance
108
117
 
118
+ # Usage
109
119
 
110
- # Example
120
+ ## Using HTML
111
121
 
112
122
  ```html
113
123
  <!doctype html>
@@ -117,16 +127,15 @@ WebOS, Windows [Phone/Mobile], Zenwalk, ...
117
127
  <script>
118
128
 
119
129
  var parser = new UAParser();
120
-
121
- // by default it takes ua string from current browser's window.navigator.userAgent
122
130
  console.log(parser.getResult());
123
131
  /*
124
- /// this will print an object structured like this:
132
+ /// This will print an object structured like this:
125
133
  {
126
134
  ua: "",
127
135
  browser: {
128
136
  name: "",
129
- version: ""
137
+ version: "",
138
+ major: "" //@deprecated
130
139
  },
131
140
  engine: {
132
141
  name: "",
@@ -146,14 +155,14 @@ WebOS, Windows [Phone/Mobile], Zenwalk, ...
146
155
  }
147
156
  }
148
157
  */
158
+ // Default result depends on current window.navigator.userAgent value
149
159
 
150
- // let's test a custom user-agent string as an example
151
- 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";
152
- parser.setUA(uastring);
153
-
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);
154
163
  var result = parser.getResult();
155
- // this will also produce the same result (without instantiation):
156
- // var result = UAParser(uastring);
164
+ // You can also use UAParser constructor directly without having to create an instance:
165
+ // var result = UAParser(uastring1);
157
166
 
158
167
  console.log(result.browser); // {name: "Chromium", version: "15.0.874.106"}
159
168
  console.log(result.device); // {model: undefined, type: undefined, vendor: undefined}
@@ -162,7 +171,7 @@ WebOS, Windows [Phone/Mobile], Zenwalk, ...
162
171
  console.log(result.engine.name); // "WebKit"
163
172
  console.log(result.cpu.architecture); // "amd64"
164
173
 
165
- // do some other tests
174
+ // Do some other tests
166
175
  var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)";
167
176
  console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror"
168
177
  console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
@@ -201,40 +210,6 @@ http.createServer(function (req, res) {
201
210
  console.log('Server running at http://127.0.0.1:1337/');
202
211
  ```
203
212
 
204
- ## Using requirejs
205
-
206
- ```js
207
- requirejs.config({
208
- baseUrl : 'js/lib', // path to your script directory
209
- paths : {
210
- 'ua-parser-js' : 'ua-parser.min'
211
- }
212
- });
213
-
214
- requirejs(['ua-parser-js'], function(UAParser) {
215
- var parser = new UAParser();
216
- console.log(parser.getResult());
217
- });
218
- ```
219
-
220
- ## Using CDN
221
-
222
- ```html
223
- <script src="https://cdn.jsdelivr.net/npm/ua-parser-js@0/dist/ua-parser.min.js"></script>
224
- ```
225
-
226
- ## Using bower
227
-
228
- ```sh
229
- $ bower install ua-parser-js
230
- ```
231
-
232
- ## Using meteor
233
-
234
- ```sh
235
- $ meteor add faisalman:ua-parser-js
236
- ```
237
-
238
213
  ## Using TypeScript
239
214
 
240
215
  ```sh
@@ -245,18 +220,18 @@ $ npm install --save @types/ua-parser-js
245
220
 
246
221
  ## Using jQuery/Zepto ($.ua)
247
222
 
248
- 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)`.
249
224
 
250
225
  ```js
251
- // 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':
252
227
 
253
- // Do some tests
228
+ // Get the details
254
229
  console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
255
230
  console.log($.ua.os); // {name: "Android", version: "2.3.4"}
256
231
  console.log($.ua.os.name); // "Android"
257
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"
258
233
 
259
- // reset to custom user-agent
234
+ // Now lets try to reset to another custom user-agent
260
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');
261
236
 
262
237
  // Test again
@@ -270,54 +245,49 @@ console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
270
245
  $('body').addClass('ua-browser-' + $.ua.browser.name + ' ua-devicetype-' + $.ua.device.type);
271
246
  ```
272
247
 
273
- ## Extending regex patterns
248
+ ## Using Extension
274
249
 
275
250
  * `UAParser([uastring,] extensions)`
276
251
 
277
- Pass your own regexes to extend the limited matching rules.
278
-
279
252
  ```js
280
253
  // Example:
281
- var myOwnRegex = [[/(myownbrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]];
282
- var myParser = new UAParser({ browser: myOwnRegex });
283
- var uaString = 'Mozilla/5.0 MyOwnBrowser/1.3';
284
- 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"}
285
260
  ```
286
261
 
287
-
288
262
  # Development
289
263
 
290
- ## Contribute
264
+ ## Sponsors
291
265
 
292
- * Fork and clone this repository
293
- * Make some changes as required
294
- * Write a unit test to showcase your feature
295
- * Run the test suites to make sure the changes you made didn't break anything `$ npm run test`
296
- * Commit and push to your own repository
297
- * Submit a pull request to this repository under `develop` branch
298
- * Profit? $$$
299
-
300
- ## Build
301
-
302
- 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>
303
267
 
304
- ```sh
305
- $ npm run build
306
- ```
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>
307
269
 
270
+ ## Contributors
308
271
 
309
- # 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>
310
275
 
311
- 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).
312
277
 
313
- [![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
314
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
315
285
 
316
286
  # License
317
287
 
318
288
  MIT License
319
289
 
320
- Copyright (c) 2012-2019 Faisal Salman <<f@faisalman.com>>
290
+ Copyright (c) 2012-2021 Faisal Salman <<f@faisalman.com>>
321
291
 
322
292
  Permission is hereby granted, free of charge, to any person obtaining a copy
323
293
  of this software and associated documentation files (the "Software"), to deal
package/security.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ Please report security issues to `f@faisalman.com`