Compare commits

..

80 Commits

Author SHA1 Message Date
Faisal Salman
615d6a2034 Add new Webkit Opera 2013-03-05 21:05:38 +07:00
Faisal Salman
40ac5c5bc3 Fix issue #12 2013-02-27 21:44:43 +07:00
Faisal Salman
3eb1c1c352 Revise jQuery plugin API 2013-02-15 19:02:44 +07:00
Faisal Salman
217cef226a Update version 2013-02-15 10:23:49 +07:00
Faisal Salman
a5e4b7bf72 Merge pull request #11 from jbuck/requirejs
Add requirejs module support
2013-02-14 18:25:59 -08:00
Jon Buckley
8aaf7db771 Add requirejs module support
Fixes #10.
2013-02-14 14:52:41 -05:00
Faisal Salman
0109c76858 Automatically create $.ua object if jQuery is present 2013-02-07 23:25:21 +07:00
Faisal Salman
d1120a4d5d Update contributors 2013-02-05 20:43:15 +07:00
Faisal Salman
204345a8bf Add Rekonq, Comodo Dragon, Conkeror, Amaya, w3m, Links, ICE Browser, NetSurf, RISC OS 2013-02-05 20:29:26 +07:00
Faisal Salman
a20d8f7052 Sprint default vendor to Sprint 2013-02-05 14:43:17 +07:00
Faisal Salman
9a90d932ce Add new OS: Firefox OS 2013-01-28 18:46:03 +07:00
Faisal Salman
cea29e5c1b Add new devices: Alcatel, GeeksPhone, Huawei, Lenovo, Nexian, Panasonic, Sony 2013-01-28 18:21:12 +07:00
Faisal Salman
e0b6ae65e5 Better fix for issue #8 2013-01-28 17:11:12 +07:00
Faisal Salman
59714adea3 Add a test for issue #8 2013-01-25 20:33:03 +07:00
Faisal Salman
249dcf0c80 Merge branch 'htc-evo' 2013-01-25 19:47:58 +07:00
Faisalman
b99546072d Workaround for issue #8 2013-01-25 19:46:09 +07:00
Faisal Salman
4e911cec88 Merge pull request #9 from leetreveil/google_closure_compiler
Fix google closure compiler JSC_TRAILING_COMMA errors
2013-01-15 08:21:55 -08:00
Lee Treveil
f1fa7f38a1 Fix google closure compiler JSC_TRAILING_COMMA errors 2013-01-15 15:17:51 +00:00
Faisal Salman
a6610646ca Fix issue #7 2012-12-23 06:45:59 +07:00
Faisal Salman
4703137b79 Minify filesize by variable-izing strings 2012-12-11 18:40:03 +07:00
Faisal Salman
541dfea86d Add some more test 2012-12-07 17:04:26 +07:00
Faisal Salman
35b410009f Insert dog 2012-12-06 20:37:39 +07:00
Faisal Salman
5e84ab7b82 Add test for engine parser 2012-12-06 20:29:37 +07:00
Faisal Salman
816b5d22b4 Add Opera Tablet & capture AppleWebKit as just WebKit 2012-12-06 20:28:33 +07:00
Faisal Salman
29bb0797a6 Merge branch 'test-cases' 2012-12-05 08:56:59 +07:00
Faisal Salman
52897acf24 Fix error build 2012-12-05 08:56:54 +07:00
Faisal Salman
9ccc32ce5a More test cases 2012-12-05 08:53:32 +07:00
Faisal Salman
4a65f1b3f8 Add minifier 2012-12-04 15:57:27 +07:00
Faisal Salman
be4d8a10d1 Turn off travis-ci notification if build success 2012-12-04 15:45:03 +07:00
Faisal Salman
6d183003b3 Fix error build 2012-12-04 15:25:47 +07:00
Faisal Salman
a2b4f6d5c5 Add .travis.yml 2012-12-04 15:08:05 +07:00
Faisal Salman
3f98036d50 Add browser test cases 2012-12-04 14:49:36 +07:00
Faisal Salman
d1d4e0a7a0 Fix Chrome for iOS not detected 2012-12-04 14:04:39 +07:00
Faisalman
3ecb3fbea2 Revise window object detection 2012-11-28 15:32:56 +07:00
Faisal Salman
5cc6bf78a5 Merge pull request #6 from tantalor/master
Fixes nodejs require.
2012-11-28 00:00:51 -08:00
John Tantalo
08c7a84407 added simple test case (mocha) 2012-11-27 20:44:37 -08:00
John Tantalo
ea9d093f0d in strict mode, this is undefined 2012-11-27 19:52:35 -08:00
Faisalman
1f4befe4c3 Fix issue #4 2012-11-26 10:34:37 +07:00
Faisalman
d35fb44066 Distinguish Windows RT from Windows 8 2012-11-15 16:44:31 +07:00
Faisalman
9a6479193a Add Polaris, Tasman, PS Vita, Hurd, AmigaOS, MorphOS 2012-11-12 16:36:11 +07:00
Faisalman
527ba70cf4 Add BB10 new UA pattern & Fix Mobile Safari being caught as just Safari 2012-11-07 18:20:59 +07:00
Faisalman
3fe07487cd Add OS/2, Plan 9, AIX, QNX 2012-11-07 17:03:23 +07:00
Faisalman
8030aa33f7 Add Mosaic, Chimera, Firebird, Phoenix 2012-11-07 16:32:33 +07:00
Faisalman
99251addfc Exclude the letter 'v' from Omniweb version 2012-11-07 15:25:20 +07:00
Faisalman
610cdb84ae Improve Mac OS detection 2012-11-07 15:22:29 +07:00
Faisalman
31b386c636 Add Baidu, Yandex, UCBrowser. Make Apple & RIM as vendor name 2012-11-06 15:53:17 +07:00
Faisalman
b15b48b1bf Rename Dolfin as Dolphin 2012-11-06 14:22:26 +07:00
Faisalman
58fe246468 Add S60 & OviBrowser 2012-11-06 14:18:28 +07:00
Faisalman
e1d3f25bf8 Get device type defined by Firefox 2012-11-06 12:24:12 +07:00
Faisal Salman
4efb13be3e Return unidentified version as undefined 2012-11-02 18:22:06 +07:00
Faisal Salman
bf9fb794d8 Fix issue #3 for old Safari < 3.0 2012-11-02 17:41:29 +07:00
Faisal Salman
df815d4109 Merge pull request #3 from cadecairos/safari-fix
Fix Safari version detection
2012-11-01 23:50:15 -07:00
Christopher De Cairos
6dcee61a0b Fix Safari version detection 2012-11-01 17:11:07 -04:00
Faisal Salman
0288766544 Check if userAgent property is defined 2012-10-23 17:35:24 +07:00
Faisal Salman
7ea79afc2f Fix issue #2 2012-10-22 16:04:23 +07:00
Faisal Salman
59270c8cf7 Some fixes 2012-09-22 00:06:50 +07:00
Faisal Salman
3f92a3cb10 Fix readme & version 2012-09-21 23:21:51 +07:00
Faisal Salman
b9843b4108 Change device properties naming into more appropriate names 2012-09-21 22:59:30 +07:00
Faisal Salman
bdeefcd1fb New identifier for device: type (Mobile, Tablet, Console) 2012-09-20 01:52:23 +07:00
Faisal Salman
bf9c8de5c4 Maps object should contains only data 2012-09-18 00:40:03 +07:00
Faisal Salman
41b3e247a4 Add some Android browsers and some others 2012-09-17 23:11:28 +07:00
Faisal Salman
e5be3083cf Use strict 2012-09-15 14:18:49 +07:00
Faisal Salman
68d124c59c Reorganize the structure of the code 2012-09-15 03:48:30 +07:00
Faisal Salman
33e6fe42d1 Move string checker to outside as strMapper 2012-09-15 02:27:54 +07:00
Faisal Salman
51822ad172 Make sure the result only get constructed once 2012-09-15 02:22:41 +07:00
Faisal Salman
ec40433c5c Fix node.js old example in readme 2012-09-15 01:55:02 +07:00
Faisal Salman
65703e7c1a Move regexMapper & maps outside UAParser class 2012-09-15 01:33:38 +07:00
Faisal Salman
064d52255f Remove optional argument from all getters 2012-09-15 01:15:02 +07:00
Faisal Salman
71b5300080 Replace UAParser.result object with UAParser.getResult() 2012-09-15 01:09:28 +07:00
Faisal Salman
e41fa1c829 Modify mapper method 2012-09-14 05:11:08 +07:00
Faisal Salman
7cd76a3fba Fix Opera, Add match for replacement 2012-09-14 04:23:48 +07:00
Faisal Salman
ac1f92d3c6 Change license paragraph in readme from GPL2 to MIT 2012-09-14 02:42:11 +07:00
Faisal Salman
eaacb14ef2 Modify mapper 2012-09-13 21:22:00 +07:00
Faisalman
7704570581 Add getUA(), improve regxMap(), add Silk browser, add more older versions of Windows, etc 2012-09-13 18:39:12 +07:00
Faisal Salman
9bb8bdb1b0 Add repository to package.json 2012-09-11 03:02:31 +07:00
Faisal Salman
1f21d35ab8 Restore UAParser 2012-08-04 05:14:17 +07:00
Faisalman
d3668b9c2f Update versioning manually 2012-07-30 07:37:20 +07:00
Faisalman
a243a6a7c3 Make undefined undefined & Add Tizen, Haiku, MeeGo, Nokia 2012-07-30 07:30:43 +07:00
Faisalman
9a9844180d Remove duplicated 2012-07-29 04:20:25 +07:00
Faisalman
a84fb2f93a npm revised package.json 2012-07-29 04:14:52 +07:00
8 changed files with 1964 additions and 262 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules/
npm-debug.log

8
.travis.yml Normal file
View File

@@ -0,0 +1,8 @@
language: node_js
node_js:
- 0.8
- 0.6
notifications:
email:
on_success: never
on_failure: always

View File

@@ -1,14 +1,10 @@
{
"title" : "UA-Parser.js",
"name" : "ua-parser-js",
"version" : "0.3.0",
"author" : {
"name" : "Faisal Salman",
"email" : "fyzlman@gmail.com",
"url" : "http://faisalman.com"
},
"description" : "Lightweight JavaScript-based user-agent parser",
"keywords" : [
"title": "UA-Parser.JS",
"name": "ua-parser-js",
"version": "0.5.15",
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
"description": "Lightweight JavaScript-based user-agent string parser",
"keywords": [
"user-agent",
"parser",
"browser",
@@ -16,28 +12,52 @@
"os",
"device"
],
"homepage" : "http://faisalman.github.com/ua-parser-js",
"homepage": "http://github.com/faisalman/ua-parser-js",
"contributors": [
{
"name" : "Faisal Salman",
"email" : "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.js",
"main": "ua-parser",
"scripts": {
"test": "./node_modules/mocha/bin/mocha -R spec",
"pretest": "./node_modules/uglify-js/bin/uglifyjs ua-parser.js > ua-parser.min.js"
},
"devDependencies": {
"mocha": ">= 1.7.1",
"uglify-js": ">= 1.3.4"
},
"repositories": [
{
"type" : "git",
"url" : "https://github.com/faisalman/ua-parser-js.git"
"type": "git",
"url": "https://github.com/faisalman/ua-parser-js.git"
}
],
"licenses" : [
"repository" :
{
"type": "git",
"url": "https://github.com/faisalman/ua-parser-js.git"
},
"licenses": [
{
"type" : "GPLv2",
"url" : "http://www.gnu.org/licenses/gpl-2.0.html"
"type": "GPLv2",
"url": "http://www.gnu.org/licenses/gpl-2.0.html"
},
{
"type" : "MIT",
"url" : "http://www.opensource.org/licenses/mit-license.php"
"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
}
]
],
"engines": {
"node": "*"
},
"directories": {
"lib": "."
},
"files": [
""
],
"repository": "git://github.com/faisalman/ua-parser-js.git"
}

125
readme.md
View File

@@ -1,36 +1,40 @@
# UA-Parser.js
# UA-Parser.JS
JavaScript-based user-agent parser
Lightweight JavaScript-based User-Agent string parser
[![Build Status](https://travis-ci.org/faisalman/ua-parser-js.png)](https://travis-ci.org/faisalman/ua-parser-js)
* Author : Faisalman <<fyzlman@gmail.com>>
* Home : http://faisalman.github.com/ua-parser-js
* Source : https://github.com/faisalman/ua-parser-js
* License : GPLv2 & MIT
* Source : https://github.com/faisalman/ua-parser-js
* License : GPLv2 & MIT
## Features
Get detailed type and version of web browser, layout engine, operating system, and device.
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).
![It's over 9000](https://pbs.twimg.com/media/A9LpEG6CIAA5VrT.jpg)
## Methods
* `getBrowser([uastring])`
* `getDevice([uastring])`
* `getEngine([uastring])`
* `getOS([uastring])`
* `getBrowser()`
* `getDevice()`
* `getEngine()`
* `getOS()`
* `getResult()`
* `getUA()`
* `setUA(uastring)`
## Properties
* `result`
## Example
```html
<script type="text/javascript" src="ua-parser.js"></script>
<script type="text/javascript">
// by default it takes ua string from current browser's window.navigator
console.log(UAParser.result);
var parser = new UAParser();
// by default it takes ua string from current browser's window.navigator.userAgent
console.log(parser.getResult());
/*
/// this will print an object structured like this:
{
@@ -39,10 +43,6 @@ Get detailed type and version of web browser, layout engine, operating system, a
version: "",
major: ""
},
device: {
name: "",
version: ""
},
engine: {
name: "",
version: ""
@@ -52,50 +52,89 @@ Get detailed type and version of web browser, layout engine, operating system, a
version: ""
},
device: {
name: "",
version: ""
model: "",
type: "",
vendor: ""
}
}
*/
// 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";
UAParser.setUA(uastr);
parser.setUA(uastr);
console.log(UAParser.result.browser); // {name: "Chromium", major: "15", version: "15.0.874.106"}
console.log(UAParser.result.engine); // {name: "AppleWebKit", version: "535.2"}
console.log(UAParser.result.os); // {name: "Ubuntu", version: "11.10"}
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: "WebKit", version: "535.2"}
console.log(parser.getResult().os); // {name: "Ubuntu", version: "11.10"}
// let's take another test please
UAParser.setUA("Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)").getOS().name; // prints "OpenBSD"
console.log(parser.setUA("Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)").getBrowser().name); // "Konqueror"
console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"}
</script>
```
## Using requirejs
If you're using requirejs, you can load UA-Parser like any other module.
```js
require(['ua-parser'], function(UAParser) {
var parser = new UAParser();
console.log(parser.getResult());
});
```
## Using node.js
```sh
$ npm install ua-parser-js
```
```js
var parser = require('ua-parser');
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';
var ua1 = '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';
var ua2 = 'Midori/0.2 (X11; Linux; U; cs-cz) WebKit/531.2+';
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); // "WebKit"
```
parser.setUA(ua1).getDevice().name; // prints "PlayBook"
parser.getOS() // prints {name: "RIM Tablet OS", version: "1.0.0"}
parser.getOS(ua2) // prints {name: "Linux", version: undefined}
parser.getOS() // prints {name: "RIM Tablet OS", version: "1.0.0"}
parser.getEngine().name; // prints "AppleWebKit"
## Using jQuery
If you're using jQuery, `$.ua` object will be created automatically based on container's user-agent. Use `$.ua.get()` / `$.ua.set(uastring)` to get/set user-agent. In case you need, `UAParser` constructor is still present in global though.
```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.device); // {vendor: "Motorola", model: "Xoom", type: "tablet"}
console.log($.ua.engine.name); // "Webkit"
console.log($.ua.browser.version); // "4.0"
console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
```
## License
Copyright © 2012 Faisalman <<fyzlman@gmail.com>>
Copyright © 2012-2013 Faisalman <<fyzlman@gmail.com>>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
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
the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

1381
test.js Normal file

File diff suppressed because it is too large Load Diff

31
ua-parser-js.jquery.json Normal file
View File

@@ -0,0 +1,31 @@
{
"title": "UA-Parser.JS",
"name": "ua-parser-js",
"version": "0.5.15",
"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/ua-parser.min.js"
}

View File

@@ -1,235 +1,449 @@
// UA-Parser.js v0.3.0
// Lightweight JavaScript-based user-agent parser
// UA-Parser.JS v0.5.15
// Lightweight JavaScript-based User-Agent string parser
// https://github.com/faisalman/ua-parser-js
//
// Copyright © 2012 Faisalman
// Licensed under GPLv2 & MIT
// Copyright © 2012-2013 Faisalman
// Dual licensed under GPLv2 & MIT
(function () {
function UAParser (uastring) {
(function (global, undefined) {
var ua = uastring || typeof window !== 'undefined' ? window.navigator.userAgent : "";
'use strict';
// regexp mapper
var regxMap = function (ua) {
var result;
var i, j, k, l;
for (i = 1; i < arguments.length; i += 2) {
var regex = arguments[i];
var props = arguments[i + 1];
var isMatchFound = false;
var EMPTY = '',
FUNC = 'function',
UNDEF = 'undefined',
OBJ = 'object',
MAJOR = 'major',
MODEL = 'model',
NAME = 'name',
TYPE = 'type',
VENDOR = 'vendor',
VERSION = 'version',
CONSOLE = 'console',
MOBILE = 'mobile',
TABLET = 'tablet';
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 === UNDEF) {
result = {};
for (k = 0; k < props.length; k++) {
if (typeof props[k] === OBJ) {
result[props[k][0]] = undefined;
} else {
result[props[k]] = undefined;
}
}
if (this.getUA().toString() === EMPTY) {
return result;
}
}
// try matching uastring with regexes
for (j = 0; j < regex.length; j++) {
var match = regex[j].exec(ua);
//console.log(match);
if (!!match) {
result = {};
l = 1;
l = regex[j].exec(this.getUA());
if (!!l) {
for (k = 0; k < props.length; k++) {
if (typeof props[k] === 'object' && props[k].length === 2) {
m = l[k + 1];
if (typeof props[k] === OBJ && props[k].length === 2) {
result[props[k][0]] = props[k][1];
l -= 1;
} else if (typeof props[k] === 'object' && props[k].length === 3) {
result[props[k][0]] = (!!match[k + l]) ? match[k + l].replace(props[k][1], props[k][2]) : undefined;
} else if (typeof props[k] === OBJ && props[k].length === 3) {
if (typeof props[k][1] === FUNC && !(props[k][1].exec && props[k][1].test)) {
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]] = (!!match[k + l]) ? match[k + l] : undefined;
result[props[k]] = m ? m : undefined;
}
}
isMatchFound = true;
break;
}
}
if (!isMatchFound) {
result = {};
for (k in props) {
if (props.hasOwnProperty(k)) {
if (typeof props[k] == 'object') {
result[props[k][0]] = undefined;
} else {
result[props[k]] = undefined;
}
}
}
} else {
return result;
}
if(!!l) break; // break the loop immediately if match found
}
return result;
};
},
var mapper = {
os : {
win: function (str, match) {
switch (match.toLowerCase()) {
case 'nt 5.0':
return '2000';
case 'nt 5.1':
case 'nt 5.2':
return 'XP';
case 'nt 6.0':
return 'Vista';
case 'nt 6.1':
return '7';
case 'nt 6.2':
return '8';
default:
return match;
};
string : function (str, map) {
for (var i in map) {
if (map.hasOwnProperty(i)) {
if (typeof map[i] === OBJ && map[i].length > 0) {
for (var j = 0; j < map[i].length; j++) {
if (str.toLowerCase().indexOf(map[i][j].toLowerCase()) !== -1) {
return (i.toString() === UNDEF) ? undefined : i;
}
}
} else if (str.toLowerCase().indexOf(map[i].toLowerCase()) !== -1) {
return (i.toString() === UNDEF) ? undefined : i;
}
}
}
return str;
}
};
var maps = {
browser : {
oldsafari : {
major : {
'1' : ['/85', '/125', '/312'],
'2' : ['/412', '/416', '/417', '/419'],
'undefined' : '/'
},
version : {
'1.0' : '/85',
'1.2' : '/125',
'1.3' : '/312',
'2.0' : '/412',
'2.0.2' : '/416',
'2.0.3' : '/417',
'2.0.4' : '/419',
'undefined' : '/'
}
}
},
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'
}
}
}
};
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\sbrowser|iemobile|slimbrowser|baidubrowser)[\/\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], [
/applewebkit.+?(mobile\s?safari|safari)((\/[\w\.]+))/i // Safari < 3.0
], [NAME, [MAJOR, mapper.string, maps.browser.oldsafari.major], [VERSION, mapper.string, maps.browser.oldsafari.version]], [
/(konqueror)\/((\d+)?[\w\.]+)/i, // Konqueror
/(applewebkit|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|playstation)\s([wids3portablev]+)/i // Nintendo/Playstation
], [VENDOR, MODEL, [TYPE, CONSOLE]], [
/(sprint\s(\w+))/i // Sprint Phones
], [[VENDOR, mapper.string, maps.device.sprint.vendor], [MODEL, mapper.string, maps.device.sprint.model], [TYPE, MOBILE]], [
/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC
/(zte)-(\w+)*/i, // ZTE
/(alcatel|geeksphone|huawei|lenovo|nexian|panasonic|;\ssony)[_\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]], [
/(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)\/([\w\.]+)/i, // KHTML
/(tasman)\s([\w\.]+)/i, // Tasman
/(links)\s\(([\w\.]+)/i, // Links
/(icab)[\/\s]([2-3]\.[\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.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
/\((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([wids3portablev]+)/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(\w*bsd|dragonfly)\s?([\w\.]+)*/i // FreeBSD/NetBSD/OpenBSD/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]
]
};
var UAParser = function UAParser (uastring) {
var ua = uastring || ((global && global.navigator && global.navigator.userAgent) ? global.navigator.userAgent : EMPTY);
this.getBrowser = function () {
return mapper.regex.apply(this, regexes.browser);
};
this.getBrowser = function (uastring) {
return regxMap(uastring || ua, [
// Mixed
/(kindle)\/((\d+)?[\w\.]+)/i, // Kindle
/(lunascape|maxthon|netfront|jasmine)[\/\s]?((\d+)?[\w\.]+)/i, // Lunascape/Maxthon/Netfront/Jasmine
// Presto based
/(opera\smini)\/((\d+)?[\w\.-]+)/i, // Opera Mini
/(opera\smobi)\/((\d+)?[\w\.-]+)/i, // Opera Mobile
/(opera).*\/((\d+)?[\w\.]+)/i, // Opera
// 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)\/((\d+)?[\w\.]+)/i, // Chromium/Flock/RockMelt/Midori/Epiphany
/(chrome|omniweb|arora|dolfin)\/((\d+)?[\w\.]+)/i, // Chrome/OmniWeb/Arora/Dolphin
], ['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|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)[\/\s]?((\d+)?[\w\.]+)/i, // Lynx/Dillo/iCab
], ['name', 'version', 'major']);
this.getDevice = function () {
return mapper.regex.apply(this, regexes.device);
};
this.getEngine = function (uastring) {
return regxMap(uastring || ua, [
/(presto)\/([\w\.]+)/i, // Presto
/([aple]*webkit|trident)\/([\w\.]+)/i, // Webkit/Trident
/(khtml)\/([\w\.]+)/i // KHTML
], ['name', 'version'], [
/rv\:([\w\.]+).*(gecko)/i // Gecko
], ['version', 'name']);
this.getEngine = function () {
return mapper.regex.apply(this, regexes.engine);
};
this.getOS = function (uastring) {
return regxMap(uastring || ua, [
// Windows based
/(windows\sphone\sos|windows)\s+([\w\.\s]+)*/i, // Windows
], ['name', ['version', /(nt\s[\d\.]+)/gi, mapper.os.win]], [
// Mobile/Embedded OS
/(blackberry).+version\/([\w\.]+)/i, // Blackberry
/(android|symbianos|symbos|webos|palm\os|qnx|bada|rim\stablet\sos)[\/\s-]?([\w\.]+)*/i,
// Android/Symbian/WebOS/Palm/QNX/Bada/RIM
/(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]+)/i // Chromium OS
], [['name', 'Chromium OS'], 'version'],[
// Solaris
/sunos\s?([\w\.\s]+)*/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', /.+/g, 'iOS'], ['version', /_/g, '.']], [
/(mac\sos)\sx\s([\w\s\.]+)/i, // Mac OS
], ['name', ['version', /_/g, '.']], [
// Other
/(macintosh|unix|minix|beos)[\/\s]?()*/i
], ['name', 'version']);
this.getOS = function () {
return mapper.regex.apply(this, regexes.os);
};
this.getDevice = function (uastring) {
return regxMap(uastring || ua, [
/\((ip[honead]+|playbook);/i, // iPod/iPhone/iPad/PlayBook
/(blackberry)[\s-]?(\w+)/i, // BlackBerry
/(blackberry|benq|nokia|palm(?=\-)|sonyericsson|acer|asus|dell|nexus|zte)[\s_-]?([\w-]+)*/i,
// BenQ/Nokia/Palm/Sony-Ericsson/Acer/Asus/Dell/Nexus/ZTE
/(hp)\s([\w\s]+)/i, // HP iPAQ
/(hp).+(touchpad)/i, // HP TouchPad
/(kindle)\/([\w\.]+)/i, // Kindle
/(lg)[e;\s-]+(\w+)*/i, // LG
/(nintendo|playstation)\s([wids3portable]+)/i // Nintendo/Playstation
], ['name', 'version'], [
/(htc)[;_\s-]+([\w\s]+(?=\))|[\w]+)*/i, // HTC
/(zte)-([\w]+)*/i
], ['name', ['version', /_/g, ' ']], [
/\s(milestone|mz601|droid[2x]?|xoom)[globa\s]*\sbuild\//i, // Motorola
/mot[\s-]?(\w+)*/i
], [['name', 'Motorola'], 'version'], [
/(s[cgp]h-\w+|gt-\w+|galaxy\snexus)/i, // Samsung
/sam[sung]*[\s-]*(\w+-?[\w-]*)*/i,
/sec-(sgh\w+)/i
], [['name', 'Samsung'], 'version'], [
/(transfo[prime\s]{4,10}\s\w+|(?:android).*eeepc)/i // Asus
], [['name', 'Asus'], 'version'], [
/sie-(\w+)*/i // Siemens
], [['name', 'Siemens'], 'version']);
};
this.setUA = function (uastring) {
ua = uastring || ua;
this.result = {
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);
};
var parser = new UAParser();
// 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 = parser;
// check js environment
if (typeof exports !== UNDEF && !/\[object\s[DOM]*Window\]/.test(global.toString())) {
// nodejs env
if (typeof module !== UNDEF && module.exports) {
exports = module.exports = UAParser;
}
exports.UAParser = parser;
exports.UAParser = UAParser;
} else if (typeof define === FUNC && define.amd) {
// requirejs env
define(function() {
return UAParser;
});
} else {
this['UAParser'] = parser;
// browser env
global.UAParser = UAParser;
// jQuery specific
if (typeof global.jQuery !== UNDEF) {
var parser = new UAParser();
global.jQuery.ua = parser.getResult();
global.jQuery.ua.get = function() {
return parser.getUA();
};
global.jQuery.ua.set = function(uastring) {
parser.setUA(uastring);
var result = parser.getResult();
for (var prop in result) {
global.jQuery.ua[prop] = result[prop];
}
};
}
}
})();
})(this);

7
ua-parser.min.js vendored Normal file

File diff suppressed because one or more lines are too long