express-useragent
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -7,3 +7,3 @@ /** | ||
* @package express-useragent | ||
* @version 0.0.8 | ||
* @version 0.0.9 | ||
* @copyright Copyright (c) 2009-2011 - All rights reserved. | ||
@@ -17,6 +17,6 @@ * @license MIT License | ||
var UserAgent = function() { | ||
this.version = '0.0.8'; | ||
this.version = '0.0.9'; | ||
this._Versions = { | ||
Firefox: /firefox\/([\d\w\.\-]+)/i, | ||
IE: /msie\s([\d\.]+[\d])/i, | ||
IE: /msie\s([\d\.]+[\d])|trident\/\d+\.\d+;\s+[rv:]+(\d+\.\d)/i, | ||
Chrome: /chrome\/([\d\w\.\-]+)/i, | ||
@@ -43,3 +43,3 @@ Safari: /version\/([\d\w\.\-]+)/i, | ||
Safari: /safari/i, | ||
IE: /msie/i, | ||
IE: /msie|trident/i, | ||
Opera: /opera/i, | ||
@@ -91,2 +91,3 @@ PS3: /playstation 3/i, | ||
isIE : false, | ||
isIECompatibilityMode : false, | ||
isSafari : false, | ||
@@ -110,2 +111,3 @@ isFirefox : false, | ||
isBot : false, | ||
isAndroidTablet : false, | ||
Browser : 'unknown', | ||
@@ -191,3 +193,3 @@ Version : 'unknown', | ||
if (this._Versions.IE.test(string)) { | ||
return RegExp.$1; | ||
return RegExp.$2? RegExp.$2:RegExp.$1; | ||
} | ||
@@ -325,3 +327,27 @@ break; | ||
}; | ||
this.testCompatibilityMode = function() { | ||
var ua = this; | ||
if(this.Agent.isIE){ | ||
if(/Trident\/(\d)\.0/i.test(ua.Agent.source)){ | ||
var tridentVersion = parseInt(RegExp.$1,10); | ||
var version = parseInt(ua.Agent.Version,10); | ||
if(version === 7 && tridentVersion === 6){ | ||
ua.Agent.isIECompatibilityMode = true; | ||
ua.Agent.Version = 10.0; | ||
} | ||
if(version === 7 && tridentVersion === 5){ | ||
ua.Agent.isIECompatibilityMode = true; | ||
ua.Agent.Version = 9.0; | ||
} | ||
if(version === 7 && tridentVersion === 4){ | ||
ua.Agent.isIECompatibilityMode = true; | ||
ua.Agent.Version = 8.0; | ||
} | ||
} | ||
} | ||
}; | ||
this.reset = function reset() { | ||
@@ -379,7 +405,14 @@ var ua = this; | ||
var ua = this; | ||
if(/googlebot|gurujibot|yandexbot|slurp|msnbot|bingbot/i.test(key)) { | ||
if(/googlebot|gurujibot|yandexbot|slurp|msnbot|bingbot/i.test(ua.Agent.source)) { | ||
ua.Agent.isBot = true; | ||
} | ||
}; | ||
this.testAndriodTablet = function testAndriodTablet() { | ||
var ua = this; | ||
if(ua.Agent.isAndroid && !/mobile/i.test(ua.Agent.source)) { | ||
ua.Agent.isAndroidTablet = true; | ||
} | ||
}; | ||
this.parse = function parse(source) { | ||
@@ -394,2 +427,4 @@ var ua = new UserAgent(); | ||
ua.testMobile(); | ||
ua.testAndriodTablet(); | ||
ua.testCompatibilityMode(); | ||
return ua.Agent; | ||
@@ -411,2 +446,4 @@ }; | ||
ua.testMobile(); | ||
ua.testAndriodTablet(); | ||
ua.testCompatibilityMode(); | ||
req.useragent = ua.Agent; | ||
@@ -421,2 +458,2 @@ res.locals({"useragent" : ua.Agent}); | ||
exports = module.exports = new UserAgent(); | ||
exports = module.exports = new UserAgent(); |
{ | ||
"name": "express-useragent", | ||
"description": "ExpressJS user-agent middleware", | ||
"version": "0.0.8", | ||
"description": "ExpressJS/Connect user-agent middleware exposing", | ||
"version": "0.0.9", | ||
"homepage": "https://github.com/biggora/express-useragent/", | ||
@@ -6,0 +6,0 @@ "repository": { |
[![build status](https://secure.travis-ci.org/biggora/express-useragent.png)](http://travis-ci.org/biggora/express-useragent) | ||
[![NPM version](https://badge.fury.io/js/express-useragent.png)](http://badge.fury.io/js/express-useragent) | ||
# Middleware exposing user-agent for [NodeJS](http://nodejs.org/) | ||
@@ -3,0 +4,0 @@ |
@@ -596,2 +596,231 @@ /** | ||
test.done(); | ||
}; | ||
exports['Windows 7 IE 10.6'] = function(test) { | ||
var s = 'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0'; | ||
var a = ua.parse(s); | ||
test.ok(!a.isMobile, 'Mobile'); | ||
test.ok(!a.isiPad, 'iPad'); | ||
test.ok(!a.isiPod, 'iPod'); | ||
test.ok(!a.isiPhone, 'iPhone'); | ||
test.ok(!a.isAndroid, 'Android'); | ||
test.ok(!a.isBlackberry, 'Blackberry'); | ||
test.ok(!a.isOpera, 'Opera'); | ||
test.ok(a.isIE, 'IE'); | ||
test.ok(!a.isSafari, 'Safari'); | ||
test.ok(!a.isFirefox, 'Firefox'); | ||
test.ok(!a.isWebkit, 'Webkit'); | ||
test.ok(!a.isChrome, 'Chrome'); | ||
test.ok(!a.isKonqueror, 'Konqueror'); | ||
test.ok(a.isDesktop, 'Desktop'); | ||
test.ok(a.isWindows, 'Windows'); | ||
test.ok(!a.isLinux, 'Linux'); | ||
test.ok(!a.isMac, 'Mac'); | ||
test.equal(a.Version, '10.6'); | ||
test.done(); | ||
}; | ||
exports['Windows 7 IE 11.0'] = function(test) { | ||
var s = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko'; | ||
var a = ua.parse(s); | ||
test.ok(!a.isMobile, 'Mobile'); | ||
test.ok(!a.isiPad, 'iPad'); | ||
test.ok(!a.isiPod, 'iPod'); | ||
test.ok(!a.isiPhone, 'iPhone'); | ||
test.ok(!a.isAndroid, 'Android'); | ||
test.ok(!a.isBlackberry, 'Blackberry'); | ||
test.ok(!a.isOpera, 'Opera'); | ||
test.ok(a.isIE, 'IE'); | ||
test.ok(!a.isSafari, 'Safari'); | ||
test.ok(!a.isFirefox, 'Firefox'); | ||
test.ok(!a.isWebkit, 'Webkit'); | ||
test.ok(!a.isChrome, 'Chrome'); | ||
test.ok(!a.isKonqueror, 'Konqueror'); | ||
test.ok(a.isDesktop, 'Desktop'); | ||
test.ok(a.isWindows, 'Windows'); | ||
test.ok(!a.isLinux, 'Linux'); | ||
test.ok(!a.isMac, 'Mac'); | ||
test.equal(a.Version, '11.0'); | ||
test.done(); | ||
}; | ||
exports['Windows XP IE 8.0'] = function(test) { | ||
var s = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)'; | ||
var a = ua.parse(s); | ||
test.ok(!a.isMobile, 'Mobile'); | ||
test.ok(!a.isiPad, 'iPad'); | ||
test.ok(!a.isiPod, 'iPod'); | ||
test.ok(!a.isiPhone, 'iPhone'); | ||
test.ok(!a.isAndroid, 'Android'); | ||
test.ok(!a.isBlackberry, 'Blackberry'); | ||
test.ok(!a.isOpera, 'Opera'); | ||
test.ok(a.isIE, 'IE'); | ||
test.ok(!a.isSafari, 'Safari'); | ||
test.ok(!a.isFirefox, 'Firefox'); | ||
test.ok(!a.isWebkit, 'Webkit'); | ||
test.ok(!a.isChrome, 'Chrome'); | ||
test.ok(!a.isKonqueror, 'Konqueror'); | ||
test.ok(a.isDesktop, 'Desktop'); | ||
test.ok(a.isWindows, 'Windows'); | ||
test.ok(!a.isLinux, 'Linux'); | ||
test.ok(!a.isMac, 'Mac'); | ||
test.equal(a.Version, '8.0'); | ||
test.done(); | ||
}; | ||
exports['Windows XP IE 8.0 - Compatibility mode'] = function(test) { | ||
var s = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0)'; | ||
var a = ua.parse(s); | ||
test.ok(!a.isMobile, 'Mobile'); | ||
test.ok(!a.isiPad, 'iPad'); | ||
test.ok(!a.isiPod, 'iPod'); | ||
test.ok(!a.isiPhone, 'iPhone'); | ||
test.ok(!a.isAndroid, 'Android'); | ||
test.ok(!a.isBlackberry, 'Blackberry'); | ||
test.ok(!a.isOpera, 'Opera'); | ||
test.ok(a.isIE, 'IE'); | ||
test.ok(!a.isSafari, 'Safari'); | ||
test.ok(!a.isFirefox, 'Firefox'); | ||
test.ok(!a.isWebkit, 'Webkit'); | ||
test.ok(!a.isChrome, 'Chrome'); | ||
test.ok(!a.isKonqueror, 'Konqueror'); | ||
test.ok(a.isDesktop, 'Desktop'); | ||
test.ok(a.isWindows, 'Windows'); | ||
test.ok(!a.isLinux, 'Linux'); | ||
test.ok(!a.isMac, 'Mac'); | ||
test.equal(a.Version, '8.0'); | ||
test.ok(a.isIECompatibilityMode); | ||
test.done(); | ||
}; | ||
exports['Windows XP IE 10.0'] = function(test) { | ||
var s = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2)'; | ||
var a = ua.parse(s); | ||
test.ok(!a.isMobile, 'Mobile'); | ||
test.ok(!a.isiPad, 'iPad'); | ||
test.ok(!a.isiPod, 'iPod'); | ||
test.ok(!a.isiPhone, 'iPhone'); | ||
test.ok(!a.isAndroid, 'Android'); | ||
test.ok(!a.isBlackberry, 'Blackberry'); | ||
test.ok(!a.isOpera, 'Opera'); | ||
test.ok(a.isIE, 'IE'); | ||
test.ok(!a.isSafari, 'Safari'); | ||
test.ok(!a.isFirefox, 'Firefox'); | ||
test.ok(!a.isWebkit, 'Webkit'); | ||
test.ok(!a.isChrome, 'Chrome'); | ||
test.ok(!a.isKonqueror, 'Konqueror'); | ||
test.ok(a.isDesktop, 'Desktop'); | ||
test.ok(a.isWindows, 'Windows'); | ||
test.ok(!a.isLinux, 'Linux'); | ||
test.ok(!a.isMac, 'Mac'); | ||
test.equal(a.Version, '10.0'); | ||
test.ok(!a.isIECompatibilityMode); | ||
test.done(); | ||
}; | ||
exports['Windows XP IE 10.0 - Compatibility mode'] = function(test) { | ||
var s = 'Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0)'; | ||
var a = ua.parse(s); | ||
test.ok(!a.isMobile, 'Mobile'); | ||
test.ok(!a.isiPad, 'iPad'); | ||
test.ok(!a.isiPod, 'iPod'); | ||
test.ok(!a.isiPhone, 'iPhone'); | ||
test.ok(!a.isAndroid, 'Android'); | ||
test.ok(!a.isBlackberry, 'Blackberry'); | ||
test.ok(!a.isOpera, 'Opera'); | ||
test.ok(a.isIE, 'IE'); | ||
test.ok(!a.isSafari, 'Safari'); | ||
test.ok(!a.isFirefox, 'Firefox'); | ||
test.ok(!a.isWebkit, 'Webkit'); | ||
test.ok(!a.isChrome, 'Chrome'); | ||
test.ok(!a.isKonqueror, 'Konqueror'); | ||
test.ok(a.isDesktop, 'Desktop'); | ||
test.ok(a.isWindows, 'Windows'); | ||
test.ok(!a.isLinux, 'Linux'); | ||
test.ok(!a.isMac, 'Mac'); | ||
test.equal(a.Version, '10.0'); | ||
test.ok(a.isIECompatibilityMode); | ||
test.done(); | ||
}; | ||
exports['Windows XP IE 7.0 - Compatibility mode (invalid mode)'] = function(test) { | ||
var s = 'Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/1.0)'; | ||
var a = ua.parse(s); | ||
test.ok(!a.isMobile, 'Mobile'); | ||
test.ok(!a.isiPad, 'iPad'); | ||
test.ok(!a.isiPod, 'iPod'); | ||
test.ok(!a.isiPhone, 'iPhone'); | ||
test.ok(!a.isAndroid, 'Android'); | ||
test.ok(!a.isBlackberry, 'Blackberry'); | ||
test.ok(!a.isOpera, 'Opera'); | ||
test.ok(a.isIE, 'IE'); | ||
test.ok(!a.isSafari, 'Safari'); | ||
test.ok(!a.isFirefox, 'Firefox'); | ||
test.ok(!a.isWebkit, 'Webkit'); | ||
test.ok(!a.isChrome, 'Chrome'); | ||
test.ok(!a.isKonqueror, 'Konqueror'); | ||
test.ok(a.isDesktop, 'Desktop'); | ||
test.ok(a.isWindows, 'Windows'); | ||
test.ok(!a.isLinux, 'Linux'); | ||
test.ok(!a.isMac, 'Mac'); | ||
test.equal(a.Version, '7.0'); | ||
test.ok(!a.isIECompatibilityMode); | ||
test.done(); | ||
}; | ||
exports['Windows XP IE 9.0 - Compatibility mode'] = function(test) { | ||
var s = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)'; | ||
var a = ua.parse(s); | ||
test.ok(!a.isMobile, 'Mobile'); | ||
test.ok(!a.isiPad, 'iPad'); | ||
test.ok(!a.isiPod, 'iPod'); | ||
test.ok(!a.isiPhone, 'iPhone'); | ||
test.ok(!a.isAndroid, 'Android'); | ||
test.ok(!a.isBlackberry, 'Blackberry'); | ||
test.ok(!a.isOpera, 'Opera'); | ||
test.ok(a.isIE, 'IE'); | ||
test.ok(!a.isSafari, 'Safari'); | ||
test.ok(!a.isFirefox, 'Firefox'); | ||
test.ok(!a.isWebkit, 'Webkit'); | ||
test.ok(!a.isChrome, 'Chrome'); | ||
test.ok(!a.isKonqueror, 'Konqueror'); | ||
test.ok(a.isDesktop, 'Desktop'); | ||
test.ok(a.isWindows, 'Windows'); | ||
test.ok(!a.isLinux, 'Linux'); | ||
test.ok(!a.isMac, 'Mac'); | ||
test.equal(a.Version, '9.0'); | ||
test.ok(a.isIECompatibilityMode); | ||
test.done(); | ||
}; |
54452
12
1318
164