express-useragent
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -7,3 +7,3 @@ /** | ||
* @package express-useragent | ||
* @version 0.0.3 | ||
* @version 0.0.4 | ||
* @copyright Copyright (c) 2009-2012 - All rights reserved. | ||
@@ -10,0 +10,0 @@ * @license MIT License |
@@ -7,3 +7,3 @@ /** | ||
* @package express-useragent | ||
* @version 0.0.3 | ||
* @version 0.0.4 | ||
* @copyright Copyright (c) 2009-2011 - All rights reserved. | ||
@@ -49,3 +49,4 @@ * @license MIT License | ||
iPad: /\(iPad.*os (\d+)[._](\d+)/i, | ||
iPhone: /\(iPhone.*os (\d+)[._](\d+)/i | ||
iPhone: /\(iPhone.*os (\d+)[._](\d+)/i, | ||
Bada: /Bada\/(\d+)\.(\d+)/i | ||
}; | ||
@@ -62,3 +63,4 @@ this._Platform = { | ||
Android: /android/i, | ||
Blackberry: /blackberry/i | ||
Blackberry: /blackberry/i, | ||
Samsung: /samsung/i | ||
}; | ||
@@ -84,2 +86,4 @@ this.Agent = {}; | ||
isMac : false, | ||
isBada : false, | ||
isSamsung : false, | ||
Browser : 'unknown', | ||
@@ -170,7 +174,5 @@ Version : 'unknown', | ||
this.Agent.isWindows = true; | ||
this.Agent.isDesktop = true; | ||
return 'Windows Vista'; | ||
case this._OS.Windows7.test(string): | ||
this.Agent.isWindows = true; | ||
this.Agent.isDesktop = true; | ||
return 'Windows 7'; | ||
@@ -182,3 +184,2 @@ case this._OS.Windows2003.test(string): | ||
this.Agent.isWindows = true; | ||
this.Agent.isDesktop = true; | ||
return 'Windows XP'; | ||
@@ -190,3 +191,2 @@ case this._OS.Windows2000.test(string): | ||
this.Agent.isLinux = true; | ||
this.Agent.isDesktop = true; | ||
return 'Linux'; | ||
@@ -208,2 +208,5 @@ case this._OS.Wii.test(string): | ||
return string.match(this._OS.iPhone)[0].replace('_', '.'); | ||
case this._OS.Bada.test(string): | ||
this.Agent.isBada = true; | ||
return 'Bada'; | ||
default: | ||
@@ -220,4 +223,6 @@ return 'unknown'; | ||
case this._Platform.Android.test(string): | ||
this.Agent.isAndroid = true; | ||
return "Android"; | ||
case this._Platform.Blackberry.test(string): | ||
this.Agent.isBlackberry = true; | ||
return "Blackberry"; | ||
@@ -231,7 +236,13 @@ case this._Platform.Linux.test(string): | ||
case this._Platform.iPad.test(string): | ||
this.Agent.isiPad = true; | ||
return "iPad"; | ||
case this._Platform.iPod.test(string): | ||
this.Agent.isiPod = true; | ||
return "iPod"; | ||
case this._Platform.iPhone.test(string): | ||
this.Agent.isiPhone = true; | ||
return "iPhone"; | ||
case this._Platform.Samsung.test(string): | ||
this.Agent.isiSamsung = true; | ||
return "Samsung"; | ||
default: | ||
@@ -250,10 +261,40 @@ return 'unknown'; | ||
this.testMobile = function testMobile() { | ||
var ua = this; | ||
switch (true) { | ||
case this.Agent.isWindows: | ||
case this.Agent.isLinux: | ||
case this.Agent.isMac: | ||
this.Agent.isDesktop = true; | ||
break; | ||
case this.Agent.isAndroid: | ||
case this.Agent.isSamsung: | ||
this.Agent.isMobile = true; | ||
this.Agent.isDesktop = false; | ||
break; | ||
default: | ||
} | ||
switch (true) { | ||
case this.Agent.isiPad: | ||
case this.Agent.isiPod: | ||
case this.Agent.isiPhone: | ||
case this.Agent.isBada: | ||
case this.Agent.isBlackberry: | ||
case this.Agent.isAndroid: | ||
this.Agent.isMobile = true; | ||
this.Agent.isDesktop = false; | ||
break; | ||
default: | ||
} | ||
// console.log(this); | ||
}; | ||
this.parse = function parse(source) { | ||
var ua = new UserAgent(); | ||
ua.Agent.source = source.replace(/^\s*/, '').replace(/\s*$/, ''); | ||
ua.Agent.OS = ua.getOS(ua.Agent.source); | ||
ua.Agent.Platform = ua.getPlatform(ua.Agent.source); | ||
ua.Agent.Browser = ua.getBrowser(ua.Agent.source); | ||
ua.Agent.Version = ua.getBrowserVersion(ua.Agent.source); | ||
ua.Agent.OS = ua.getOS(ua.Agent.source); | ||
ua.Agent.Platform = ua.getPlatform(ua.Agent.source); | ||
ua.testMobile(); | ||
return ua.Agent; | ||
@@ -267,6 +308,7 @@ }; | ||
ua.Agent.source = source.replace(/^\s*/, '').replace(/\s*$/, ''); | ||
ua.Agent.OS = ua.getOS(ua.Agent.source); | ||
ua.Agent.Platform = ua.getPlatform(ua.Agent.source); | ||
ua.Agent.Browser = ua.getBrowser(ua.Agent.source); | ||
ua.Agent.Version = ua.getBrowserVersion(ua.Agent.source); | ||
ua.Agent.OS = ua.getOS(ua.Agent.source); | ||
ua.Agent.Platform = ua.getPlatform(ua.Agent.source); | ||
ua.testMobile(); | ||
req.useragent = ua.Agent; | ||
@@ -273,0 +315,0 @@ res.locals("useragent", ua.Agent); |
{ | ||
"name": "express-useragent", | ||
"description": "ExpressJS user-agent middleware", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"homepage": "https://github.com/biggora/express-useragent/", | ||
@@ -27,5 +27,9 @@ "repository": { | ||
"devDependencies": { | ||
"connect": "1.7.1", | ||
"express": "2.5.0" | ||
"connect": ">= 1.7.1 < 2.0.0", | ||
"express": ">= 2.5.0 < 3.0.0", | ||
"nodeunit": ">=0.5.4" | ||
}, | ||
"scripts": { | ||
"test": "nodeunit tests/browsers.js" | ||
} | ||
} |
@@ -7,3 +7,3 @@ /** | ||
* @package express-useragent | ||
* @version 0.0.3 | ||
* @version 0.0.4 | ||
* @copyright Copyright (c) 2009-2012 - All rights reserved. | ||
@@ -10,0 +10,0 @@ * @license MIT License |
@@ -7,3 +7,3 @@ /** | ||
* @package express-useragent | ||
* @version 0.0.3 | ||
* @version 0.0.4 | ||
* @copyright Copyright (c) 2009-2012 - All rights reserved. | ||
@@ -10,0 +10,0 @@ * @license MIT License |
@@ -7,3 +7,3 @@ /** | ||
* @package express-useragent | ||
* @version 0.0.3 | ||
* @version 0.0.4 | ||
* @copyright Copyright (c) 2009-2012 - All rights reserved. | ||
@@ -10,0 +10,0 @@ * @license MIT License |
33710
8
813
3