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/.npmignore +24 -24
- package/.travis.yml +13 -13
- package/bower.json +17 -43
- package/dist/ua-parser.html +1 -0
- package/dist/ua-parser.min.js +9 -8
- package/dist/ua-parser.pack.js +9 -8
- package/package.js +12 -11
- package/package.json +121 -91
- package/readme.md +311 -281
- package/src/ua-parser.js +1033 -881
- package/test/browser-test.json +962 -752
- package/test/cpu-test.json +106 -106
- package/test/device-test.json +927 -272
- package/test/engine-test.json +74 -74
- package/test/mediaplayer-test.json +582 -0
- package/test/os-test.json +641 -614
- package/test/test.js +98 -74
- package/component.json +0 -24
- package/test/browser&mediaplayer-test.json +0 -1232
- package/ua-parser-js.jquery.json +0 -32
package/readme.md
CHANGED
@@ -1,281 +1,311 @@
|
|
1
|
-
# UAParser.js
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
[](https://travis-ci.org/faisalman/ua-parser-js)
|
6
|
-
[](https://travis-ci.org/faisalman/ua-parser-js)
|
6
|
+
[](https://www.npmjs.com/package/ua-parser-js)
|
7
|
+
[](https://www.npmjs.com/package/ua-parser-js)
|
8
|
+
[](https://bower.io/)
|
9
|
+
[](https://cdnjs.com/libraries/UAParser.js)
|
10
|
+
[](https://gratipay.com/UAParser.js)
|
11
|
+
[](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
|
+
[](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.
|