ua-parser-js 0.7.24 → 0.7.25

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,338 +1,307 @@
1
- # UAParser.js
2
-
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.
4
-
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)
10
-
11
- * Author : Faisal Salman <<f@faisalman.com>>
12
- * Demo : http://faisalman.github.io/ua-parser-js
13
- * Source : https://github.com/faisalman/ua-parser-js
14
-
15
- # Constructor
16
-
17
- * `new UAParser([uastring][,extensions])`
18
- * returns new instance
19
-
20
- * `UAParser([uastring][,extensions])`
21
- * returns result object `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
22
-
23
- # Methods
24
-
25
- * `getBrowser()`
26
- * returns `{ name: '', version: '' }`
27
-
28
- ```sh
29
- # 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, Whale Browser...
44
-
45
- # 'browser.version' determined dynamically
46
- ```
47
-
48
- * `getDevice()`
49
- * returns `{ model: '', type: '', vendor: '' }`
50
-
51
- ```sh
52
- # Possible 'device.type':
53
- console, mobile, tablet, smarttv, wearable, embedded
54
-
55
- # 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, ...
60
-
61
- # 'device.model' determined dynamically
62
- ```
63
-
64
- * `getEngine()`
65
- * returns `{ name: '', version: '' }`
66
-
67
- ```sh
68
- # Possible 'engine.name'
69
- Amaya, Blink, EdgeHTML, Gecko, Goanna, iCab, KHTML, Links, Lynx, NetFront,
70
- NetSurf, Presto, Tasman, Trident, w3m, WebKit
71
-
72
- # 'engine.version' determined dynamically
73
- ```
74
-
75
- * `getOS()`
76
- * returns `{ name: '', version: '' }`
77
-
78
- ```sh
79
- # 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, ...
87
-
88
- # 'os.version' determined dynamically
89
- ```
90
-
91
- * `getCPU()`
92
- * returns `{ architecture: '' }`
93
-
94
- ```sh
95
- # Possible 'cpu.architecture'
96
- 68k, amd64, arm[64], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]
97
- ```
98
-
99
- * `getResult()`
100
- * returns `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
101
-
102
- * `getUA()`
103
- * returns UA string of current instance
104
-
105
- * `setUA(uastring)`
106
- * set UA string to parse
107
- * returns current instance
108
-
109
-
110
- # Example
111
-
112
- ```html
113
- <!doctype html>
114
- <html>
115
- <head>
116
- <script src="ua-parser.min.js"></script>
117
- <script>
118
-
119
- var parser = new UAParser();
120
-
121
- // by default it takes ua string from current browser's window.navigator.userAgent
122
- console.log(parser.getResult());
123
- /*
124
- /// this will print an object structured like this:
125
- {
126
- ua: "",
127
- browser: {
128
- name: "",
129
- version: ""
130
- },
131
- engine: {
132
- name: "",
133
- version: ""
134
- },
135
- os: {
136
- name: "",
137
- version: ""
138
- },
139
- device: {
140
- model: "",
141
- type: "",
142
- vendor: ""
143
- },
144
- cpu: {
145
- architecture: ""
146
- }
147
- }
148
- */
149
-
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
-
154
- var result = parser.getResult();
155
- // this will also produce the same result (without instantiation):
156
- // var result = UAParser(uastring);
157
-
158
- console.log(result.browser); // {name: "Chromium", version: "15.0.874.106"}
159
- console.log(result.device); // {model: undefined, type: undefined, vendor: undefined}
160
- console.log(result.os); // {name: "Ubuntu", version: "11.10"}
161
- console.log(result.os.version); // "11.10"
162
- console.log(result.engine.name); // "WebKit"
163
- console.log(result.cpu.architecture); // "amd64"
164
-
165
- // do some other tests
166
- var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)";
167
- console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror"
168
- console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
169
- console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"}
170
-
171
- var uastring3 = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11';
172
- console.log(parser.setUA(uastring3).getDevice().model); // "PlayBook"
173
- console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
174
- console.log(parser.getBrowser().name); // "Safari"
175
-
176
- </script>
177
- </head>
178
- <body>
179
- </body>
180
- </html>
181
- ```
182
-
183
- ## Using node.js
184
-
185
- ```sh
186
- $ npm install ua-parser-js
187
- ```
188
-
189
- ```js
190
- var http = require('http');
191
- var parser = require('ua-parser-js');
192
-
193
- http.createServer(function (req, res) {
194
- // get user-agent header
195
- var ua = parser(req.headers['user-agent']);
196
- // write the result as response
197
- res.end(JSON.stringify(ua, null, ' '));
198
- })
199
- .listen(1337, '127.0.0.1');
200
-
201
- console.log('Server running at http://127.0.0.1:1337/');
202
- ```
203
-
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
- ## Using TypeScript
239
-
240
- ```sh
241
- $ npm install --save @types/ua-parser-js
242
- # Download TS type definition from DefinitelyTyped repository:
243
- # https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/ua-parser-js
244
- ```
245
-
246
- ## Using jQuery/Zepto ($.ua)
247
-
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)`.
249
-
250
- ```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':
252
-
253
- // Do some tests
254
- console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
255
- console.log($.ua.os); // {name: "Android", version: "2.3.4"}
256
- console.log($.ua.os.name); // "Android"
257
- 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
-
259
- // reset to custom user-agent
260
- $.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
-
262
- // Test again
263
- console.log($.ua.browser.name); // "Safari"
264
- console.log($.ua.engine.name); // "Webkit"
265
- console.log($.ua.device); // {vendor: "Motorola", model: "Xoom", type: "tablet"}
266
- console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
267
-
268
- // Add class to <body> tag
269
- // <body class="ua-browser-safari ua-devicetype-tablet">
270
- $('body').addClass('ua-browser-' + $.ua.browser.name + ' ua-devicetype-' + $.ua.device.type);
271
- ```
272
-
273
- ## Extending regex patterns
274
-
275
- * `UAParser([uastring,] extensions)`
276
-
277
- Pass your own regexes to extend the limited matching rules.
278
-
279
- ```js
280
- // 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"}
285
- ```
286
-
287
-
288
- # Development
289
-
290
- ## Contribute
291
-
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
303
-
304
- ```sh
305
- $ npm run build
306
- ```
307
-
308
-
309
- # Donate
310
-
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 :)
312
-
313
- [![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/faisalman/)
314
-
315
-
316
- # License
317
-
318
- MIT License
319
-
320
- Copyright (c) 2012-2021 Faisal Salman <<f@faisalman.com>>
321
-
322
- Permission is hereby granted, free of charge, to any person obtaining a copy
323
- of this software and associated documentation files (the "Software"), to deal
324
- in the Software without restriction, including without limitation the rights
325
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
326
- copies of the Software, and to permit persons to whom the Software is
327
- furnished to do so, subject to the following conditions:
328
-
329
- The above copyright notice and this permission notice shall be included in all
330
- copies or substantial portions of the Software.
331
-
332
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
333
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
334
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
335
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
336
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
337
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
338
- SOFTWARE.
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>
12
+
13
+ # UAParser.js
14
+
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).
16
+
17
+ * Author : Faisal Salman <<f@faisalman.com>>
18
+ * Demo : http://faisalman.github.io/ua-parser-js
19
+ * Source : https://github.com/faisalman/ua-parser-js
20
+
21
+ # Documentation
22
+
23
+ ## Constructor
24
+
25
+ * `new UAParser([uastring][,extensions])`
26
+ * returns new instance
27
+
28
+ * `UAParser([uastring][,extensions])`
29
+ * returns result object `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
30
+
31
+ ## Methods
32
+
33
+ * `getBrowser()`
34
+ * returns `{ name: '', version: '' }`
35
+
36
+ ```sh
37
+ # Possible 'browser.name':
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, Epiphany, Facebook, Falkon, Fennec, Firebird, Firefox,
42
+ Flock, GSA, GoBrowser, ICE Browser, IE, IEMobile, IceApe, IceCat, IceDragon,
43
+ Iceape, Iceweasel, Instagram, Iridium, Iron, Jasmine, K-Meleon, Kindle,
44
+ 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, Opera Mobi, Opera Tablet, Opera, PaleMoon,
48
+ PhantomJS, Phoenix, Polaris, Puffin, QQ, QQBrowser, QQBrowserLite, Quark,
49
+ QupZilla, RockMelt, Safari, Sailfish Browser, Samsung Browser, SeaMonkey, Silk,
50
+ Skyfire, Sleipnir, Slim, SlimBrowser, Swiftfox, Tizen Browser, UCBrowser,
51
+ Vivaldi, Waterfox, WeChat, Weibo, Yandex, baidu, iCab, w3m, Whale Browser...
52
+
53
+ # 'browser.version' determined dynamically
54
+ ```
55
+
56
+ * `getDevice()`
57
+ * returns `{ model: '', type: '', vendor: '' }`
58
+
59
+ ```sh
60
+ # Possible 'device.type':
61
+ console, mobile, tablet, smarttv, wearable, embedded
62
+
63
+ # Possible 'device.vendor':
64
+ Acer, Alcatel, Amazon, Apple, Archos, Asus, BenQ, BlackBerry, Dell, Essential,
65
+ GeeksPhone, Google, HP, HTC, Huawei, Jolla, Lenovo, LG, Meizu, Microsoft, Motorola,
66
+ Nexian, Nintendo, Nokia, Nvidia, OnePlus, Ouya, Palm, Panasonic, Pebble, Polytron,
67
+ RIM, Samsung, Sharp, Siemens, Sony[Ericsson], Sprint, Xbox, Xiaomi, ZTE, ...
68
+
69
+ # 'device.model' determined dynamically
70
+ ```
71
+
72
+ * `getEngine()`
73
+ * returns `{ name: '', version: '' }`
74
+
75
+ ```sh
76
+ # Possible 'engine.name'
77
+ Amaya, Blink, EdgeHTML, Gecko, Goanna, iCab, KHTML, Links, Lynx, NetFront,
78
+ NetSurf, Presto, Tasman, Trident, w3m, WebKit
79
+
80
+ # 'engine.version' determined dynamically
81
+ ```
82
+
83
+ * `getOS()`
84
+ * returns `{ name: '', version: '' }`
85
+
86
+ ```sh
87
+ # Possible 'os.name'
88
+ AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,
89
+ Contiki, Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Fuchsia, Gentoo, GNU,
90
+ Haiku, Hurd, iOS, Joli, KaiOS, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo,
91
+ Minix, Mint, Morph OS, NetBSD, Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD,
92
+ PCLinuxOS, Plan9, PlayStation, QNX, RedHat, RIM Tablet OS, RISC OS, Sailfish,
93
+ Series40, Slackware, Solaris, SUSE, Symbian, Tizen, Ubuntu, Unix, VectorLinux,
94
+ WebOS, Windows [Phone/Mobile], Zenwalk, ...
95
+
96
+ # 'os.version' determined dynamically
97
+ ```
98
+
99
+ * `getCPU()`
100
+ * returns `{ architecture: '' }`
101
+
102
+ ```sh
103
+ # Possible 'cpu.architecture'
104
+ 68k, amd64, arm[64], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]
105
+ ```
106
+
107
+ * `getResult()`
108
+ * returns `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
109
+
110
+ * `getUA()`
111
+ * returns UA string of current instance
112
+
113
+ * `setUA(uastring)`
114
+ * set UA string to be parsed
115
+ * returns current instance
116
+
117
+ # Usage
118
+
119
+ ## Using HTML
120
+
121
+ ```html
122
+ <!doctype html>
123
+ <html>
124
+ <head>
125
+ <script src="ua-parser.min.js"></script>
126
+ <script>
127
+
128
+ var parser = new UAParser();
129
+ console.log(parser.getResult());
130
+ /*
131
+ /// This will print an object structured like this:
132
+ {
133
+ ua: "",
134
+ browser: {
135
+ name: "",
136
+ version: "",
137
+ major: "" //@deprecated
138
+ },
139
+ engine: {
140
+ name: "",
141
+ version: ""
142
+ },
143
+ os: {
144
+ name: "",
145
+ version: ""
146
+ },
147
+ device: {
148
+ model: "",
149
+ type: "",
150
+ vendor: ""
151
+ },
152
+ cpu: {
153
+ architecture: ""
154
+ }
155
+ }
156
+ */
157
+ // Default result depends on current window.navigator.userAgent value
158
+
159
+ // Now let's try a custom user-agent string as an example
160
+ 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";
161
+ parser.setUA(uastring1);
162
+ var result = parser.getResult();
163
+ // You can also use UAParser constructor directly without having to create an instance:
164
+ // var result = UAParser(uastring1);
165
+
166
+ console.log(result.browser); // {name: "Chromium", version: "15.0.874.106"}
167
+ console.log(result.device); // {model: undefined, type: undefined, vendor: undefined}
168
+ console.log(result.os); // {name: "Ubuntu", version: "11.10"}
169
+ console.log(result.os.version); // "11.10"
170
+ console.log(result.engine.name); // "WebKit"
171
+ console.log(result.cpu.architecture); // "amd64"
172
+
173
+ // Do some other tests
174
+ var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)";
175
+ console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror"
176
+ console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
177
+ console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"}
178
+
179
+ var uastring3 = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11';
180
+ console.log(parser.setUA(uastring3).getDevice().model); // "PlayBook"
181
+ console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
182
+ console.log(parser.getBrowser().name); // "Safari"
183
+
184
+ </script>
185
+ </head>
186
+ <body>
187
+ </body>
188
+ </html>
189
+ ```
190
+
191
+ ## Using node.js
192
+
193
+ ```sh
194
+ $ npm install ua-parser-js
195
+ ```
196
+
197
+ ```js
198
+ var http = require('http');
199
+ var parser = require('ua-parser-js');
200
+
201
+ http.createServer(function (req, res) {
202
+ // get user-agent header
203
+ var ua = parser(req.headers['user-agent']);
204
+ // write the result as response
205
+ res.end(JSON.stringify(ua, null, ' '));
206
+ })
207
+ .listen(1337, '127.0.0.1');
208
+
209
+ console.log('Server running at http://127.0.0.1:1337/');
210
+ ```
211
+
212
+ ## Using TypeScript
213
+
214
+ ```sh
215
+ $ npm install --save @types/ua-parser-js
216
+ # Download TS type definition from DefinitelyTyped repository:
217
+ # https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/ua-parser-js
218
+ ```
219
+
220
+ ## Using jQuery/Zepto ($.ua)
221
+
222
+ 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)`.
223
+
224
+ ```js
225
+ // 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':
226
+
227
+ // Get the details
228
+ console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
229
+ console.log($.ua.os); // {name: "Android", version: "2.3.4"}
230
+ console.log($.ua.os.name); // "Android"
231
+ 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"
232
+
233
+ // Now lets try to reset to another custom user-agent
234
+ $.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');
235
+
236
+ // Test again
237
+ console.log($.ua.browser.name); // "Safari"
238
+ console.log($.ua.engine.name); // "Webkit"
239
+ console.log($.ua.device); // {vendor: "Motorola", model: "Xoom", type: "tablet"}
240
+ console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
241
+
242
+ // Add class to <body> tag
243
+ // <body class="ua-browser-safari ua-devicetype-tablet">
244
+ $('body').addClass('ua-browser-' + $.ua.browser.name + ' ua-devicetype-' + $.ua.device.type);
245
+ ```
246
+
247
+ ## Using Extension
248
+
249
+ * `UAParser([uastring,] extensions)`
250
+
251
+ ```js
252
+ // Example:
253
+ var myOwnListOfBrowsers = [
254
+ [/(mybrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]
255
+ ];
256
+ var myParser = new UAParser({ browser: myOwnListOfBrowsers });
257
+ var myUA = 'Mozilla/5.0 MyBrowser/1.3';
258
+ console.log(myParser.setUA(myUA).getBrowser()); // {name: "MyBrowser", version: "1.3"}
259
+ ```
260
+
261
+ # Development
262
+
263
+ ## Sponsors
264
+
265
+ <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>
266
+
267
+ <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>
268
+
269
+ ## Contributors
270
+
271
+ <a href="https://github.com/faisalman/ua-parser-js/graphs/contributors">
272
+ <img src="https://contrib.rocks/image?repo=faisalman/ua-parser-js" />
273
+ </a>
274
+
275
+ Made with [contributors-img](https://contrib.rocks).
276
+
277
+ ## How To Contribute
278
+
279
+ * Fork and clone this repository
280
+ * Make some changes as required
281
+ * Write unit test to showcase its functionality
282
+ * Run the test suites to make sure it's not breaking anything `$ npm test`
283
+ * Submit a pull request under `develop` branch
284
+
285
+ # License
286
+
287
+ MIT License
288
+
289
+ Copyright (c) 2012-2021 Faisal Salman <<f@faisalman.com>>
290
+
291
+ Permission is hereby granted, free of charge, to any person obtaining a copy
292
+ of this software and associated documentation files (the "Software"), to deal
293
+ in the Software without restriction, including without limitation the rights
294
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
295
+ copies of the Software, and to permit persons to whom the Software is
296
+ furnished to do so, subject to the following conditions:
297
+
298
+ The above copyright notice and this permission notice shall be included in all
299
+ copies or substantial portions of the Software.
300
+
301
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
302
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
303
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
304
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
305
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
306
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
307
+ SOFTWARE.