ua-parser-js 0.7.10 → 0.7.14

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,281 +1,311 @@
1
- # UAParser.js
2
-
3
- Lightweight JavaScript-based User-Agent string parser. Supports browser & node.js environment. Also available as jQuery/Zepto plugin, Component/Bower/Meteor package, & RequireJS/AMD module
4
-
5
- [![Build Status](https://travis-ci.org/faisalman/ua-parser-js.svg?branch=master)](https://travis-ci.org/faisalman/ua-parser-js)
6
- [![Flattr this](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/3867907/faisalmanua-parser-js-on-GitHub)
7
-
8
- * Author : Faisal Salman <<fyzlman@gmail.com>>
9
- * Demo : http://faisalman.github.io/ua-parser-js
10
- * Source : https://github.com/faisalman/ua-parser-js
11
-
12
- ## Features
13
-
14
- Extract detailed type of web browser, layout engine, operating system, cpu architecture, and device type/model purely from user-agent string with relatively lightweight footprint (~11KB minified / ~4KB gzipped). Written in vanilla js, which means it doesn't depends on any other library.
15
-
16
- ![It's over 9000](https://raw.githubusercontent.com/faisalman/ua-parser-js/gh-pages/images/over9000.jpg)
17
-
18
- ## Methods
19
-
20
- * `getBrowser()`
21
- * returns `{ name: '', version: '' }`
22
-
23
- ```
24
- # Possible 'browser.name':
25
- Amaya, Android Browser, Arora, Avant, Baidu, Blazer, Bolt, Camino, Chimera, Chrome,
26
- Chromium, Comodo Dragon, Conkeror, Dillo, Dolphin, Doris, Edge, Epiphany, Fennec,
27
- Firebird, Firefox, Flock, GoBrowser, iCab, ICE Browser, IceApe, IceCat, IceDragon,
28
- Iceweasel, IE [Mobile], Iron, Jasmine, K-Meleon, Konqueror, Kindle, Links,
29
- Lunascape, Lynx, Maemo, Maxthon, Midori, Minimo, MIUI Browser, [Mobile] Safari,
30
- Mosaic, Mozilla, Netfront, Netscape, NetSurf, Nokia, OmniWeb, Opera [Mini/Mobi/Tablet],
31
- PhantomJS, Phoenix, Polaris, QQBrowser, RockMelt, Silk, Skyfire, SeaMonkey, SlimBrowser,
32
- Swiftfox, Tizen, UCBrowser, Vivaldi, w3m, Yandex
33
-
34
- # 'browser.version' determined dynamically
35
- ```
36
-
37
- * `getDevice()`
38
- * returns `{ model: '', type: '', vendor: '' }`
39
-
40
- ```
41
- # Possible 'device.type':
42
- console, mobile, tablet, smarttv, wearable, embedded
43
-
44
- # Possible 'device.vendor':
45
- Acer, Alcatel, Amazon, Apple, Archos, Asus, BenQ, BlackBerry, Dell, GeeksPhone,
46
- Google, HP, HTC, Huawei, Jolla, Lenovo, LG, Meizu, Microsoft, Motorola, Nexian,
47
- Nintendo, Nokia, Nvidia, Ouya, Palm, Panasonic, Polytron, RIM, Samsung, Sharp,
48
- Siemens, Sony-Ericsson, Sprint, Xbox, ZTE
49
-
50
- # 'device.model' determined dynamically
51
- ```
52
-
53
- * `getEngine()`
54
- * returns `{ name: '', version: '' }`
55
-
56
- ```
57
- # Possible 'engine.name'
58
- Amaya, EdgeHTML, Gecko, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto,
59
- Tasman, Trident, w3m, WebKit
60
-
61
- # 'engine.version' determined dynamically
62
- ```
63
-
64
- * `getOS()`
65
- * returns `{ name: '', version: '' }`
66
-
67
- ```
68
- # Possible 'os.name'
69
- AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS, Contiki,
70
- Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Gentoo, GNU, Haiku, Hurd, iOS,
71
- Joli, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo, Minix, Mint, Morph OS, NetBSD,
72
- Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PCLinuxOS, Plan9, Playstation, QNX, RedHat,
73
- RIM Tablet OS, RISC OS, Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen,
74
- Ubuntu, UNIX, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk
75
-
76
- # 'os.version' determined dynamically
77
- ```
78
-
79
- * `getCPU()`
80
- * returns `{ architecture: '' }`
81
-
82
- ```
83
- # Possible 'cpu.architecture'
84
- 68k, amd64, arm, arm64, avr, ia32, ia64, irix, irix64, mips, mips64, pa-risc,
85
- ppc, sparc, sparc64
86
- ```
87
-
88
- * `getResult()`
89
- * returns `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
90
-
91
- * `getUA()`
92
- * returns UA string of current instance
93
-
94
- * `setUA(uastring)`
95
- * set & parse UA string
96
-
97
- ## Example
98
-
99
- ```html
100
- <!doctype html>
101
- <html>
102
- <head>
103
- <script type="text/javascript" src="ua-parser.min.js"></script>
104
- <script type="text/javascript">
105
-
106
- var parser = new UAParser();
107
-
108
- // by default it takes ua string from current browser's window.navigator.userAgent
109
- console.log(parser.getResult());
110
- /*
111
- /// this will print an object structured like this:
112
- {
113
- ua: "",
114
- browser: {
115
- name: "",
116
- version: ""
117
- },
118
- engine: {
119
- name: "",
120
- version: ""
121
- },
122
- os: {
123
- name: "",
124
- version: ""
125
- },
126
- device: {
127
- model: "",
128
- type: "",
129
- vendor: ""
130
- },
131
- cpu: {
132
- architecture: ""
133
- }
134
- }
135
- */
136
-
137
- // let's test a custom user-agent string as an example
138
- 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";
139
- parser.setUA(uastring);
140
-
141
- var result = parser.getResult();
142
- // this will also produce the same result (without instantiation):
143
- // var result = UAParser(uastring);
144
-
145
- console.log(result.browser); // {name: "Chromium", version: "15.0.874.106"}
146
- console.log(result.device); // {model: undefined, type: undefined, vendor: undefined}
147
- console.log(result.os); // {name: "Ubuntu", version: "11.10"}
148
- console.log(result.os.version); // "11.10"
149
- console.log(result.engine.name); // "WebKit"
150
- console.log(result.cpu.architecture); // "amd64"
151
-
152
- // do some other tests
153
- var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)";
154
- console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror"
155
- console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
156
- console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"}
157
-
158
- 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';
159
- console.log(parser.setUA(uastring3).getDevice().model); // "PlayBook"
160
- console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
161
- console.log(parser.getBrowser().name); // "Safari"
162
-
163
- </script>
164
- </head>
165
- <body>
166
- </body>
167
- </html>
168
- ```
169
-
170
- ### Using node.js
171
-
172
- ```sh
173
- $ npm install ua-parser-js
174
- ```
175
-
176
- ```js
177
- var http = require('http');
178
- var parser = require('ua-parser-js');
179
-
180
- http.createServer(function (req, res) {
181
- // get user-agent header
182
- var ua = parser(req.headers['user-agent']);
183
- // write the result as response
184
- res.end(JSON.stringify(ua, null, ' '));
185
- })
186
- .listen(1337, '127.0.0.1');
187
-
188
- console.log('Server running at http://127.0.0.1:1337/');
189
- ```
190
-
191
- ### Using requirejs
192
-
193
- ```js
194
- require(['ua-parser'], function(UAParser) {
195
- var parser = new UAParser();
196
- console.log(parser.getResult());
197
- });
198
- ```
199
-
200
- ### Using component
201
-
202
- ```sh
203
- $ component install faisalman/ua-parser-js
204
- ```
205
-
206
- ### Using bower
207
-
208
- ```sh
209
- $ bower install ua-parser-js
210
- ```
211
-
212
- ### Using meteor
213
-
214
- ```sh
215
- $ meteor add faisalman:ua-parser-js
216
- ```
217
-
218
- ### Using jQuery/Zepto ($.ua)
219
-
220
- 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)`.
221
-
222
- ```js
223
- // 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':
224
-
225
- // Do some tests
226
- console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
227
- console.log($.ua.os); // {name: "Android", version: "2.3.4"}
228
- console.log($.ua.os.name); // "Android"
229
- 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"
230
-
231
- // reset to custom user-agent
232
- $.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');
233
-
234
- // Test again
235
- console.log($.ua.browser.name); // "Safari"
236
- console.log($.ua.engine.name); // "Webkit"
237
- console.log($.ua.device); // {vendor: "Motorola", model: "Xoom", type: "tablet"}
238
- console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
239
- ```
240
-
241
- ### Extending regex patterns
242
-
243
- * `UAParser(uastring[, extensions])`
244
-
245
- Pass your own regexes to extend the limited matching rules.
246
-
247
- ```js
248
- // Example:
249
- var uaString = 'ownbrowser/1.3';
250
- var ownBrowser = [[/(ownbrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]];
251
- var parser = new UAParser(uaString, {browser: ownBrowser});
252
- console.log(parser.getBrowser()); // {name: "ownbrowser", version: "1.3"}
253
- ```
254
-
255
- ## Development
256
-
257
- Verify, test, & minify script
258
-
259
- ```sh
260
- $ npm run test
261
- $ npm run build
262
- ```
263
-
264
- Then submit a pull request to https://github.com/faisalman/ua-parser-js under `develop` branch.
265
-
266
-
267
- ## License
268
-
269
- Dual licensed under GPLv2 & MIT
270
-
271
- Copyright © 2012-2015 Faisal Salman <<fyzlman@gmail.com>>
272
-
273
- Permission is hereby granted, free of charge, to any person obtaining a copy of
274
- this software and associated documentation files (the "Software"), to deal in
275
- the Software without restriction, including without limitation the rights to use,
276
- copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
277
- Software, and to permit persons to whom the Software is furnished to do so,
278
- subject to the following conditions:
279
-
280
- The above copyright notice and this permission notice shall be included in all
281
- copies or substantial portions of the Software.
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 (~11KB when minified / ~4KB 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 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
+ [![Gratipay](https://img.shields.io/gratipay/team/UAParser.js.svg)](https://gratipay.com/UAParser.js)
11
+ [![Flattr this](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/3867907/faisalmanua-parser-js-on-GitHub)
12
+
13
+ * Author : Faisal Salman <<f@faisalman.com>>
14
+ * Demo : http://faisalman.github.io/ua-parser-js
15
+ * Source : https://github.com/faisalman/ua-parser-js
16
+
17
+ # Constructor
18
+
19
+ * `new UAParser([uastring][,extensions])`
20
+ * returns new instance
21
+
22
+ * `UAParser([uastring][,extensions])`
23
+ * returns result object `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
24
+
25
+ # Methods
26
+
27
+ * `getBrowser()`
28
+ * returns `{ name: '', version: '' }`
29
+
30
+ ```
31
+ # Possible 'browser.name':
32
+ Amaya, Android Browser, Arora, Avant, Baidu, Blazer, Bolt, Bowser, Camino, Chimera,
33
+ Chrome [WebView], Chromium, Comodo Dragon, Conkeror, Dillo, Dolphin, Doris, Edge,
34
+ Epiphany, Fennec, Firebird, Firefox, Flock, GoBrowser, iCab, ICE Browser, IceApe,
35
+ IceCat, IceDragon, Iceweasel, IE[Mobile], Iron, Jasmine, K-Meleon, Konqueror, Kindle,
36
+ Links, Lunascape, Lynx, Maemo, Maxthon, Midori, Minimo, MIUI Browser, [Mobile] Safari,
37
+ Mosaic, Mozilla, Netfront, Netscape, NetSurf, Nokia, OmniWeb, Opera [Mini/Mobi/Tablet],
38
+ PhantomJS, Phoenix, Polaris, QQBrowser, RockMelt, Silk, Skyfire, SeaMonkey, Sleipnir,
39
+ SlimBrowser, Swiftfox, Tizen, UCBrowser, Vivaldi, w3m, WeChat, Yandex
40
+
41
+ # 'browser.version' determined dynamically
42
+ ```
43
+
44
+ * `getDevice()`
45
+ * returns `{ model: '', type: '', vendor: '' }`
46
+
47
+ ```
48
+ # Possible 'device.type':
49
+ console, mobile, tablet, smarttv, wearable, embedded
50
+
51
+ # Possible 'device.vendor':
52
+ Acer, Alcatel, Amazon, Apple, Archos, Asus, BenQ, BlackBerry, Dell, GeeksPhone,
53
+ Google, HP, HTC, Huawei, Jolla, Lenovo, LG, Meizu, Microsoft, Motorola, Nexian,
54
+ Nintendo, Nokia, Nvidia, OnePlus, Ouya, Palm, Panasonic, Pebble, Polytron, RIM,
55
+ Samsung, Sharp, Siemens, Sony[Ericsson], Sprint, Xbox, Xiaomi, ZTE
56
+
57
+ # 'device.model' determined dynamically
58
+ ```
59
+
60
+ * `getEngine()`
61
+ * returns `{ name: '', version: '' }`
62
+
63
+ ```
64
+ # Possible 'engine.name'
65
+ Amaya, EdgeHTML, Gecko, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto,
66
+ Tasman, Trident, w3m, WebKit
67
+
68
+ # 'engine.version' determined dynamically
69
+ ```
70
+
71
+ * `getOS()`
72
+ * returns `{ name: '', version: '' }`
73
+
74
+ ```
75
+ # Possible 'os.name'
76
+ AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS, Contiki,
77
+ Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Gentoo, GNU, Haiku, Hurd, iOS,
78
+ Joli, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo, Minix, Mint, Morph OS, NetBSD,
79
+ Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD, PCLinuxOS, Plan9, Playstation, QNX, RedHat,
80
+ RIM Tablet OS, RISC OS, Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen,
81
+ Ubuntu, UNIX, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk
82
+
83
+ # 'os.version' determined dynamically
84
+ ```
85
+
86
+ * `getCPU()`
87
+ * returns `{ architecture: '' }`
88
+
89
+ ```
90
+ # Possible 'cpu.architecture'
91
+ 68k, amd64, arm[64], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]
92
+ ```
93
+
94
+ * `getResult()`
95
+ * returns `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
96
+
97
+ * `getUA()`
98
+ * returns UA string of current instance
99
+
100
+ * `setUA(uastring)`
101
+ * set UA string to parse
102
+ * returns current instance
103
+
104
+
105
+ # Example
106
+
107
+ ```html
108
+ <!doctype html>
109
+ <html>
110
+ <head>
111
+ <script type="text/javascript" src="ua-parser.min.js"></script>
112
+ <script type="text/javascript">
113
+
114
+ var parser = new UAParser();
115
+
116
+ // by default it takes ua string from current browser's window.navigator.userAgent
117
+ console.log(parser.getResult());
118
+ /*
119
+ /// this will print an object structured like this:
120
+ {
121
+ ua: "",
122
+ browser: {
123
+ name: "",
124
+ version: ""
125
+ },
126
+ engine: {
127
+ name: "",
128
+ version: ""
129
+ },
130
+ os: {
131
+ name: "",
132
+ version: ""
133
+ },
134
+ device: {
135
+ model: "",
136
+ type: "",
137
+ vendor: ""
138
+ },
139
+ cpu: {
140
+ architecture: ""
141
+ }
142
+ }
143
+ */
144
+
145
+ // let's test a custom user-agent string as an example
146
+ 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";
147
+ parser.setUA(uastring);
148
+
149
+ var result = parser.getResult();
150
+ // this will also produce the same result (without instantiation):
151
+ // var result = UAParser(uastring);
152
+
153
+ console.log(result.browser); // {name: "Chromium", version: "15.0.874.106"}
154
+ console.log(result.device); // {model: undefined, type: undefined, vendor: undefined}
155
+ console.log(result.os); // {name: "Ubuntu", version: "11.10"}
156
+ console.log(result.os.version); // "11.10"
157
+ console.log(result.engine.name); // "WebKit"
158
+ console.log(result.cpu.architecture); // "amd64"
159
+
160
+ // do some other tests
161
+ var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)";
162
+ console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror"
163
+ console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
164
+ console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"}
165
+
166
+ 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';
167
+ console.log(parser.setUA(uastring3).getDevice().model); // "PlayBook"
168
+ console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
169
+ console.log(parser.getBrowser().name); // "Safari"
170
+
171
+ </script>
172
+ </head>
173
+ <body>
174
+ </body>
175
+ </html>
176
+ ```
177
+
178
+ ## Using node.js
179
+
180
+ ```sh
181
+ $ npm install ua-parser-js
182
+ ```
183
+
184
+ ```js
185
+ var http = require('http');
186
+ var parser = require('ua-parser-js');
187
+
188
+ http.createServer(function (req, res) {
189
+ // get user-agent header
190
+ var ua = parser(req.headers['user-agent']);
191
+ // write the result as response
192
+ res.end(JSON.stringify(ua, null, ' '));
193
+ })
194
+ .listen(1337, '127.0.0.1');
195
+
196
+ console.log('Server running at http://127.0.0.1:1337/');
197
+ ```
198
+
199
+ ## Using requirejs
200
+
201
+ ```js
202
+ requirejs.config({
203
+ baseUrl : 'js/lib', // path to your script directory
204
+ paths : {
205
+ 'ua-parser-js' : 'ua-parser.min'
206
+ }
207
+ });
208
+
209
+ requirejs(['ua-parser-js'], function(UAParser) {
210
+ var parser = new UAParser();
211
+ console.log(parser.getResult());
212
+ });
213
+ ```
214
+
215
+ ## Using bower
216
+
217
+ ```sh
218
+ $ bower install ua-parser-js
219
+ ```
220
+
221
+ ## Using meteor
222
+
223
+ ```sh
224
+ $ meteor add faisalman:ua-parser-js
225
+ ```
226
+
227
+ ## Using jQuery/Zepto ($.ua)
228
+
229
+ 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)`.
230
+
231
+ ```js
232
+ // 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':
233
+
234
+ // Do some tests
235
+ console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
236
+ console.log($.ua.os); // {name: "Android", version: "2.3.4"}
237
+ console.log($.ua.os.name); // "Android"
238
+ 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"
239
+
240
+ // reset to custom user-agent
241
+ $.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');
242
+
243
+ // Test again
244
+ console.log($.ua.browser.name); // "Safari"
245
+ console.log($.ua.engine.name); // "Webkit"
246
+ console.log($.ua.device); // {vendor: "Motorola", model: "Xoom", type: "tablet"}
247
+ console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
248
+
249
+ // Add class to <body> tag
250
+ // <body class="ua-browser-safari ua-devicetype-tablet">
251
+ $('body').addClass('ua-browser-' + $.ua.browser.name + ' ua-devicetype-' + $.ua.device.type);
252
+ ```
253
+
254
+ ## Extending regex patterns
255
+
256
+ * `UAParser([uastring,] extensions)`
257
+
258
+ Pass your own regexes to extend the limited matching rules.
259
+
260
+ ```js
261
+ // Example:
262
+ var myOwnRegex = [[/(myownbrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]];
263
+ var myParser = new UAParser({ browser: myOwnRegex });
264
+ var uaString = 'Mozilla/5.0 MyOwnBrowser/1.3';
265
+ console.log(myParser.setUA(uaString).getBrowser()); // {name: "MyOwnBrowser", version: "1.3"}
266
+ ```
267
+
268
+
269
+ # Development
270
+
271
+ ## Contribute
272
+
273
+ * Fork and clone this repository
274
+ * Make some changes as required
275
+ * Write a unit test to showcase your feature
276
+ * Run the test suites to make sure the changes you made didn't break anything `$ npm run test`
277
+ * Commit and push to your own repository
278
+ * Submit a pull request to this repository under `develop` branch
279
+ * Profit? $$$
280
+
281
+ ## Build
282
+
283
+ Build a minified & packed script
284
+
285
+ ```sh
286
+ $ npm run build
287
+ ```
288
+
289
+
290
+ # Donate
291
+
292
+ 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 :)
293
+
294
+ [![Support via Pledgie](https://pledgie.com/campaigns/34252.png?skin_name=chrome)](https://pledgie.com/campaigns/34252)
295
+
296
+
297
+ # License
298
+
299
+ Dual licensed under GPLv2 & MIT
300
+
301
+ Copyright © 2012-2016 Faisal Salman <<fyzlman@gmail.com>>
302
+
303
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
304
+ this software and associated documentation files (the "Software"), to deal in
305
+ the Software without restriction, including without limitation the rights to use,
306
+ copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
307
+ Software, and to permit persons to whom the Software is furnished to do so,
308
+ subject to the following conditions:
309
+
310
+ The above copyright notice and this permission notice shall be included in all
311
+ copies or substantial portions of the Software.