ua-parser-js 0.7.17 → 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/.github/FUNDING.yml +12 -0
- package/.github/workflows/run-test.yml +17 -0
- package/.jshintrc +3 -0
- package/.travis.yml +6 -1
- package/bower.json +2 -2
- package/changelog.md +3 -0
- package/dist/ua-parser.min.js +4 -9
- package/dist/ua-parser.pack.js +4 -9
- package/license.md +21 -0
- package/package.js +1 -1
- package/package.json +92 -15
- package/readme.md +115 -136
- package/security.md +5 -0
- package/src/ua-parser.js +566 -764
- package/test/browser-test.json +489 -4
- package/test/cpu-test.json +105 -1
- package/test/device-test.json +2335 -230
- package/test/engine-test.json +81 -0
- package/test/os-test.json +628 -151
- package/test/test.js +66 -11
- package/.npmignore +0 -24
package/readme.md
CHANGED
@@ -1,20 +1,26 @@
|
|
1
|
-
|
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
|
-
|
13
|
+
# UAParser.js
|
4
14
|
|
5
|
-
|
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)
|
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).
|
12
16
|
|
13
17
|
* Author : Faisal Salman <<f@faisalman.com>>
|
14
|
-
* Demo :
|
18
|
+
* Demo : https://faisalman.github.io/ua-parser-js
|
15
19
|
* Source : https://github.com/faisalman/ua-parser-js
|
16
20
|
|
17
|
-
#
|
21
|
+
# Documentation
|
22
|
+
|
23
|
+
## Constructor
|
18
24
|
|
19
25
|
* `new UAParser([uastring][,extensions])`
|
20
26
|
* returns new instance
|
@@ -22,37 +28,44 @@
|
|
22
28
|
* `UAParser([uastring][,extensions])`
|
23
29
|
* returns result object `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
|
24
30
|
|
25
|
-
|
31
|
+
## Methods
|
26
32
|
|
27
33
|
* `getBrowser()`
|
28
34
|
* returns `{ name: '', version: '' }`
|
29
35
|
|
30
|
-
```
|
36
|
+
```sh
|
31
37
|
# Possible 'browser.name':
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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...
|
40
52
|
|
41
53
|
# 'browser.version' determined dynamically
|
42
54
|
```
|
43
55
|
|
44
56
|
* `getDevice()`
|
45
|
-
* returns `{ model: '', type: '', vendor: '' }`
|
57
|
+
* returns `{ model: '', type: '', vendor: '' }`
|
46
58
|
|
47
|
-
```
|
59
|
+
```sh
|
48
60
|
# Possible 'device.type':
|
49
61
|
console, mobile, tablet, smarttv, wearable, embedded
|
50
62
|
|
51
63
|
# Possible 'device.vendor':
|
52
|
-
Acer, Alcatel, Amazon, Apple, Archos,
|
53
|
-
Google, HP, HTC, Huawei, Jolla, Lenovo, LG,
|
54
|
-
|
55
|
-
|
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, ...
|
56
69
|
|
57
70
|
# 'device.model' determined dynamically
|
58
71
|
```
|
@@ -60,10 +73,10 @@ Samsung, Sharp, Siemens, Sony[Ericsson], Sprint, Xbox, Xiaomi, ZTE
|
|
60
73
|
* `getEngine()`
|
61
74
|
* returns `{ name: '', version: '' }`
|
62
75
|
|
63
|
-
```
|
76
|
+
```sh
|
64
77
|
# Possible 'engine.name'
|
65
|
-
Amaya, EdgeHTML, Gecko, iCab, KHTML, Links, Lynx, NetFront,
|
66
|
-
Tasman, Trident, w3m, WebKit
|
78
|
+
Amaya, Blink, EdgeHTML, Flow, Gecko, Goanna, iCab, KHTML, Links, Lynx, NetFront,
|
79
|
+
NetSurf, Presto, Tasman, Trident, w3m, WebKit
|
67
80
|
|
68
81
|
# 'engine.version' determined dynamically
|
69
82
|
```
|
@@ -71,14 +84,15 @@ Tasman, Trident, w3m, WebKit
|
|
71
84
|
* `getOS()`
|
72
85
|
* returns `{ name: '', version: '' }`
|
73
86
|
|
74
|
-
```
|
87
|
+
```sh
|
75
88
|
# Possible 'os.name'
|
76
|
-
AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,
|
77
|
-
Fedora, Firefox OS, FreeBSD, Debian,
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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, ...
|
82
96
|
|
83
97
|
# 'os.version' determined dynamically
|
84
98
|
```
|
@@ -86,9 +100,9 @@ Ubuntu, UNIX, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk
|
|
86
100
|
* `getCPU()`
|
87
101
|
* returns `{ architecture: '' }`
|
88
102
|
|
89
|
-
```
|
103
|
+
```sh
|
90
104
|
# Possible 'cpu.architecture'
|
91
|
-
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]
|
92
106
|
```
|
93
107
|
|
94
108
|
* `getResult()`
|
@@ -98,30 +112,30 @@ Ubuntu, UNIX, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk
|
|
98
112
|
* returns UA string of current instance
|
99
113
|
|
100
114
|
* `setUA(uastring)`
|
101
|
-
* set UA string to
|
115
|
+
* set UA string to be parsed
|
102
116
|
* returns current instance
|
103
117
|
|
118
|
+
# Usage
|
104
119
|
|
105
|
-
|
120
|
+
## Using HTML
|
106
121
|
|
107
122
|
```html
|
108
123
|
<!doctype html>
|
109
124
|
<html>
|
110
125
|
<head>
|
111
|
-
<script
|
112
|
-
<script
|
113
|
-
|
114
|
-
var parser = new UAParser();
|
126
|
+
<script src="ua-parser.min.js"></script>
|
127
|
+
<script>
|
115
128
|
|
116
|
-
|
129
|
+
var parser = new UAParser();
|
117
130
|
console.log(parser.getResult());
|
118
131
|
/*
|
119
|
-
///
|
132
|
+
/// This will print an object structured like this:
|
120
133
|
{
|
121
134
|
ua: "",
|
122
135
|
browser: {
|
123
136
|
name: "",
|
124
|
-
version: ""
|
137
|
+
version: "",
|
138
|
+
major: "" //@deprecated
|
125
139
|
},
|
126
140
|
engine: {
|
127
141
|
name: "",
|
@@ -141,14 +155,14 @@ Ubuntu, UNIX, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk
|
|
141
155
|
}
|
142
156
|
}
|
143
157
|
*/
|
158
|
+
// Default result depends on current window.navigator.userAgent value
|
144
159
|
|
145
|
-
// let's
|
146
|
-
var
|
147
|
-
parser.setUA(
|
148
|
-
|
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);
|
149
163
|
var result = parser.getResult();
|
150
|
-
//
|
151
|
-
// var result = UAParser(
|
164
|
+
// You can also use UAParser constructor directly without having to create an instance:
|
165
|
+
// var result = UAParser(uastring1);
|
152
166
|
|
153
167
|
console.log(result.browser); // {name: "Chromium", version: "15.0.874.106"}
|
154
168
|
console.log(result.device); // {model: undefined, type: undefined, vendor: undefined}
|
@@ -157,7 +171,7 @@ Ubuntu, UNIX, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk
|
|
157
171
|
console.log(result.engine.name); // "WebKit"
|
158
172
|
console.log(result.cpu.architecture); // "amd64"
|
159
173
|
|
160
|
-
//
|
174
|
+
// Do some other tests
|
161
175
|
var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)";
|
162
176
|
console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror"
|
163
177
|
console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
|
@@ -196,66 +210,28 @@ http.createServer(function (req, res) {
|
|
196
210
|
console.log('Server running at http://127.0.0.1:1337/');
|
197
211
|
```
|
198
212
|
|
199
|
-
## Using
|
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 CDN
|
216
|
-
|
217
|
-
```html
|
218
|
-
<script src="https://cdn.jsdelivr.net/npm/ua-parser-js@0/dist/ua-parser.min.js"></script>
|
219
|
-
```
|
220
|
-
|
221
|
-
## Using bower
|
222
|
-
|
223
|
-
```sh
|
224
|
-
$ bower install ua-parser-js
|
225
|
-
```
|
226
|
-
|
227
|
-
## Using meteor
|
228
|
-
|
229
|
-
```sh
|
230
|
-
$ meteor add faisalman:ua-parser-js
|
231
|
-
```
|
232
|
-
|
233
|
-
## Using CLI
|
213
|
+
## Using TypeScript
|
234
214
|
|
235
215
|
```sh
|
236
|
-
$
|
237
|
-
#
|
238
|
-
|
239
|
-
# piped args
|
240
|
-
$ echo "Opera/1.2" | node ua-parser.min.js
|
241
|
-
# log file
|
242
|
-
$ cat ua.log | node ua-parser.min.js
|
216
|
+
$ npm install --save @types/ua-parser-js
|
217
|
+
# Download TS type definition from DefinitelyTyped repository:
|
218
|
+
# https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/ua-parser-js
|
243
219
|
```
|
244
220
|
|
245
221
|
## Using jQuery/Zepto ($.ua)
|
246
222
|
|
247
|
-
Although written in vanilla js
|
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)`.
|
248
224
|
|
249
225
|
```js
|
250
|
-
//
|
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':
|
251
227
|
|
252
|
-
//
|
228
|
+
// Get the details
|
253
229
|
console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
|
254
230
|
console.log($.ua.os); // {name: "Android", version: "2.3.4"}
|
255
231
|
console.log($.ua.os.name); // "Android"
|
256
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"
|
257
233
|
|
258
|
-
// reset to custom user-agent
|
234
|
+
// Now lets try to reset to another custom user-agent
|
259
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');
|
260
236
|
|
261
237
|
// Test again
|
@@ -269,61 +245,64 @@ console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
|
|
269
245
|
$('body').addClass('ua-browser-' + $.ua.browser.name + ' ua-devicetype-' + $.ua.device.type);
|
270
246
|
```
|
271
247
|
|
272
|
-
##
|
248
|
+
## Using Extension
|
273
249
|
|
274
250
|
* `UAParser([uastring,] extensions)`
|
275
251
|
|
276
|
-
Pass your own regexes to extend the limited matching rules.
|
277
|
-
|
278
252
|
```js
|
279
253
|
// Example:
|
280
|
-
var
|
281
|
-
|
282
|
-
|
283
|
-
|
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"}
|
284
260
|
```
|
285
261
|
|
286
|
-
|
287
262
|
# Development
|
288
263
|
|
289
|
-
##
|
264
|
+
## Sponsors
|
290
265
|
|
291
|
-
|
292
|
-
* Make some changes as required
|
293
|
-
* Write a unit test to showcase your feature
|
294
|
-
* Run the test suites to make sure the changes you made didn't break anything `$ npm run test`
|
295
|
-
* Commit and push to your own repository
|
296
|
-
* Submit a pull request to this repository under `develop` branch
|
297
|
-
* Profit? $$$
|
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>
|
298
267
|
|
299
|
-
|
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>
|
300
269
|
|
301
|
-
|
270
|
+
## Contributors
|
302
271
|
|
303
|
-
|
304
|
-
|
305
|
-
|
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>
|
306
275
|
|
276
|
+
Made with [contributors-img](https://contrib.rocks).
|
307
277
|
|
308
|
-
|
309
|
-
|
310
|
-
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 :)
|
311
|
-
|
312
|
-
[](https://pledgie.com/campaigns/34252)
|
278
|
+
## How To Contribute
|
313
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
|
314
285
|
|
315
286
|
# License
|
316
287
|
|
317
|
-
|
288
|
+
MIT License
|
318
289
|
|
319
|
-
Copyright
|
290
|
+
Copyright (c) 2012-2021 Faisal Salman <<f@faisalman.com>>
|
320
291
|
|
321
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
322
|
-
this software and associated documentation files (the "Software"), to deal
|
323
|
-
the Software without restriction, including without limitation the rights
|
324
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
325
|
-
Software, and to permit persons to whom the Software is
|
326
|
-
subject to the following conditions:
|
292
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
293
|
+
of this software and associated documentation files (the "Software"), to deal
|
294
|
+
in the Software without restriction, including without limitation the rights
|
295
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
296
|
+
copies of the Software, and to permit persons to whom the Software is
|
297
|
+
furnished to do so, subject to the following conditions:
|
327
298
|
|
328
|
-
The above copyright notice and this permission notice shall be included in all
|
299
|
+
The above copyright notice and this permission notice shall be included in all
|
329
300
|
copies or substantial portions of the Software.
|
301
|
+
|
302
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
303
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
304
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
305
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
306
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
307
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
308
|
+
SOFTWARE.
|