mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-15 22:52:16 +03:00
Compare commits
77 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc47b6a1e9 | ||
|
|
84a8eedad4 | ||
|
|
30e1e7a98f | ||
|
|
c1df106dca | ||
|
|
edcd5402a6 | ||
|
|
4f2ee98dae | ||
|
|
ce8f4977c0 | ||
|
|
38f62b3d63 | ||
|
|
d5d329e15d | ||
|
|
e89e8173f5 | ||
|
|
e58c93fe0a | ||
|
|
8c36f005a5 | ||
|
|
5717b00343 | ||
|
|
4ebe7a1899 | ||
|
|
b7d76f5df0 | ||
|
|
acfce61942 | ||
|
|
d75f84820a | ||
|
|
007f74178f | ||
|
|
d063e532e3 | ||
|
|
f3f25ae3e7 | ||
|
|
45571b6f21 | ||
|
|
615d6a2034 | ||
|
|
40ac5c5bc3 | ||
|
|
3eb1c1c352 | ||
|
|
217cef226a | ||
|
|
a5e4b7bf72 | ||
|
|
8aaf7db771 | ||
|
|
0109c76858 | ||
|
|
d1120a4d5d | ||
|
|
204345a8bf | ||
|
|
a20d8f7052 | ||
|
|
9a90d932ce | ||
|
|
cea29e5c1b | ||
|
|
e0b6ae65e5 | ||
|
|
59714adea3 | ||
|
|
249dcf0c80 | ||
|
|
b99546072d | ||
|
|
4e911cec88 | ||
|
|
f1fa7f38a1 | ||
|
|
a6610646ca | ||
|
|
4703137b79 | ||
|
|
541dfea86d | ||
|
|
35b410009f | ||
|
|
5e84ab7b82 | ||
|
|
816b5d22b4 | ||
|
|
29bb0797a6 | ||
|
|
52897acf24 | ||
|
|
9ccc32ce5a | ||
|
|
4a65f1b3f8 | ||
|
|
be4d8a10d1 | ||
|
|
6d183003b3 | ||
|
|
a2b4f6d5c5 | ||
|
|
3f98036d50 | ||
|
|
d1d4e0a7a0 | ||
|
|
3ecb3fbea2 | ||
|
|
5cc6bf78a5 | ||
|
|
08c7a84407 | ||
|
|
ea9d093f0d | ||
|
|
1f4befe4c3 | ||
|
|
d35fb44066 | ||
|
|
9a6479193a | ||
|
|
527ba70cf4 | ||
|
|
3fe07487cd | ||
|
|
8030aa33f7 | ||
|
|
99251addfc | ||
|
|
610cdb84ae | ||
|
|
31b386c636 | ||
|
|
b15b48b1bf | ||
|
|
58fe246468 | ||
|
|
e1d3f25bf8 | ||
|
|
4efb13be3e | ||
|
|
bf9fb794d8 | ||
|
|
df815d4109 | ||
|
|
6dcee61a0b | ||
|
|
0288766544 | ||
|
|
7ea79afc2f | ||
|
|
59270c8cf7 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
6
.travis.yml
Normal file
6
.travis.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.8
|
||||
- 0.6
|
||||
notifications:
|
||||
email: false
|
||||
37
build/build.sh
Executable file
37
build/build.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
# dependencies
|
||||
JSHINT_DIR="node_modules/jshint/bin/jshint"
|
||||
MOCHA_DIR="node_modules/mocha/bin/mocha"
|
||||
UGLIFY_DIR="node_modules/uglify-js/bin/uglifyjs"
|
||||
|
||||
# check module directory & install if not found
|
||||
function check_module {
|
||||
if ! type $2 &> /dev/null
|
||||
then
|
||||
echo "$2 is not found"
|
||||
if ! type "npm" &> /dev/null
|
||||
then
|
||||
echo "npm is not installed"
|
||||
echo "Exiting"
|
||||
exit 1
|
||||
else
|
||||
echo "Installing $1..."
|
||||
npm install $1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
check_module "jshint" $JSHINT_DIR
|
||||
check_module "mocha" $MOCHA_DIR
|
||||
check_module "uglify-js" $UGLIFY_DIR
|
||||
|
||||
echo "Verifiying code..."
|
||||
$JSHINT_DIR src/ua-parser.js
|
||||
|
||||
echo "Running test..."
|
||||
$MOCHA_DIR -R nyan test/test.js
|
||||
|
||||
echo "Minifying script..."
|
||||
$UGLIFY_DIR src/ua-parser.js > src/ua-parser.min.js
|
||||
echo "OK"
|
||||
14
component.json
Normal file
14
component.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.5.27",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": ["user-agent", "parser", "browser", "engine", "os", "device"],
|
||||
"scripts": ["src/ua-parser.js"],
|
||||
"main": "src/ua-parser.js",
|
||||
"license": "MIT",
|
||||
"development": {
|
||||
"jshint/jshint": "*",
|
||||
"visionmedia/mocha": "*",
|
||||
"mishoo/uglifyjs2": "*"
|
||||
}
|
||||
}
|
||||
25
package.json
25
package.json
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"title": "UA-Parser.JS",
|
||||
"title": "UAParser.js",
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.4.3",
|
||||
"version": "0.5.27",
|
||||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
"user agent",
|
||||
"user-agent",
|
||||
"parser",
|
||||
"browser",
|
||||
"engine",
|
||||
@@ -14,9 +14,21 @@
|
||||
],
|
||||
"homepage": "http://github.com/faisalman/ua-parser-js",
|
||||
"contributors": [
|
||||
"Faisal Salman <fyzlman@gmail.com>"
|
||||
"Faisal Salman <fyzlman@gmail.com>",
|
||||
"Christopher De Cairos <chris.decairos@gmail.com>",
|
||||
"John Tantalo <john.tantalo@gmail.com>",
|
||||
"Jon Buckley <jon@jbuckley.ca>",
|
||||
"Lee Treveil <leetreveil@gmail.com>"
|
||||
],
|
||||
"main": "ua-parser",
|
||||
"main": "src/ua-parser.js",
|
||||
"scripts": {
|
||||
"test": "./build/build.sh"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jshint": ">= 1.1.0",
|
||||
"mocha": ">= 1.7.1",
|
||||
"uglify-js": ">= 1.3.4"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "git",
|
||||
@@ -42,7 +54,8 @@
|
||||
"node": "*"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "."
|
||||
"lib": "src",
|
||||
"test": "test"
|
||||
},
|
||||
"files": [
|
||||
""
|
||||
|
||||
190
readme.md
190
readme.md
@@ -1,30 +1,92 @@
|
||||
# UA-Parser.JS
|
||||
# UAParser.js
|
||||
|
||||
Lightweight JavaScript-based User-Agent string parser
|
||||
Lightweight JavaScript-based User-Agent string parser. Supports browser & node.js environment. Also available as Component package, Bower package, jQuery.ua, & AMD module
|
||||
|
||||
[](https://travis-ci.org/faisalman/ua-parser-js)
|
||||
|
||||
* Author : Faisalman <<fyzlman@gmail.com>>
|
||||
* Home : http://faisalman.github.com/ua-parser-js
|
||||
* Demo : http://faisalman.github.com/ua-parser-js
|
||||
* Source : https://github.com/faisalman/ua-parser-js
|
||||
* License : GPLv2 & MIT
|
||||
|
||||
## Features
|
||||
|
||||
Extract detailed type of web browser, layout engine, operating system, and device purely from user-agent string.
|
||||
Extract detailed type of web browser, layout engine, operating system, and device purely from user-agent string with relatively lightweight footprint (~7KB minified / ~3KB gzipped). Written in vanilla js, which means it doesn't depends on any other library.
|
||||
|
||||

|
||||
|
||||
## Methods
|
||||
|
||||
* `getBrowser()`
|
||||
* returns `{ name: '', major: '', version: '' }`
|
||||
|
||||
```
|
||||
# Possible 'browser.name':
|
||||
Amaya, Arora, Avant, Baidu, Blazer, Bolt, Camino, Chimera, Chrome, Chromium,
|
||||
Comodo Dragon, Conkeror, Dillo, Dolphin, Doris, Epiphany, Fennec, Firebird,
|
||||
Firefox, Flock, GoBrowser, iCab, ICE Browser, IceApe, IceCat, Iceweasel,
|
||||
IE [Mobile], Jasmine, K-Meleon, Konqueror, Kindle, Links, Lunascape, Lynx, Maemo,
|
||||
Maxthon, Midori, Minimo, [Mobile] Safari, Mosaic, Mozilla, Netfront, Netscape,
|
||||
NetSurf, Nokia, OmniWeb, Opera [Mini/Mobi/Tablet], Phoenix, Polaris, RockMelt,
|
||||
Silk, Skyfire, SeaMonkey, SlimBrowser, Swiftfox, Tizen, UCBrowser, w3m, Yandex
|
||||
|
||||
# 'browser.version' & 'browser.major' determined dynamically
|
||||
```
|
||||
|
||||
* `getDevice()`
|
||||
* returns `{ model: '', type: '', vendor: '' }`
|
||||
|
||||
```
|
||||
# Possible 'device.type':
|
||||
console, mobile, tablet
|
||||
|
||||
# Possible 'device.vendor':
|
||||
Acer, Alcatel, Apple, Asus, BenQ, BlackBerry, Dell, GeeksPhone, HP, HTC, Huawei,
|
||||
Lenovo, LG, Meizu, Motorola, Nexian, Nintendo, Nokia, Palm, Panasonic,
|
||||
RIM, Samsung, Siemens, Sony-Ericsson, Sprint, ZTE
|
||||
|
||||
# 'device.model' determined dynamically
|
||||
```
|
||||
|
||||
* `getEngine()`
|
||||
* returns `{ name: '', version: '' }`
|
||||
|
||||
```
|
||||
# Possible 'engine.name'
|
||||
Amaya, Gecko, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto, Tasman,
|
||||
Trident, w3m, WebKit
|
||||
|
||||
# 'engine.version' determined dynamically
|
||||
```
|
||||
|
||||
* `getOS()`
|
||||
* returns `{ name: '', version: '' }`
|
||||
|
||||
```
|
||||
# Possible 'os.name'
|
||||
AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,
|
||||
Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Gentoo, GNU, Haiku, Hurd, iOS,
|
||||
Joli, Linux, Mac OS, Mandriva, MeeGo, Minix, Mint, Morph OS, NetBSD, Nintendo,
|
||||
OpenBSD, OS/2, Palm, PCLinuxOS, Plan9, Playstation, QNX, RedHat, RIM Tablet OS,
|
||||
RISC OS, Slackware, Solaris, SUSE, Symbian, Tizen, Ubuntu, UNIX, WebOS,
|
||||
Windows [Phone/Mobile], Zenwalk
|
||||
|
||||
# 'os.version' determined dynamically
|
||||
```
|
||||
|
||||
* `getResult()`
|
||||
* returns `{ browser: {}, device: {}, engine: {}, os: {} }`
|
||||
* `getUA()`
|
||||
* returns UA string of current instance
|
||||
* `setUA(uastring)`
|
||||
* set & parse UA string
|
||||
|
||||
## Example
|
||||
|
||||
```html
|
||||
<script type="text/javascript" src="ua-parser.js"></script>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="ua-parser.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var parser = new UAParser();
|
||||
@@ -56,36 +118,120 @@ Extract detailed type of web browser, layout engine, operating system, and devic
|
||||
*/
|
||||
|
||||
// let's test a custom user-agent string as an example
|
||||
var uastr = "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";
|
||||
parser.setUA(uastr);
|
||||
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";
|
||||
parser.setUA(uastring);
|
||||
|
||||
console.log(parser.getResult().browser); // {name: "Chromium", major: "15", version: "15.0.874.106"}
|
||||
console.log(parser.getResult().device); // {model: undefined, type: undefined, vendor: undefined}
|
||||
console.log(parser.getResult().engine); // {name: "AppleWebKit", version: "535.2"}
|
||||
console.log(parser.getResult().os); // {name: "Ubuntu", version: "11.10"}
|
||||
var result = parser.getResult();
|
||||
// this will also produce the same result (without instantiation):
|
||||
// var result = UAParser(uastring);
|
||||
|
||||
// let's take another test please
|
||||
console.log(parser.setUA("Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)").getBrowser().name); // "Konqueror"
|
||||
console.log(result.browser); // {name: "Chromium", major: "15", version: "15.0.874.106"}
|
||||
console.log(result.device); // {model: undefined, type: undefined, vendor: undefined}
|
||||
console.log(result.os); // {name: "Ubuntu", version: "11.10"}
|
||||
console.log(result.os.version); // "11.10"
|
||||
console.log(result.engine.name); // "WebKit"
|
||||
|
||||
// do some other tests
|
||||
var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)";
|
||||
console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror"
|
||||
console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
|
||||
console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"}
|
||||
|
||||
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';
|
||||
console.log(parser.setUA(uastring3).getDevice().model); // "PlayBook"
|
||||
console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
|
||||
console.log(parser.getBrowser().name); // "Safari"
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
## Using node.js
|
||||
### Using requirejs
|
||||
|
||||
```js
|
||||
var UAParser = require('ua-parser');
|
||||
var parser = new UAParser();
|
||||
var uaString = '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';
|
||||
require(['ua-parser'], function(UAParser) {
|
||||
var parser = new UAParser();
|
||||
console.log(parser.getResult());
|
||||
});
|
||||
```
|
||||
|
||||
console.log(parser.setUA(uaString).getDevice().model); // "PlayBook"
|
||||
console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
|
||||
console.log(parser.getEngine().name); // "AppleWebKit"
|
||||
### Using node.js
|
||||
|
||||
```sh
|
||||
$ npm install ua-parser-js
|
||||
```
|
||||
|
||||
```js
|
||||
var UAParser = require('ua-parser-js');
|
||||
var parser = new UAParser();
|
||||
console.log(parser.getResult());
|
||||
```
|
||||
|
||||
### Using component
|
||||
|
||||
```sh
|
||||
$ component install faisalman/ua-parser-js
|
||||
```
|
||||
|
||||
```js
|
||||
var UAParser = require('ua-parser-js');
|
||||
var parser = new UAParser();
|
||||
console.log(parser.getResult());
|
||||
```
|
||||
|
||||
### Using bower
|
||||
|
||||
```sh
|
||||
$ bower install ua-parser-js
|
||||
```
|
||||
|
||||
### Using jQuery.ua
|
||||
|
||||
Although written in vanilla js (which means it doesn't depends on jQuery), if you're using jQuery, this library will automatically detect 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)`.
|
||||
|
||||
```js
|
||||
// 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':
|
||||
|
||||
// Do some tests
|
||||
console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
|
||||
console.log($.ua.os); // {name: "Android", version: "2.3.4"}
|
||||
console.log($.ua.os.name); // "Android"
|
||||
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"
|
||||
|
||||
// reset to custom user-agent
|
||||
$.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');
|
||||
|
||||
// Test again
|
||||
console.log($.ua.browser.name); // "Safari"
|
||||
console.log($.ua.engine.name); // "Webkit"
|
||||
console.log($.ua.device); // {vendor: "Motorola", model: "Xoom", type: "tablet"}
|
||||
console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
Install dependencies
|
||||
|
||||
```sh
|
||||
$ npm install jshint
|
||||
$ npm install mocha
|
||||
$ npm install uglify-js
|
||||
```
|
||||
|
||||
Verify, test, & minify script
|
||||
|
||||
```sh
|
||||
$ ./build/build.sh
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2012 Faisalman <<fyzlman@gmail.com>>
|
||||
Dual licensed under GPLv2 & MIT
|
||||
|
||||
Copyright © 2012-2013 Faisalman <<fyzlman@gmail.com>>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
|
||||
501
src/ua-parser.js
Normal file
501
src/ua-parser.js
Normal file
@@ -0,0 +1,501 @@
|
||||
// UAParser.js v0.5.27
|
||||
// Lightweight JavaScript-based User-Agent string parser
|
||||
// https://github.com/faisalman/ua-parser-js
|
||||
//
|
||||
// Copyright © 2012-2013 Faisalman <fyzlman@gmail.com>
|
||||
// Dual licensed under GPLv2 & MIT
|
||||
|
||||
(function (window, undefined) {
|
||||
|
||||
'use strict';
|
||||
|
||||
//////////////
|
||||
// Constants
|
||||
/////////////
|
||||
|
||||
|
||||
var EMPTY = '',
|
||||
UNKNOWN = '?',
|
||||
FUNC_TYPE = 'function',
|
||||
UNDEF_TYPE = 'undefined',
|
||||
OBJ_TYPE = 'object',
|
||||
MAJOR = 'major',
|
||||
MODEL = 'model',
|
||||
NAME = 'name',
|
||||
TYPE = 'type',
|
||||
VENDOR = 'vendor',
|
||||
VERSION = 'version',
|
||||
CONSOLE = 'console',
|
||||
MOBILE = 'mobile',
|
||||
TABLET = 'tablet';
|
||||
|
||||
|
||||
///////////
|
||||
// Helper
|
||||
//////////
|
||||
|
||||
|
||||
var util = {
|
||||
has : function (str1, str2) {
|
||||
return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
///////////////
|
||||
// Map helper
|
||||
//////////////
|
||||
|
||||
|
||||
var mapper = {
|
||||
|
||||
rgx : function () {
|
||||
|
||||
// loop through all regexes maps
|
||||
for (var result, i = 0, j, k, p, q, matches, match, args = arguments; i < args.length; i += 2) {
|
||||
|
||||
var regex = args[i], // even sequence (0,2,4,..)
|
||||
props = args[i + 1]; // odd sequence (1,3,5,..)
|
||||
|
||||
// construct object barebones
|
||||
if (typeof(result) === UNDEF_TYPE) {
|
||||
result = {};
|
||||
for (p in props) {
|
||||
q = props[p];
|
||||
if (typeof(q) === OBJ_TYPE) {
|
||||
result[q[0]] = undefined;
|
||||
} else {
|
||||
result[q] = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// try matching uastring with regexes
|
||||
for (j = k = 0; j < regex.length; j++) {
|
||||
matches = regex[j].exec(this.getUA());
|
||||
if (!!matches) {
|
||||
for (p in props) {
|
||||
match = matches[++k];
|
||||
q = props[p];
|
||||
// check if given property is actually array
|
||||
if (typeof(q) === OBJ_TYPE && q.length > 0) {
|
||||
if (q.length == 2) {
|
||||
// assign given value, ignore regex match
|
||||
result[q[0]] = q[1];
|
||||
} else if (q.length == 3) {
|
||||
// check whether function or regex
|
||||
if (typeof(q[1]) === FUNC_TYPE && !(q[1].exec && q[1].test)) {
|
||||
// call function (usually string mapper)
|
||||
result[q[0]] = match ? q[1].call(this, match, q[2]) : undefined;
|
||||
} else {
|
||||
// sanitize match using given regex
|
||||
result[q[0]] = match ? match.replace(q[1], q[2]) : undefined;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result[q] = match ? match : undefined;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!!matches) break; // break the loop immediately if match found
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
str : function (str, map) {
|
||||
|
||||
for (var i in map) {
|
||||
// check if array
|
||||
if (typeof(map[i]) === OBJ_TYPE && map[i].length > 0) {
|
||||
for (var j in map[i]) {
|
||||
if (util.has(map[i][j], str)) {
|
||||
return (i === UNKNOWN) ? undefined : i;
|
||||
}
|
||||
}
|
||||
} else if (util.has(map[i], str)) {
|
||||
return (i === UNKNOWN) ? undefined : i;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
///////////////
|
||||
// String map
|
||||
//////////////
|
||||
|
||||
|
||||
var maps = {
|
||||
|
||||
browser : {
|
||||
oldsafari : {
|
||||
major : {
|
||||
'1' : ['/8', '/1', '/3'],
|
||||
'2' : '/4',
|
||||
'?' : '/'
|
||||
},
|
||||
version : {
|
||||
'1.0' : '/8',
|
||||
'1.2' : '/1',
|
||||
'1.3' : '/3',
|
||||
'2.0' : '/412',
|
||||
'2.0.2' : '/416',
|
||||
'2.0.3' : '/417',
|
||||
'2.0.4' : '/419',
|
||||
'?' : '/'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
device : {
|
||||
sprint : {
|
||||
model : {
|
||||
'Evo Shift 4G' : '7373KT'
|
||||
},
|
||||
vendor : {
|
||||
'HTC' : 'APA',
|
||||
'Sprint' : 'Sprint'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
os : {
|
||||
windows : {
|
||||
version : {
|
||||
'ME' : '4.90',
|
||||
'NT 3.11' : 'NT3.51',
|
||||
'NT 4.0' : 'NT4.0',
|
||||
'2000' : 'NT 5.0',
|
||||
'XP' : ['NT 5.1', 'NT 5.2'],
|
||||
'Vista' : 'NT 6.0',
|
||||
'7' : 'NT 6.1',
|
||||
'8' : 'NT 6.2',
|
||||
'RT' : 'ARM'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//////////////
|
||||
// Regex map
|
||||
/////////////
|
||||
|
||||
|
||||
var regexes = {
|
||||
|
||||
browser : [[
|
||||
|
||||
// Presto based
|
||||
/(opera\smini)\/((\d+)?[\w\.-]+)/i, // Opera Mini
|
||||
/(opera\s[mobiletab]+).+version\/((\d+)?[\w\.-]+)/i, // Opera Mobi/Tablet
|
||||
/(opera).+version\/((\d+)?[\w\.]+)/i, // Opera > 9.80
|
||||
/(opera)[\/\s]+((\d+)?[\w\.]+)/i // Opera < 9.80
|
||||
|
||||
], [NAME, VERSION, MAJOR], [
|
||||
|
||||
/\s(opr)\/((\d+)?[\w\.]+)/i // Opera Webkit
|
||||
], [[NAME, 'Opera'], VERSION, MAJOR], [
|
||||
|
||||
// Mixed
|
||||
/(kindle)\/((\d+)?[\w\.]+)/i, // Kindle
|
||||
/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?((\d+)?[\w\.]+)*/i,
|
||||
// Lunascape/Maxthon/Netfront/Jasmine/Blazer
|
||||
|
||||
// Trident based
|
||||
/(avant\s|iemobile|slim|baidu)(?:browser)?[\/\s]?((\d+)?[\w\.]*)/i,
|
||||
// Avant/IEMobile/SlimBrowser/Baidu
|
||||
/((?:ms|\()ie)\s((\d+)?[\w\.]+)/i, // Internet Explorer
|
||||
|
||||
// Webkit/KHTML based
|
||||
/(rekonq)((?:\/)[\w\.]+)*/i, // Rekonq
|
||||
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt)\/((\d+)?[\w\.-]+)/i
|
||||
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt
|
||||
], [NAME, VERSION, MAJOR], [
|
||||
|
||||
/(yabrowser)\/((\d+)?[\w\.]+)/i // Yandex
|
||||
], [[NAME, 'Yandex'], VERSION, MAJOR], [
|
||||
|
||||
/(comodo_dragon)\/((\d+)?[\w\.]+)/i // Comodo Dragon
|
||||
], [[NAME, /_/g, ' '], VERSION, MAJOR], [
|
||||
|
||||
/(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?((\d+)?[\w\.]+)/i
|
||||
// Chrome/OmniWeb/Arora/Tizen/Nokia
|
||||
], [NAME, VERSION, MAJOR], [
|
||||
|
||||
/(dolfin)\/((\d+)?[\w\.]+)/i // Dolphin
|
||||
], [[NAME, 'Dolphin'], VERSION, MAJOR], [
|
||||
|
||||
/((?:android.+)crmo|crios)\/((\d+)?[\w\.]+)/i // Chrome for Android/iOS
|
||||
], [[NAME, 'Chrome'], VERSION, MAJOR], [
|
||||
|
||||
/version\/((\d+)?[\w\.]+).+?mobile\/\w+\s(safari)/i // Mobile Safari
|
||||
], [VERSION, MAJOR, [NAME, 'Mobile Safari']], [
|
||||
|
||||
/version\/((\d+)?[\w\.]+).+?(mobile\s?safari|safari)/i // Safari & Safari Mobile
|
||||
], [VERSION, MAJOR, NAME], [
|
||||
|
||||
/webkit.+?(mobile\s?safari|safari)((\/[\w\.]+))/i // Safari < 3.0
|
||||
], [NAME, [MAJOR, mapper.str, maps.browser.oldsafari.major], [VERSION, mapper.str, maps.browser.oldsafari.version]], [
|
||||
|
||||
/(konqueror)\/((\d+)?[\w\.]+)/i, // Konqueror
|
||||
/(webkit|khtml)\/((\d+)?[\w\.]+)/i
|
||||
], [NAME, VERSION, MAJOR], [
|
||||
|
||||
// Gecko based
|
||||
/(navigator|netscape)\/((\d+)?[\w\.-]+)/i // Netscape
|
||||
], [[NAME, 'Netscape'], VERSION, MAJOR], [
|
||||
/(swiftfox)/i, // Swiftfox
|
||||
/(iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?((\d+)?[\w\.\+]+)/i,
|
||||
// Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
|
||||
/(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix)\/((\d+)?[\w\.-]+)/i,
|
||||
// Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
|
||||
/(mozilla)\/((\d+)?[\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
|
||||
|
||||
// Other
|
||||
/(uc\s?browser|polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf)[\/\s]?((\d+)?[\w\.]+)/i,
|
||||
// UCBrowser/Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf
|
||||
/(links)\s\(((\d+)?[\w\.]+)/i, // Links
|
||||
/(gobrowser)\/?((\d+)?[\w\.]+)*/i, // GoBrowser
|
||||
/(ice\s?browser)\/v?((\d+)?[\w\._]+)/i, // ICE Browser
|
||||
/(mosaic)[\/\s]((\d+)?[\w\.]+)/i // Mosaic
|
||||
], [NAME, VERSION, MAJOR]
|
||||
],
|
||||
|
||||
device : [[
|
||||
|
||||
/\((ipad|playbook);[\w\s\);-]+(rim|apple)/i // iPad/PlayBook
|
||||
], [MODEL, VENDOR, [TYPE, TABLET]], [
|
||||
|
||||
/(hp).+(touchpad)/i, // HP TouchPad
|
||||
/(kindle)\/([\w\.]+)/i, // Kindle
|
||||
/\s(nook)[\w\s]+build\/(\w+)/i, // Nook
|
||||
/(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
|
||||
], [VENDOR, MODEL, [TYPE, TABLET]], [
|
||||
|
||||
/\((ip[honed]+);.+(apple)/i // iPod/iPhone
|
||||
], [MODEL, VENDOR, [TYPE, MOBILE]], [
|
||||
|
||||
/(blackberry)[\s-]?(\w+)/i, // BlackBerry
|
||||
/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|huawei|meizu|motorola)[\s_-]?([\w-]+)*/i,
|
||||
// BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Huawei/Meizu/Motorola
|
||||
/(hp)\s([\w\s]+\w)/i, // HP iPAQ
|
||||
/(asus)-?(\w+)/i // Asus
|
||||
], [VENDOR, MODEL, [TYPE, MOBILE]], [
|
||||
/\((bb10);\s(\w+)/i // BlackBerry 10
|
||||
], [[VENDOR, 'BlackBerry'], MODEL, [TYPE, MOBILE]], [
|
||||
|
||||
/android.+((transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+))/i // Asus Tablets
|
||||
], [[VENDOR, 'Asus'], MODEL, [TYPE, TABLET]], [
|
||||
|
||||
/(sony)\s(tablet\s[ps])/i // Sony Tablets
|
||||
], [VENDOR, MODEL, [TYPE, TABLET]], [
|
||||
|
||||
/(nintendo)\s([wids3u]+)/i // Nintendo
|
||||
], [VENDOR, MODEL, [TYPE, CONSOLE]], [
|
||||
|
||||
/((playstation)\s[3portablevi]+)/i // Playstation
|
||||
], [[VENDOR, 'Sony'], MODEL, [TYPE, CONSOLE]], [
|
||||
|
||||
/(sprint\s(\w+))/i // Sprint Phones
|
||||
], [[VENDOR, mapper.str, maps.device.sprint.vendor], [MODEL, mapper.str, maps.device.sprint.model], [TYPE, MOBILE]], [
|
||||
|
||||
/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC
|
||||
/(zte)-(\w+)*/i, // ZTE
|
||||
/(alcatel|geeksphone|huawei|lenovo|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]+)*/i
|
||||
// Alcatel/GeeksPhone/Huawei/Lenovo/Nexian/Panasonic/Sony
|
||||
], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
|
||||
|
||||
/\s((milestone|droid[2x]?))[globa\s]*\sbuild\//i, // Motorola
|
||||
/(mot)[\s-]?(\w+)*/i
|
||||
], [[VENDOR, 'Motorola'], MODEL, [TYPE, MOBILE]], [
|
||||
/android.+\s((mz60\d|xoom[\s2]{0,2}))\sbuild\//i
|
||||
], [[VENDOR, 'Motorola'], MODEL, [TYPE, TABLET]], [
|
||||
|
||||
/android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n8000|sgh-t8[56]9))/i
|
||||
], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
|
||||
/((s[cgp]h-\w+|gt-\w+|galaxy\snexus))/i,
|
||||
/(sam[sung]*)[\s-]*(\w+-?[\w-]*)*/i,
|
||||
/sec-((sgh\w+))/i
|
||||
], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
|
||||
/(sie)-(\w+)*/i // Siemens
|
||||
], [[VENDOR, 'Siemens'], MODEL, [TYPE, MOBILE]], [
|
||||
|
||||
/(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
|
||||
/(nokia)[\s_-]?([\w-]+)*/i
|
||||
], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
|
||||
|
||||
/android\s3\.[\s\w-;]{10}((a\d{3}))/i // Acer
|
||||
], [[VENDOR, 'Acer'], MODEL, [TYPE, TABLET]], [
|
||||
|
||||
/android\s3\.[\s\w-;]{10}(lg?)-([06cv9]{3,4})/i // LG
|
||||
], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
|
||||
/((nexus\s4))/i,
|
||||
/(lg)[e;\s-\/]+(\w+)*/i
|
||||
], [[VENDOR, 'LG'], MODEL, [TYPE, MOBILE]], [
|
||||
|
||||
/(mobile|tablet);.+rv\:.+gecko\//i // Unidentifiable
|
||||
], [TYPE, VENDOR, MODEL]
|
||||
],
|
||||
|
||||
engine : [[
|
||||
|
||||
/(presto)\/([\w\.]+)/i, // Presto
|
||||
/(webkit|trident|netfront|netsurf|amaya|lynx|w3m)\/([\w\.]+)/i, // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m
|
||||
/(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i, // KHTML/Tasman/Links
|
||||
/(icab)[\/\s]([23]\.[\d\.]+)/i // iCab
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/rv\:([\w\.]+).*(gecko)/i // Gecko
|
||||
], [VERSION, NAME]
|
||||
],
|
||||
|
||||
os : [[
|
||||
|
||||
// Windows based
|
||||
/(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
|
||||
/(windows\sphone(?:\sos)*|windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
|
||||
], [NAME, [VERSION, mapper.str, maps.os.windows.version]], [
|
||||
/(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
|
||||
], [[NAME, 'Windows'], [VERSION, mapper.str, maps.os.windows.version]], [
|
||||
|
||||
// Mobile/Embedded OS
|
||||
/\((bb)(10);/i // BlackBerry 10
|
||||
], [[NAME, 'BlackBerry'], VERSION], [
|
||||
/(blackberry)\w*\/?([\w\.]+)*/i, // Blackberry
|
||||
/(tizen)\/([\w\.]+)/i, // Tizen
|
||||
/(android|webos|palm\os|qnx|bada|rim\stablet\sos|meego)[\/\s-]?([\w\.]+)*/i
|
||||
// Android/WebOS/Palm/QNX/Bada/RIM/MeeGo
|
||||
], [NAME, VERSION], [
|
||||
/(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]+)*/i // Symbian
|
||||
], [[NAME, 'Symbian'], VERSION],[
|
||||
/mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
|
||||
], [[NAME, 'Firefox OS'], VERSION], [
|
||||
|
||||
// Console
|
||||
/(nintendo|playstation)\s([wids3portablevu]+)/i, // Nintendo/Playstation
|
||||
|
||||
// GNU/Linux based
|
||||
/(mint)[\/\s\(]?(\w+)*/i, // Mint
|
||||
/(joli|[kxln]?ubuntu|debian|[open]*suse|gentoo|arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk)[\/\s-]?([\w\.-]+)*/i,
|
||||
// Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
|
||||
// Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk
|
||||
/(hurd|linux)\s?([\w\.]+)*/i, // Hurd/Linux
|
||||
/(gnu)\s?([\w\.]+)*/i // GNU
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
|
||||
], [[NAME, 'Chromium OS'], VERSION],[
|
||||
|
||||
// Solaris
|
||||
/(sunos)\s?([\w\.]+\d)*/i // Solaris
|
||||
], [[NAME, 'Solaris'], VERSION], [
|
||||
|
||||
// BSD based
|
||||
/\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]+)*/i // FreeBSD/NetBSD/OpenBSD/PC-BSD/DragonFly
|
||||
], [NAME, VERSION],[
|
||||
|
||||
/(ip[honead]+)(?:.*os\s*([\w]+)*\slike\smac|;\sopera)/i // iOS
|
||||
], [[NAME, 'iOS'], [VERSION, /_/g, '.']], [
|
||||
|
||||
/(mac\sos\sx)\s?([\w\s\.]+\w)*/i // Mac OS
|
||||
], [NAME, [VERSION, /_/g, '.']], [
|
||||
|
||||
// Other
|
||||
/(haiku)\s(\w+)/i, // Haiku
|
||||
/(aix)\s((\d)(?=\.|\)|\s)[\w\.]*)*/i, // AIX
|
||||
/(macintosh|mac(?=_powerpc)|plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos)/i,
|
||||
// Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS
|
||||
/(unix)\s?([\w\.]+)*/i // UNIX
|
||||
], [NAME, VERSION]
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
/////////////////
|
||||
// Constructor
|
||||
////////////////
|
||||
|
||||
|
||||
var UAParser = function (uastring) {
|
||||
|
||||
var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
|
||||
|
||||
if (!(this instanceof UAParser)) {
|
||||
return new UAParser(uastring).getResult();
|
||||
}
|
||||
this.getBrowser = function () {
|
||||
return mapper.rgx.apply(this, regexes.browser);
|
||||
};
|
||||
this.getDevice = function () {
|
||||
return mapper.rgx.apply(this, regexes.device);
|
||||
};
|
||||
this.getEngine = function () {
|
||||
return mapper.rgx.apply(this, regexes.engine);
|
||||
};
|
||||
this.getOS = function () {
|
||||
return mapper.rgx.apply(this, regexes.os);
|
||||
};
|
||||
this.getResult = function() {
|
||||
return {
|
||||
browser : this.getBrowser(),
|
||||
engine : this.getEngine(),
|
||||
os : this.getOS(),
|
||||
device : this.getDevice()
|
||||
};
|
||||
};
|
||||
this.getUA = function () {
|
||||
return ua;
|
||||
};
|
||||
this.setUA = function (uastring) {
|
||||
ua = uastring;
|
||||
return this;
|
||||
};
|
||||
this.setUA(ua);
|
||||
};
|
||||
|
||||
|
||||
///////////
|
||||
// Export
|
||||
//////////
|
||||
|
||||
|
||||
// check js environment
|
||||
if (typeof(exports) !== UNDEF_TYPE) {
|
||||
// nodejs env
|
||||
if (typeof(module) !== UNDEF_TYPE && module.exports) {
|
||||
exports = module.exports = UAParser;
|
||||
}
|
||||
exports.UAParser = UAParser;
|
||||
} else {
|
||||
// browser env
|
||||
window.UAParser = UAParser;
|
||||
// requirejs env (optional)
|
||||
if (typeof(define) === FUNC_TYPE && define.amd) {
|
||||
define(function () {
|
||||
return UAParser;
|
||||
});
|
||||
}
|
||||
// jQuery specific (optional)
|
||||
if (typeof(window.jQuery) !== UNDEF_TYPE) {
|
||||
var $ = window.jQuery;
|
||||
var parser = new UAParser();
|
||||
$.ua = parser.getResult();
|
||||
$.ua.get = function() {
|
||||
return parser.getUA();
|
||||
};
|
||||
$.ua.set = function (uastring) {
|
||||
parser.setUA(uastring);
|
||||
var result = parser.getResult();
|
||||
for (var prop in result) {
|
||||
$.ua[prop] = result[prop];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
})(this);
|
||||
7
src/ua-parser.min.js
vendored
Normal file
7
src/ua-parser.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
641
test/browser-test.json
Normal file
641
test/browser-test.json
Normal file
@@ -0,0 +1,641 @@
|
||||
[
|
||||
{
|
||||
"desc" : "Arora",
|
||||
"ua" : "Mozilla/5.0 (Windows; U; Windows NT 5.1; de-CH) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.2",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Arora",
|
||||
"version" : "0.2",
|
||||
"major" : "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Avant",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB5; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Avant Browser",
|
||||
"version" : "undefined",
|
||||
"major" : "undefined"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Baidu",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; baidubrowser 1.x)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "baidubrowser",
|
||||
"version" : "1.x",
|
||||
"major" : "1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Bolt",
|
||||
"ua" : "Mozilla/5.0 (X11; 78; CentOS; US-en) AppleWebKit/527+ (KHTML, like Gecko) Bolt/0.862 Version/3.0 Safari/523.15",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Bolt",
|
||||
"version" : "0.862",
|
||||
"major" : "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Camino",
|
||||
"ua" : "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.4; en; rv:1.9.0.19) Gecko/2011091218 Camino/2.0.9 (like Firefox/3.0.19)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Camino",
|
||||
"version" : "2.0.9",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Chimera",
|
||||
"ua" : "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; pl-PL; rv:1.0.1) Gecko/20021111 Chimera/0.6",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Chimera",
|
||||
"version" : "0.6",
|
||||
"major" : "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Chrome",
|
||||
"ua" : "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Chrome",
|
||||
"version" : "20.0.1090.0",
|
||||
"major" : "20"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Chrome on iOS",
|
||||
"ua" : "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Chrome",
|
||||
"version" : "19.0.1084.60",
|
||||
"major" : "19"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Chromium",
|
||||
"ua" : "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Ubuntu/11.10 Chromium/16.0.912.21 Chrome/16.0.912.21 Safari/535.7",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Chromium",
|
||||
"version" : "16.0.912.21",
|
||||
"major" : "16"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Chrome on Android",
|
||||
"ua" : "Mozilla/5.0 (Linux; U; Android-4.0.3; en-us; Galaxy Nexus Build/IML74K) AppleWebKit/535.7 (KHTML, like Gecko) CrMo/16.0.912.75 Mobile Safari/535.7",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Chrome",
|
||||
"version" : "16.0.912.75",
|
||||
"major" : "16"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Dillo",
|
||||
"ua" : "Dillo/2.2",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Dillo",
|
||||
"version" : "2.2",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Dolphin",
|
||||
"ua" : "Mozilla/5.0 (SCH-F859/F859DG12;U;NUCLEUS/2.1;Profile/MIDP-2.1 Configuration/CLDC-1.1;480*800;CTC/2.0) Dolfin/2.0",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Dolphin",
|
||||
"version" : "2.0",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Doris",
|
||||
"ua" : "Doris/1.15 [en] (Symbian)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Doris",
|
||||
"version" : "1.15",
|
||||
"major" : "1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Epiphany",
|
||||
"ua" : "Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7) Gecko/20040628 Epiphany/1.2.6",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Epiphany",
|
||||
"version" : "1.2.6",
|
||||
"major" : "1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Firebird",
|
||||
"ua" : "Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.5) Gecko/20031007 Firebird/0.7",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Firebird",
|
||||
"version" : "0.7",
|
||||
"major" : "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Firefox",
|
||||
"ua" : "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Firefox",
|
||||
"version" : "15.0a2",
|
||||
"major" : "15"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Fennec",
|
||||
"ua" : "Mozilla/5.0 (X11; U; Linux armv61; en-US; rv:1.9.1b2pre) Gecko/20081015 Fennec/1.0a1",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Fennec",
|
||||
"version" : "1.0a1",
|
||||
"major" : "1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Flock",
|
||||
"ua" : "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008100716 Firefox/3.0.3 Flock/2.0",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Flock",
|
||||
"version" : "2.0",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "GoBrowser",
|
||||
"ua" : "Nokia5700XpressMusic/GoBrowser/1.6.91",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "GoBrowser",
|
||||
"version" : "1.6.91",
|
||||
"major" : "1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "IceApe",
|
||||
"ua" : "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.19) Gecko/20110817 Iceape/2.0.14",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Iceape",
|
||||
"version" : "2.0.14",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "IceCat",
|
||||
"ua" : "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092921 IceCat/3.0.3-g1",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "IceCat",
|
||||
"version" : "3.0.3-g1",
|
||||
"major" : "3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Iceweasel",
|
||||
"ua" : "Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.0.16) Gecko/2009121610 Iceweasel/3.0.6 (Debian-3.0.6-3)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Iceweasel",
|
||||
"version" : "3.0.6",
|
||||
"major" : "3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "iCab",
|
||||
"ua" : "iCab/2.9.5 (Macintosh; U; PPC; Mac OS X)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "iCab",
|
||||
"version" : "2.9.5",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "IEMobile",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.11) 320x240; VZW; Motorola-Q9c; Windows Mobile 6.1 Standard",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "IEMobile",
|
||||
"version" : "7.11",
|
||||
"major" : "7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "IE 11",
|
||||
"ua" : "Mozilla/5.0 (IE 11.0; Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "IE",
|
||||
"version" : "11.0",
|
||||
"major" : "11"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "K-Meleon",
|
||||
"ua" : "Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.5) Gecko/20031016 K-Meleon/0.8.2",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "K-Meleon",
|
||||
"version" : "0.8.2",
|
||||
"major" : "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Kindle Browser",
|
||||
"ua" : "Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.5 (screen 600x800; rotate)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Kindle",
|
||||
"version" : "2.5",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Konqueror",
|
||||
"ua" : "Mozilla/5.0 (compatible; Konqueror/3.5; Linux; X11; x86_64) KHTML/3.5.6 (like Gecko) (Kubuntu)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Konqueror",
|
||||
"version" : "3.5",
|
||||
"major" : "3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Lunascape",
|
||||
"ua" : "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.2) Gecko/20090804 Firefox/3.5.2 Lunascape/5.1.4.5",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Lunascape",
|
||||
"version" : "5.1.4.5",
|
||||
"major" : "5"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Lynx",
|
||||
"ua" : "Lynx/2.8.5dev.16 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6b",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Lynx",
|
||||
"version" : "2.8.5dev.16",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Maemo Browser",
|
||||
"ua" : "Mozilla/5.0 (X11; U; Linux armv7l; ru-RU; rv:1.9.2.3pre) Gecko/20100723 Firefox/3.5 Maemo Browser 1.7.4.8 RX-51 N900",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Maemo Browser",
|
||||
"version" : "1.7.4.8",
|
||||
"major" : "1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Maxthon",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Maxthon",
|
||||
"version" : "undefined",
|
||||
"major" : "undefined"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Midori",
|
||||
"ua" : "Midori/0.2.2 (X11; Linux i686; U; en-us) WebKit/531.2+",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Midori",
|
||||
"version" : "0.2.2",
|
||||
"major" : "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Minimo",
|
||||
"ua" : "Mozilla/5.0 (X11; U; Linux armv6l; rv 1.8.1.5pre) Gecko/20070619 Minimo/0.020",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Minimo",
|
||||
"version" : "0.020",
|
||||
"major" : "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Mobile Safari",
|
||||
"ua" : "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Mobile Safari",
|
||||
"version" : "4.0.5",
|
||||
"major" : "4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Mosaic",
|
||||
"ua" : "NCSA_Mosaic/2.6 (X11; SunOS 4.1.3 sun4m)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Mosaic",
|
||||
"version" : "2.6",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Mozilla",
|
||||
"ua" : "Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.7) Gecko/20070606",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Mozilla",
|
||||
"version" : "5.0",
|
||||
"major" : "5"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "MSIE",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 5.0b1; Mac_PowerPC)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "IE",
|
||||
"version" : "5.0b1",
|
||||
"major" : "5"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "NetFront",
|
||||
"ua" : "Mozilla/4.0 (PDA; Windows CE/1.0.1) NetFront/3.0",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "NetFront",
|
||||
"version" : "3.0",
|
||||
"major" : "3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Netscape on Windows ME",
|
||||
"ua" : "Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.8.1.8pre) Gecko/20071015 Firefox/2.0.0.7 Navigator/9.0",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Netscape",
|
||||
"version" : "9.0",
|
||||
"major" : "9"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Netscape on Windows 2000",
|
||||
"ua" : "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20050519 Netscape/8.0.1",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Netscape",
|
||||
"version" : "8.0.1",
|
||||
"major" : "8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Nokia Browser",
|
||||
"ua" : "Mozilla/5.0 (Symbian/3; Series60/5.2 NokiaN8-00/025.007; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/533.4 (KHTML, like Gecko) NokiaBrowser/7.3.1.37 Mobile Safari/533.4 3gpp-gba",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "NokiaBrowser",
|
||||
"version" : "7.3.1.37",
|
||||
"major" : "7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "OmniWeb",
|
||||
"ua" : "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/85 (KHTML, like Gecko) OmniWeb/v558.48",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "OmniWeb",
|
||||
"version" : "558.48",
|
||||
"major" : "558"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Opera > 9.80",
|
||||
"ua" : "Opera/9.80 (X11; Linux x86_64; U; Linux Mint; en) Presto/2.2.15 Version/10.10",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Opera",
|
||||
"version" : "10.10",
|
||||
"major" : "10"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Opera < 9.80 on Windows",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 5.0; Windows 95) Opera 6.01 [en]",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Opera",
|
||||
"version" : "6.01",
|
||||
"major" : "6"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Opera < 9.80 on OSX",
|
||||
"ua" : "Opera/8.5 (Macintosh; PPC Mac OS X; U; en)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Opera",
|
||||
"version" : "8.5",
|
||||
"major" : "8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Opera Mobile",
|
||||
"ua" : "Opera/9.80 (Android 2.3.5; Linux; Opera Mobi/ADR-1111101157; U; de) Presto/2.9.201 Version/11.50",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Opera Mobi",
|
||||
"version" : "11.50",
|
||||
"major" : "11"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Opera Webkit",
|
||||
"ua" : "Mozilla/5.0 AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.123 Mobile Safari/537.22 OPR/14.0.1025.52315",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Opera",
|
||||
"version" : "14.0.1025.52315",
|
||||
"major" : "14"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Opera Mini",
|
||||
"ua" : "Opera/9.80 (J2ME/MIDP; Opera Mini/5.1.21214/19.916; U; en) Presto/2.5.25",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Opera Mini",
|
||||
"version" : "5.1.21214",
|
||||
"major" : "5"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Opera Tablet",
|
||||
"ua" : "Opera/9.80 (Windows NT 6.1; Opera Tablet/15165; U; en) Presto/2.8.149 Version/11.1",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Opera Tablet",
|
||||
"version" : "11.1",
|
||||
"major" : "11"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Phoenix",
|
||||
"ua" : "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2b) Gecko/20021029 Phoenix/0.4",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Phoenix",
|
||||
"version" : "0.4",
|
||||
"major" : "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Polaris",
|
||||
"ua" : "LG-LX600 Polaris/6.0 MMP/2.0 Profile/MIDP-2.1 Configuration/CLDC-1.1",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Polaris",
|
||||
"version" : "6.0",
|
||||
"major" : "6"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "RockMelt",
|
||||
"ua" : "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) RockMelt/0.8.36.78 Chrome/7.0.517.44 Safari/534.7",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "RockMelt",
|
||||
"version" : "0.8.36.78",
|
||||
"major" : "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Safari",
|
||||
"ua" : "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Safari",
|
||||
"version" : "5.0.1",
|
||||
"major" : "5"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Safari < 3.0",
|
||||
"ua" : "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Safari",
|
||||
"version" : "2.0.4",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "SeaMonkey",
|
||||
"ua" : "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4pre) Gecko/20090405 SeaMonkey/2.0b1pre",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "SeaMonkey",
|
||||
"version" : "2.0b1pre",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Silk Browser",
|
||||
"ua" : "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-84)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Silk",
|
||||
"version" : "1.1.0-84",
|
||||
"major" : "1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Skyfire",
|
||||
"ua" : "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Safari/530.17 Skyfire/2.0",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Skyfire",
|
||||
"version" : "2.0",
|
||||
"major" : "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "SlimBrowser",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SlimBrowser)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "SlimBrowser",
|
||||
"version" : "undefined",
|
||||
"major" : "undefined"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Swiftfox",
|
||||
"ua" : "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061024 Firefox/2.0 (Swiftfox)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Swiftfox",
|
||||
"version" : "undefined",
|
||||
"major" : "undefined"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Tizen Browser",
|
||||
"ua" : "Mozilla/5.0 (Linux; U; Tizen/1.0 like Android; en-us; AppleWebKit/534.46 (KHTML, like Gecko) Tizen Browser/1.0 Mobile",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Tizen Browser",
|
||||
"version" : "1.0",
|
||||
"major" : "1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "UC Browser on Samsung",
|
||||
"ua" : "Mozilla/5.0 (Java; U; Pt-br; samsung-gt-s5620) UCBrowser8.2.1.144/69/352/UCWEB Mobile UNTRUSTED/1.0",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "UCBrowser",
|
||||
"version" : "8.2.1.144",
|
||||
"major" : "8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "UC Browser on Nokia",
|
||||
"ua" : "Mozilla/5.0 (S60V3; U; en-in; NokiaN73)/UC Browser8.4.0.159/28/351/UCWEB Mobile",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "UC Browser",
|
||||
"version" : "8.4.0.159",
|
||||
"major" : "8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Yandex",
|
||||
"ua" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.5 (KHTML, like Gecko) YaBrowser/1.0.1084.5402 Chrome/19.0.1084.5402 Safari/536.5",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Yandex",
|
||||
"version" : "1.0.1084.5402",
|
||||
"major" : "1"
|
||||
}
|
||||
}]
|
||||
21
test/device-test.json
Normal file
21
test/device-test.json
Normal file
@@ -0,0 +1,21 @@
|
||||
[
|
||||
{
|
||||
"desc" : "HTC Evo Shift 4G",
|
||||
"ua" : "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0",
|
||||
"expect" :
|
||||
{
|
||||
"vendor" : "HTC",
|
||||
"model" : "Evo Shift 4G",
|
||||
"type" : "mobile"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "LG Nexus 4",
|
||||
"ua" : "Mozilla/5.0 (Linux; Android 4.2.1; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19",
|
||||
"expect" :
|
||||
{
|
||||
"vendor" : "LG",
|
||||
"model" : "Nexus 4",
|
||||
"type" : "mobile"
|
||||
}
|
||||
}]
|
||||
64
test/engine-test.json
Normal file
64
test/engine-test.json
Normal file
@@ -0,0 +1,64 @@
|
||||
[
|
||||
{
|
||||
"desc" : "Gecko",
|
||||
"ua" : "Mozilla/5.0 (X11; Linux x86_64; rv:2.0b9pre) Gecko/20110111 Firefox/4.0b9pre",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Gecko",
|
||||
"version" : "2.0b9pre"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "KHTML",
|
||||
"ua" : "Mozilla/5.0 (compatible; Konqueror/4.5; FreeBSD) KHTML/4.5.4 (like Gecko)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "KHTML",
|
||||
"version" : "4.5.4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "NetFront",
|
||||
"ua" : "Mozilla/4.0 (PDA; Windows CE/1.0.1) NetFront/3.0",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "NetFront",
|
||||
"version" : "3.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Presto",
|
||||
"ua" : "Opera/9.80 (Windows NT 6.1; Opera Tablet/15165; U; en) Presto/2.8.149 Version/11.1",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Presto",
|
||||
"version" : "2.8.149"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Tasman",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 6.0; PPC Mac OS X 10.4.7; Tasman 1.0)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Tasman",
|
||||
"version" : "1.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Trident",
|
||||
"ua" : "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Trident",
|
||||
"version" : "6.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "WebKit",
|
||||
"ua" : "Mozilla/5.0 (Windows; U; Windows NT 6.1; sv-SE) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "WebKit",
|
||||
"version" : "533.19.4"
|
||||
}
|
||||
}]
|
||||
568
test/os-test.json
Normal file
568
test/os-test.json
Normal file
@@ -0,0 +1,568 @@
|
||||
[
|
||||
{
|
||||
"desc" : "Windows 95",
|
||||
"ua" : "Mozilla/1.22 (compatible; MSIE 2.0; Windows 95)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows",
|
||||
"version" : "95"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows 98",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows",
|
||||
"version" : "98"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows ME",
|
||||
"ua" : "Mozilla/5.0 (Windows; U; Win 9x 4.90) Gecko/20020502 CS 2000 7.0/7.0",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows",
|
||||
"version" : "ME"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows 2000",
|
||||
"ua" : "Mozilla/3.0 (compatible; MSIE 3.0; Windows NT 5.0)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows",
|
||||
"version" : "2000"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows XP",
|
||||
"ua" : "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 5.2)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows",
|
||||
"version" : "XP"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows Vista",
|
||||
"ua" : "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0; fr-FR)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows",
|
||||
"version" : "Vista"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows 7",
|
||||
"ua" : "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows",
|
||||
"version" : "7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows 8",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Win64; x64; Trident/6.0; .NET4.0E; .NET4.0C)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows",
|
||||
"version" : "8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows RT",
|
||||
"ua" : "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows",
|
||||
"version" : "RT"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows CE",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.11)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows",
|
||||
"version" : "CE"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows Mobile",
|
||||
"ua" : "Mozilla/5.0 (ZTE-E_N72/N72V1.0.0B02;U;Windows Mobile/6.1;Profile/MIDP-2.0 Configuration/CLDC-1.1;320*240;CTC/2.0) IE/6.0 (compatible; MSIE 4.01; Windows CE; PPC)/UC Browser7.7.1.88",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows Mobile",
|
||||
"version" : "6.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows Phone OS",
|
||||
"ua" : "Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; DELL; Venue Pro)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows Phone OS",
|
||||
"version" : "7.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows Phone 8",
|
||||
"ua" : "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; HTC; Windows Phone 8X by HTC)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Windows Phone",
|
||||
"version" : "8.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "BlackBerry",
|
||||
"ua" : "BlackBerry9300/5.0.0.912 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/378",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "BlackBerry",
|
||||
"version" : "5.0.0.912"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "BlackBerry 10",
|
||||
"ua" : "Mozilla/5.0 (BB10; Touch) AppleWebKit/537.3+ (KHTML, like Gecko) Version/10.0.9.386 Mobile Safari/537.3+",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "BlackBerry",
|
||||
"version" : "10"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Tizen",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Android",
|
||||
"ua" : "Mozilla/5.0 (Linux; U; Android 2.2.2; en-us; VM670 Build/FRG83G) AppleWebKit/533.1 (KHTML, like Gecko)",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Android",
|
||||
"version" : "2.2.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "WebOS",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Palm OS",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "QNX",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Bada",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "RIM Tablet OS",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "MeeGo",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Symbian",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Firefox OS",
|
||||
"ua" : "Mozilla/5.0 (Mobile; rv:14.0) Gecko/14.0 Firefox/14.0",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Firefox OS",
|
||||
"version" : "undefined"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Nintendo",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "PlayStation",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Mint",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Joli",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Ubuntu",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Debian",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "OpenSUSE",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Gentoo",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Arch",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Slackware",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Fedora",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Mandriva",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "CentOS",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "PCLinuxOS",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "RedHat",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Zenwalk",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Hurd",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Linux",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "GNU",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Chromium OS",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Solaris",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "FreeBSD",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "OpenBSD",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "NetBSD",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "DragonFly",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "iOS with Chrome",
|
||||
"ua" : "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "iOS",
|
||||
"version" : "5.1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "iOS with Opera Mini",
|
||||
"ua" : "Opera/9.80 (iPhone; Opera Mini/7.1.32694/27.1407; U; en) Presto/2.8.119 Version/11.10",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "iOS",
|
||||
"version" : "undefined"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Mac OS",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Haiku",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "AIX",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Plan9",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Minix",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "BeOS",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "OS/2",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "AmigaOS",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "MorphOS",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "UNIX",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "",
|
||||
"ua" : "",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "",
|
||||
"version" : ""
|
||||
}
|
||||
}]
|
||||
58
test/test.js
Normal file
58
test/test.js
Normal file
@@ -0,0 +1,58 @@
|
||||
var assert = require('assert');
|
||||
var UAParser = require('./../src/ua-parser');
|
||||
var browsers = require('./browser-test.json');
|
||||
var devices = require('./device-test.json');
|
||||
var engines = require('./engine-test.json');
|
||||
var os = require('./os-test.json');
|
||||
var parser = new UAParser();
|
||||
var methods = [
|
||||
{
|
||||
title : 'getBrowser',
|
||||
label : 'browser',
|
||||
list : browsers,
|
||||
properties : ['name', 'major', 'version']
|
||||
},
|
||||
{
|
||||
title : 'getDevice',
|
||||
label : 'device',
|
||||
list : devices,
|
||||
properties : ['model', 'type', 'vendor']
|
||||
},
|
||||
{
|
||||
title : 'getEngine',
|
||||
label : 'engine',
|
||||
list : engines,
|
||||
properties : ['name', 'version']
|
||||
},
|
||||
{
|
||||
title : 'getOS',
|
||||
label : 'os',
|
||||
list : os,
|
||||
properties : ['name', 'version']
|
||||
}];
|
||||
|
||||
describe('UAParser()', function () {
|
||||
var ua = 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6';
|
||||
assert.deepEqual(UAParser(ua), new UAParser().setUA(ua).getResult());
|
||||
});
|
||||
|
||||
for (var i in methods) {
|
||||
describe(methods[i]['title'], function () {
|
||||
for (var j in methods[i]['list']) {
|
||||
if (!!methods[i]['list'][j].ua) {
|
||||
describe('[' + methods[i]['list'][j].desc + ']', function () {
|
||||
describe('"' + methods[i]['list'][j].ua + '"', function () {
|
||||
var expect = methods[i]['list'][j].expect;
|
||||
var result = parser.setUA(methods[i]['list'][j].ua).getResult()[methods[i]['label']];
|
||||
for (var k in methods[i]['properties']) {
|
||||
var m = methods[i]['properties'][k];
|
||||
it('should return ' + methods[i]['label'] + ' ' + m + ': ' + expect[m], function () {
|
||||
assert.equal(result[m], expect[m] != 'undefined' ? expect[m] : undefined);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
31
ua-parser-js.jquery.json
Normal file
31
ua-parser-js.jquery.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"title": "UAParser.js",
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.5.27",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
"user-agent",
|
||||
"parser",
|
||||
"browser",
|
||||
"engine",
|
||||
"os",
|
||||
"device"
|
||||
],
|
||||
"homepage": "https://faisalman.github.com/ua-parser-js",
|
||||
"author": {
|
||||
"name": "Faisal Salman",
|
||||
"email": "fyzlman@gmail.com"
|
||||
},
|
||||
"dependencies": {
|
||||
"jquery": ">=1.5"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://www.opensource.org/licenses/mit-license.php"
|
||||
}
|
||||
],
|
||||
"bugs": "https://github.com/faisalman/ua-parser-js/issues",
|
||||
"docs": "https://github.com/faisalman/ua-parser-js",
|
||||
"download": "https://raw.github.com/faisalman/ua-parser-js/master/src/ua-parser.min.js"
|
||||
}
|
||||
310
ua-parser.js
310
ua-parser.js
@@ -1,310 +0,0 @@
|
||||
// UA-Parser.JS v0.4.3
|
||||
// Lightweight JavaScript-based User-Agent string parser
|
||||
// https://github.com/faisalman/ua-parser-js
|
||||
//
|
||||
// Copyright © 2012 Faisalman
|
||||
// Dual licensed under GPLv2 & MIT
|
||||
|
||||
(function (undefined) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var mapper = {
|
||||
|
||||
regex : function () {
|
||||
|
||||
var result, i, j, k, l, m, args = arguments;
|
||||
|
||||
// loop through all regexes maps
|
||||
for (i = 0; i < args.length; i += 2) {
|
||||
|
||||
var regex = args[i], // odd sequence (0,2,4,..)
|
||||
props = args[i + 1]; // even sequence (1,3,5,..)
|
||||
|
||||
// construct object barebones
|
||||
if (typeof result === 'undefined') {
|
||||
result = {};
|
||||
for (k = 0; k < props.length; k++) {
|
||||
if (typeof props[k] === 'object') {
|
||||
result[props[k][0]] = undefined;
|
||||
} else {
|
||||
result[props[k]] = undefined;
|
||||
}
|
||||
}
|
||||
if (this.getUA().toString() === '') {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// try matching uastring with regexes
|
||||
for (j = 0; j < regex.length; j++) {
|
||||
l = regex[j].exec(this.getUA());
|
||||
if (!!l) {
|
||||
for (k = 0; k < props.length; k++) {
|
||||
m = l[k + 1];
|
||||
if (typeof props[k] === 'object' && props[k].length === 2) {
|
||||
result[props[k][0]] = props[k][1];
|
||||
} else if (typeof props[k] === 'object' && props[k].length === 3) {
|
||||
if (typeof props[k][1] === 'function') {
|
||||
result[props[k][0]] = m ? props[k][1].call(this, m, props[k][2]) : undefined;
|
||||
} else {
|
||||
result[props[k][0]] = m ? m.replace(props[k][1], props[k][2]) : undefined;
|
||||
}
|
||||
} else {
|
||||
result[props[k]] = m ? m : undefined;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!!l) break; // break the loop immediately if match found
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
string : function (str, map) {
|
||||
|
||||
for (var i in map) {
|
||||
if (map.hasOwnProperty(i)) {
|
||||
if (typeof map[i] === 'object' && map[i].length > 0) {
|
||||
for (var j = 0; j < map[i].length; j++) {
|
||||
if (str.toLowerCase().indexOf(map[i][j].toLowerCase()) !== -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else if (str.toLowerCase().indexOf(map[i].toLowerCase()) !== -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
var maps = {
|
||||
os : {
|
||||
windows : {
|
||||
version : {
|
||||
'ME' : '4.90',
|
||||
'NT 3.11' : 'NT3.51',
|
||||
'NT 4.0' : 'NT4.0',
|
||||
'2000' : 'NT 5.0',
|
||||
'XP' : ['NT 5.1', 'NT 5.2'],
|
||||
'Vista' : 'NT 6.0',
|
||||
'7' : 'NT 6.1',
|
||||
'8' : 'NT 6.2'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var regexes = {
|
||||
|
||||
browser : [[
|
||||
|
||||
// Mixed
|
||||
/(kindle)\/((\d+)?[\w\.]+)/i, // Kindle
|
||||
/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?((\d+)?[\w\.]+)/i,
|
||||
// Lunascape/Maxthon/Netfront/Jasmine/Blazer
|
||||
|
||||
// Presto based
|
||||
/(opera\smini)\/((\d+)?[\w\.-]+)/i, // Opera Mini
|
||||
/(opera\smobi)\/((\d+)?[\w\.-]+)/i, // Opera Mobile
|
||||
/(opera).+version\/((\d+)?[\w\.]+)/i, // Opera > 9.80
|
||||
/(opera)[\/\s]+((\d+)?[\w\.]+)/i, // Opera < 9.80
|
||||
|
||||
// Trident based
|
||||
/(avant\sbrowser|iemobile|slimbrowser)[\/\s]?((\d+)?[\w\.]*)/i, // Avant/IEMobile/SlimBrowser
|
||||
/ms(ie)\s((\d+)?[\w\.]+)/i, // Internet Explorer
|
||||
|
||||
// Webkit/KHTML based
|
||||
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|series60|bolt)\/((\d+)?[\w\.]+)/i,
|
||||
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/S60/Bolt
|
||||
/(chrome|omniweb|arora|dolfin|[tizenoka]{5}\s?browser)\/((\d+)?[\w\.]+)/i,
|
||||
// Chrome/OmniWeb/Arora/Dolphin/Tizen/Nokia
|
||||
], ['name', 'version', 'major'], [
|
||||
/(?:android.+(crmo|crios))\/((\d+)?[\w\.]+)/i, // Chrome for Android/iOS
|
||||
], [['name', 'Chrome'], 'version', 'major'], [
|
||||
/(mobile\ssafari|safari|konqueror)\/((\d+)?[\w\.]+)/i, // Safari/Konqueror
|
||||
/(applewebkit|khtml)\/((\d+)?[\w\.]+)/i,
|
||||
|
||||
// Gecko based
|
||||
/(iceweasel|camino|fennec|maemo\sbrowser|minimo)[\/\s]?((\d+)?[\w\.\+]+)/i,
|
||||
// Iceweasel/Camino/Fennec/Maemo/Minimo
|
||||
/(firefox|seamonkey|netscape|navigator|k-meleon|icecat|iceape)\/((\d+)?[\w\.]+)/i,
|
||||
// Firefox/SeaMonkey/Netscape/K-Meleon/IceCat/IceApe
|
||||
/(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
|
||||
|
||||
// Other
|
||||
/(lynx|dillo|icab|doris)[\/\s]?((\d+)?[\w\.]+)/i, // Lynx/Dillo/iCab/Doris
|
||||
/(gobrowser)\/?[\d\.]*/i // GoBrowser
|
||||
], ['name', 'version', 'major']
|
||||
],
|
||||
|
||||
device : [[
|
||||
|
||||
/\(((ip[honead]+|playbook));/i, // iPod/iPhone/iPad/PlayBook
|
||||
/(hp).+(touchpad)/i, // HP TouchPad
|
||||
/(kindle)\/([\w\.]+)/i, // Kindle
|
||||
/\s(nook)[\w\s]+build\/(\w+)/i, // Nook
|
||||
/(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
|
||||
], ['vendor', 'model', ['type', 'Tablet']], [
|
||||
|
||||
/(blackberry)[\s-]?(\w+)/i, // BlackBerry
|
||||
/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|nexus|huawei|meizu)[\s_-]?([\w-]+)*/i,
|
||||
// BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Nexus/Huawei/Meizu
|
||||
/(hp)\s([\w\s]+\w)/i, // HP iPAQ
|
||||
/(asus)-?(\w+)/i // Asus
|
||||
], ['vendor', 'model', ['type', 'Mobile']], [
|
||||
|
||||
/android.+((transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+))/i // Asus Tablets
|
||||
], [['vendor', 'Asus'], 'model', ['type', 'Tablet']], [
|
||||
|
||||
/(sony)\s(tablet\s[ps])/i // Sony Tablets
|
||||
], ['vendor', 'model', ['type', 'Tablet']], [
|
||||
|
||||
/(nintendo|playstation)\s([wids3portablev]+)/i // Nintendo/Playstation
|
||||
], ['vendor', 'model', ['type', 'Console']], [
|
||||
|
||||
/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC
|
||||
/(zte)-(\w+)*/i // ZTE
|
||||
], ['vendor', ['model', /_/g, ' '], ['type', 'Mobile']], [
|
||||
|
||||
/\s((milestone|droid[2x]?))[globa\s]*\sbuild\//i, // Motorola
|
||||
/(mot)[\s-]?(\w+)*/i
|
||||
], [['vendor', 'Motorola'], 'model', ['type', 'Mobile']], [
|
||||
/android.+\s((mz60\d|xoom[\s2]{0,2}))\sbuild\//i
|
||||
], [['vendor', 'Motorola'], 'model', ['type', 'Tablet']], [
|
||||
|
||||
/android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n8000|sgh-t8[56]9))/i
|
||||
], [['vendor', 'Samsung'], 'model', ['type', 'Tablet']], [ // Samsung
|
||||
/((s[cgp]h-\w+|gt-\w+|galaxy\snexus))/i,
|
||||
/(sam[sung]*)[\s-]*(\w+-?[\w-]*)*/i,
|
||||
/sec-((sgh\w+))/i
|
||||
], [['vendor', 'Samsung'], 'model', ['type', 'Mobile']], [
|
||||
/(sie)-(\w+)*/i // Siemens
|
||||
], [['vendor', 'Siemens'], 'model', ['type', 'Mobile']], [
|
||||
|
||||
/(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
|
||||
/(nokia)[\s_-]?([\w-]+)*/i
|
||||
], [['vendor', 'Nokia'], 'model', ['type', 'Mobile']], [
|
||||
|
||||
/android\s3\.[\s\w-;]{10}((a\d{3}))/i // Acer
|
||||
], [['vendor', 'Acer'], 'model', ['type', 'Tablet']], [
|
||||
|
||||
/android\s3\.[\s\w-;]{10}(lg?)-([06cv9]{3,4})/i // LG
|
||||
], [['vendor', 'LG'], 'model', ['type', 'Tablet']], [
|
||||
/(lg)[e;\s-]+(\w+)*/i
|
||||
], [['vendor', 'LG'], 'model', ['type', 'Mobile']]
|
||||
],
|
||||
|
||||
engine : [[
|
||||
|
||||
/(presto)\/([\w\.]+)/i, // Presto
|
||||
/([aple]*webkit|trident)\/([\w\.]+)/i, // Webkit/Trident
|
||||
/(khtml)\/([\w\.]+)/i // KHTML
|
||||
], ['name', 'version'], [
|
||||
|
||||
/rv\:([\w\.]+).*(gecko)/i // Gecko
|
||||
], ['version', 'name']
|
||||
],
|
||||
|
||||
os : [[
|
||||
|
||||
// Windows based
|
||||
/(windows\sphone\sos|windows)\s?([ntce\d\.\s]+\d)/i // Windows
|
||||
], ['name', ['version', mapper.string, maps.os.windows.version]], [
|
||||
/(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
|
||||
], [['name', 'Windows'], ['version', mapper.string, maps.os.windows.version]], [
|
||||
|
||||
// Mobile/Embedded OS
|
||||
/(blackberry).+version\/([\w\.]+)/i, // Blackberry
|
||||
/(tizen)\/([\w\.]+)/i, // Tizen
|
||||
/(android|symbianos|symbos|webos|palm\os|qnx|bada|rim\stablet\sos|meego)[\/\s-]?([\w\.]+)*/i,
|
||||
// Android/Symbian/WebOS/Palm/QNX/Bada/RIM/MeeGo
|
||||
/(nintendo|playstation)\s([wids3portable]+)/i, // Nintendo/Playstation
|
||||
|
||||
// GNU/Linux based
|
||||
/(mint)[\/\s\(]?(\w+)*/i, // Mint
|
||||
/(joli|[kxln]?ubuntu|debian|[open]*suse|gentoo|arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk)[\/\s-]?([\w\.-]+)*/i,
|
||||
// Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
|
||||
// Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk
|
||||
/(gnu|linux)\s?([\w\.]+)*/i // Other GNU/Linux
|
||||
], ['name', 'version'], [
|
||||
|
||||
/(cros)\s([\w\.\s]+\d)/i // Chromium OS
|
||||
], [['name', 'Chromium OS'], 'version'],[
|
||||
|
||||
// Solaris
|
||||
/(sunos)\s?([\w\.\s]+\d)*/i // Solaris
|
||||
], [['name', 'Solaris'], 'version'], [
|
||||
|
||||
// BSD based
|
||||
/\s(\w*bsd|dragonfly)\s?([\w\.]+)*/i, // FreeBSD/NetBSD/OpenBSD/DragonFly
|
||||
], ['name', 'version'],[
|
||||
|
||||
/(ip[honead]+).*os\s*([\w]+)*\slike\smac/i // iOS
|
||||
], [['name', 'iOS'], ['version', /_/g, '.']], [
|
||||
|
||||
/(mac\sos\sx)\s([\w\s\.]+\w)/i, // Mac OS
|
||||
], ['name', ['version', /_/g, '.']], [
|
||||
|
||||
// Other
|
||||
/(haiku)\s(\w+)/i, // Haiku
|
||||
/(macintosh|unix|minix|beos)[\/\s]?()*/i // UNIX/Minix/BeOS
|
||||
], ['name', 'version']
|
||||
]
|
||||
};
|
||||
|
||||
var UAParser = function UAParser (uastring) {
|
||||
|
||||
var ua = uastring || (typeof window !== 'undefined' ? window.navigator.userAgent : "");
|
||||
|
||||
this.getBrowser = function () {
|
||||
return mapper.regex.apply(this, regexes.browser);
|
||||
};
|
||||
|
||||
this.getDevice = function () {
|
||||
return mapper.regex.apply(this, regexes.device);
|
||||
};
|
||||
|
||||
this.getEngine = function () {
|
||||
return mapper.regex.apply(this, regexes.engine);
|
||||
};
|
||||
|
||||
this.getOS = function () {
|
||||
return mapper.regex.apply(this, regexes.os);
|
||||
};
|
||||
|
||||
this.getResult = function() {
|
||||
return {
|
||||
browser : this.getBrowser(),
|
||||
engine : this.getEngine(),
|
||||
os : this.getOS(),
|
||||
device : this.getDevice()
|
||||
};
|
||||
};
|
||||
|
||||
this.getUA = function() {
|
||||
return ua;
|
||||
};
|
||||
|
||||
this.setUA = function (uastring) {
|
||||
ua = uastring;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.setUA(ua);
|
||||
};
|
||||
|
||||
// check whether script is running inside node.js export as module
|
||||
if (typeof exports !== 'undefined' && this.toString() !== '[object DOMWindow]') {
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
exports = module.exports = UAParser;
|
||||
}
|
||||
exports.UAParser = UAParser;
|
||||
} else {
|
||||
window['UAParser'] = UAParser;
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user