Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-useragent

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-useragent - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

.jshintrc

36

index.js

@@ -7,3 +7,3 @@ /**

* @package express-useragent
* @version 0.0.8
* @version 0.1.8
* @copyright Copyright (c) 2009-2012 - All rights reserved.

@@ -15,3 +15,33 @@ * @license MIT License

*/
module.exports = require('./lib/express-useragent');
var UserAgent = require('./lib/express-useragent').UserAgent;
module.exports = new UserAgent();
module.exports.UserAgent = UserAgent;
module.exports.express = function () {
return function (req, res, next) {
var source = req.headers['user-agent'] || '',
ua = new UserAgent();
if (typeof source === 'undefined') {
source = "unknown";
}
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.testNginxGeoIP(req.headers);
ua.testBot();
ua.testMobile();
ua.testAndroidTablet();
ua.testTablet();
ua.testCompatibilityMode();
ua.testSilk();
ua.testKindleFire();
req.useragent = ua.Agent;
if ('function' === typeof res.locals) {
res.locals({useragent: ua.Agent});
} else {
res.locals.useragent = ua.Agent;
}
next();
};
};

1050

lib/express-useragent.js

@@ -1,555 +0,530 @@

/**
*
* @revision $Id: express-useragent.js 2012-03-24 16:21:10 Aleksey $
* @created 2011-12-10 17:19:10
* @category Express Helpers
* @package express-useragent
* @version 0.1.6
* @copyright Copyright (c) 2009-2011 - All rights reserved.
* @license MIT License
* @author Alexey Gordeyev IK <aleksej@gordejev.lv>
* @link http://www.gordejev.lv
*
/*!
* express-useragent.js v0.1.8 (https://github.com/biggora/express-useragent/)
* Copyright 2011-2015 Alexey Gordeyev
* Licensed under MIT (https://github.com/biggora/express-useragent/blob/master/LICENSE)
*/
(function(exports) {
'use strict';
var UserAgent = function() {
this.version = '0.1.6';
this._Versions = {
Firefox: /firefox\/([\d\w\.\-]+)/i,
IE: /msie\s([\d\.]+[\d])|trident\/\d+\.\d+;.*[rv:]+(\d+\.\d)/i,
Chrome: /chrome\/([\d\w\.\-]+)/i,
Chromium: /(?:chromium|crios)\/([\d\w\.\-]+)/i,
Safari: /version\/([\d\w\.\-]+)/i,
Opera: /version\/([\d\w\.\-]+)/i,
Ps3: /([\d\w\.\-]+)\)\s*$/i,
Psp: /([\d\w\.\-]+)\)?\s*$/i,
Amaya: /amaya\/([\d\w\.\-]+)/i,
SeaMonkey: /seamonkey\/([\d\w\.\-]+)/i,
OmniWeb: /omniweb\/v([\d\w\.\-]+)/i,
Flock: /flock\/([\d\w\.\-]+)/i,
Epiphany: /epiphany\/([\d\w\.\-]+)/i,
WinJs: /msapphost\/([\d\w\.\-]+)/i
};
this._Browsers = {
Amaya: /amaya/i,
Konqueror: /konqueror/i,
Epiphany: /epiphany/i,
SeaMonkey: /seamonkey/i,
Flock: /flock/i,
OmniWeb: /omniweb/i,
Chromium: /chromium|crios/i,
Chrome: /chrome/i,
Safari: /safari/i,
IE: /msie|trident/i,
Opera: /opera/i,
PS3: /playstation 3/i,
PSP: /playstation portable/i,
Firefox: /firefox/i,
WinJs: /msapphost/i
};
this._OS = {
Windows10: /windows nt 10\.0/i,
Windows81: /windows nt 6\.3/i,
Windows8: /windows nt 6\.2/i,
Windows7: /windows nt 6\.1/i,
UnknownWindows: /windows nt 6\.\d+/i,
WindowsVista: /windows nt 6\.0/i,
Windows2003: /windows nt 5\.2/i,
WindowsXP: /windows nt 5\.1/i,
Windows2000: /windows nt 5\.0/i,
WindowsPhone8: /windows phone 8\./,
OSX: /os x (\d+)[._](\d+)/i,
Mac: /os x/i,
Linux: /linux/i,
Linux64: /linux x86\_64/i,
ChromeOS: /cros/i,
Wii: /wii/i,
PS3: /playstation 3/i,
PSP: /playstation portable/i,
iPad: /\(iPad.*os (\d+)[._](\d+)/i,
iPhone: /\(iPhone.*os (\d+)[._](\d+)/i,
Bada: /Bada\/(\d+)\.(\d+)/i,
Curl: /curl\/(\d+)\.(\d+)\.(\d+)/i
};
this._Platform = {
Windows: /windows nt/i,
WindowsPhone: /windows phone/i,
Mac: /macintosh/i,
Linux: /linux/i,
Wii: /wii/i,
Playstation: /playstation/i,
iPad: /ipad/i,
iPod: /ipod/i,
iPhone: /iphone/i,
Android: /android/i,
Blackberry: /blackberry/i,
Samsung: /samsung/i,
Curl: /curl/i
};
this.Agent = {};
this.DefaultAgent = {
isMobile: false,
isTablet: false,
isiPad: false,
isiPod: false,
isiPhone: false,
isAndroid: false,
isBlackberry: false,
isOpera: false,
isIE: false,
isIECompatibilityMode: false,
isSafari: false,
isFirefox: false,
isWebkit: false,
isChrome: false,
isKonqueror: false,
isOmniWeb: false,
isSeaMonkey: false,
isFlock: false,
isAmaya: false,
isEpiphany: false,
isDesktop: false,
isWindows: false,
isLinux: false,
isLinux64: false,
isMac: false,
isChromeOS: false,
isBada: false,
isSamsung: false,
isRaspberry: false,
isBot: false,
isCurl: false,
isAndroidTablet: false,
isWinJs: false,
isKindleFire: false,
isSilk: false,
SilkAccelerated: false,
Browser: 'unknown',
Version: 'unknown',
OS: 'unknown',
Platform: 'unknown',
GeoIP: {},
source: ''
};
var UserAgent = function () {
this.version = '0.1.8';
this._Versions = {
Firefox: /firefox\/([\d\w\.\-]+)/i,
IE: /msie\s([\d\.]+[\d])|trident\/\d+\.\d+;.*[rv:]+(\d+\.\d)/i,
Chrome: /chrome\/([\d\w\.\-]+)/i,
Chromium: /(?:chromium|crios)\/([\d\w\.\-]+)/i,
Safari: /version\/([\d\w\.\-]+)/i,
Opera: /version\/([\d\w\.\-]+)/i,
Ps3: /([\d\w\.\-]+)\)\s*$/i,
Psp: /([\d\w\.\-]+)\)?\s*$/i,
Amaya: /amaya\/([\d\w\.\-]+)/i,
SeaMonkey: /seamonkey\/([\d\w\.\-]+)/i,
OmniWeb: /omniweb\/v([\d\w\.\-]+)/i,
Flock: /flock\/([\d\w\.\-]+)/i,
Epiphany: /epiphany\/([\d\w\.\-]+)/i,
WinJs: /msapphost\/([\d\w\.\-]+)/i
};
this._Browsers = {
Amaya: /amaya/i,
Konqueror: /konqueror/i,
Epiphany: /epiphany/i,
SeaMonkey: /seamonkey/i,
Flock: /flock/i,
OmniWeb: /omniweb/i,
Chromium: /chromium|crios/i,
Chrome: /chrome/i,
Safari: /safari/i,
IE: /msie|trident/i,
Opera: /opera/i,
PS3: /playstation 3/i,
PSP: /playstation portable/i,
Firefox: /firefox/i,
WinJs: /msapphost/i
};
this._OS = {
Windows10: /windows nt 10\.0/i,
Windows81: /windows nt 6\.3/i,
Windows8: /windows nt 6\.2/i,
Windows7: /windows nt 6\.1/i,
UnknownWindows: /windows nt 6\.\d+/i,
WindowsVista: /windows nt 6\.0/i,
Windows2003: /windows nt 5\.2/i,
WindowsXP: /windows nt 5\.1/i,
Windows2000: /windows nt 5\.0/i,
WindowsPhone8: /windows phone 8\./,
OSX: /os x (\d+)[._](\d+)/i,
Mac: /os x/i,
Linux: /linux/i,
Linux64: /linux x86\_64/i,
ChromeOS: /cros/i,
Wii: /wii/i,
PS3: /playstation 3/i,
PSP: /playstation portable/i,
iPad: /\(iPad.*os (\d+)[._](\d+)/i,
iPhone: /\(iPhone.*os (\d+)[._](\d+)/i,
Bada: /Bada\/(\d+)\.(\d+)/i,
Curl: /curl\/(\d+)\.(\d+)\.(\d+)/i
};
this._Platform = {
Windows: /windows nt/i,
WindowsPhone: /windows phone/i,
Mac: /macintosh/i,
Linux: /linux/i,
Wii: /wii/i,
Playstation: /playstation/i,
iPad: /ipad/i,
iPod: /ipod/i,
iPhone: /iphone/i,
Android: /android/i,
Blackberry: /blackberry/i,
Samsung: /samsung/i,
Curl: /curl/i
};
this.getBrowser = function(string) {
switch (true) {
case this._Browsers.Konqueror.test(string):
this.Agent.isKonqueror = true;
return 'Konqueror';
case this._Browsers.Amaya.test(string):
this.Agent.isAmaya = true;
return 'Amaya';
case this._Browsers.Epiphany.test(string):
this.Agent.isEpiphany = true;
return 'Epiphany';
case this._Browsers.SeaMonkey.test(string):
this.Agent.isSeaMonkey = true;
return 'SeaMonkey';
case this._Browsers.Flock.test(string):
this.Agent.isFlock = true;
return 'Flock';
case this._Browsers.OmniWeb.test(string):
this.Agent.isOmniWeb = true;
return 'OmniWeb';
case this._Browsers.Chromium.test(string):
this.Agent.isChrome = true;
return 'Chromium';
case this._Browsers.Chrome.test(string):
this.Agent.isChrome = true;
return 'Chrome';
case this._Browsers.Safari.test(string):
this.Agent.isSafari = true;
return 'Safari';
case this._Browsers.WinJs.test(string):
this.Agent.isWinJs = true;
return 'WinJs';
case this._Browsers.IE.test(string):
this.Agent.isIE = true;
return 'IE';
case this._Browsers.Opera.test(string):
this.Agent.isOpera = true;
return 'Opera';
case this._Browsers.PS3.test(string):
return 'ps3';
case this._Browsers.PSP.test(string):
return 'psp';
case this._Browsers.Firefox.test(string):
this.Agent.isFirefox = true;
return 'Firefox';
default:
return 'unknown';
}
};
this.getBrowserVersion = function(string) {
var regex;
switch (this.Agent.Browser) {
case 'Chrome':
if (this._Versions.Chrome.test(string)) {
return RegExp.$1;
}
break;
case 'Chromium':
if (this._Versions.Chromium.test(string)) {
return RegExp.$1;
}
break;
case 'Safari':
if (this._Versions.Safari.test(string)) {
return RegExp.$1;
}
break;
case 'Opera':
if (this._Versions.Opera.test(string)) {
return RegExp.$1;
}
break;
case 'Firefox':
if (this._Versions.Firefox.test(string)) {
return RegExp.$1;
}
break;
case 'WinJs':
if (this._Versions.WinJs.test(string)) {
return RegExp.$1;
}
break;
case 'IE':
if (this._Versions.IE.test(string)) {
return RegExp.$2 ? RegExp.$2 : RegExp.$1;
}
break;
case 'ps3':
if (this._Versions.Ps3.test(string)) {
return RegExp.$1;
}
break;
case 'psp':
if (this._Versions.Psp.test(string)) {
return RegExp.$1;
}
break;
case 'Amaya':
if (this._Versions.Amaya.test(string)) {
return RegExp.$1;
}
break;
case 'Epiphany':
if (this._Versions.Epiphany.test(string)) {
return RegExp.$1;
}
break;
case 'SeaMonkey':
if (this._Versions.SeaMonkey.test(string)) {
return RegExp.$1;
}
break;
case 'Flock':
if (this._Versions.Flock.test(string)) {
return RegExp.$1;
}
break;
case 'OmniWeb':
if (this._Versions.OmniWeb.test(string)) {
return RegExp.$1;
}
break;
default:
regex = /#{name}[\/ ]([\d\w\.\-]+)/i;
if (regex.test(string)) {
return RegExp.$1;
}
}
};
this.DefaultAgent = {
isMobile: false,
isTablet: false,
isiPad: false,
isiPod: false,
isiPhone: false,
isAndroid: false,
isBlackberry: false,
isOpera: false,
isIE: false,
isIECompatibilityMode: false,
isSafari: false,
isFirefox: false,
isWebkit: false,
isChrome: false,
isKonqueror: false,
isOmniWeb: false,
isSeaMonkey: false,
isFlock: false,
isAmaya: false,
isEpiphany: false,
isDesktop: false,
isWindows: false,
isLinux: false,
isLinux64: false,
isMac: false,
isChromeOS: false,
isBada: false,
isSamsung: false,
isRaspberry: false,
isBot: false,
isCurl: false,
isAndroidTablet: false,
isWinJs: false,
isKindleFire: false,
isSilk: false,
silkAccelerated: false,
browser: 'unknown',
version: 'unknown',
os: 'unknown',
platform: 'unknown',
geoIp: {},
source: ''
};
this.getOS = function(string) {
switch (true) {
case this._OS.WindowsVista.test(string):
this.Agent.isWindows = true;
return 'Windows Vista';
case this._OS.Windows7.test(string):
this.Agent.isWindows = true;
return 'Windows 7';
case this._OS.Windows8.test(string):
this.Agent.isWindows = true;
return 'Windows 8';
case this._OS.Windows81.test(string):
this.Agent.isWindows = true;
return 'Windows 8.1';
case this._OS.Windows10.test(string):
this.Agent.isWindows = true;
return 'Windows 10.0';
case this._OS.Windows2003.test(string):
this.Agent.isWindows = true;
return 'Windows 2003';
case this._OS.WindowsXP.test(string):
this.Agent.isWindows = true;
return 'Windows XP';
case this._OS.Windows2000.test(string):
this.Agent.isWindows = true;
return 'Windows 2000';
case this._OS.WindowsPhone8.test(string):
return 'Windows Phone 8';
case this._OS.Linux64.test(string):
this.Agent.isLinux = true;
this.Agent.isLinux64 = true;
return 'Linux 64';
case this._OS.Linux.test(string):
this.Agent.isLinux = true;
return 'Linux';
case this._OS.ChromeOS.test(string):
this.Agent.isChromeOS = true;
return 'Chrome OS';
case this._OS.Wii.test(string):
return 'Wii';
case this._OS.PS3.test(string):
return 'Playstation';
case this._OS.PSP.test(string):
return 'Playstation';
case this._OS.Mac.test(string):
this.Agent.isMac = true;
return 'OS X';
case this._OS.OSX.test(string):
this.Agent.isMac = true;
return string.match(this._OS.OSX)[0].replace('_', '.');
case this._OS.iPad.test(string):
this.Agent.isiPad = true;
return string.match(this._OS.iPad)[0].replace('_', '.');
case this._OS.iPhone.test(string):
this.Agent.isiPhone = true;
return string.match(this._OS.iPhone)[0].replace('_', '.');
case this._OS.Bada.test(string):
this.Agent.isBada = true;
return 'Bada';
case this._OS.Curl.test(string):
this.Agent.isCurl = true;
return 'Curl';
default:
return 'unknown';
}
};
this.Agent = {};
this.getPlatform = function(string) {
switch (true) {
case this._Platform.Windows.test(string):
return "Microsoft Windows";
case this._Platform.WindowsPhone.test(string):
this.Agent.isWindowsPhone = true;
return "Microsoft Windows Phone";
case this._Platform.Mac.test(string):
return "Apple Mac";
case this._Platform.Curl.test(string):
return "Curl";
case this._Platform.Android.test(string):
this.Agent.isAndroid = true;
return "Android";
case this._Platform.Blackberry.test(string):
this.Agent.isBlackberry = true;
return "Blackberry";
case this._Platform.Linux.test(string):
return "Linux";
case this._Platform.Wii.test(string):
return "Wii";
case this._Platform.Playstation.test(string):
return "Playstation";
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:
return 'unknown';
}
};
this.getBrowser = function (string) {
switch (true) {
case this._Browsers.Konqueror.test(string):
this.Agent.isKonqueror = true;
return 'Konqueror';
case this._Browsers.Amaya.test(string):
this.Agent.isAmaya = true;
return 'Amaya';
case this._Browsers.Epiphany.test(string):
this.Agent.isEpiphany = true;
return 'Epiphany';
case this._Browsers.SeaMonkey.test(string):
this.Agent.isSeaMonkey = true;
return 'SeaMonkey';
case this._Browsers.Flock.test(string):
this.Agent.isFlock = true;
return 'Flock';
case this._Browsers.OmniWeb.test(string):
this.Agent.isOmniWeb = true;
return 'OmniWeb';
case this._Browsers.Chromium.test(string):
this.Agent.isChrome = true;
return 'Chromium';
case this._Browsers.Chrome.test(string):
this.Agent.isChrome = true;
return 'Chrome';
case this._Browsers.Safari.test(string):
this.Agent.isSafari = true;
return 'Safari';
case this._Browsers.WinJs.test(string):
this.Agent.isWinJs = true;
return 'WinJs';
case this._Browsers.IE.test(string):
this.Agent.isIE = true;
return 'IE';
case this._Browsers.Opera.test(string):
this.Agent.isOpera = true;
return 'Opera';
case this._Browsers.PS3.test(string):
return 'ps3';
case this._Browsers.PSP.test(string):
return 'psp';
case this._Browsers.Firefox.test(string):
this.Agent.isFirefox = true;
return 'Firefox';
default:
return 'unknown';
}
};
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;
}
this.getBrowserVersion = function (string) {
var regex;
switch (this.Agent.browser) {
case 'Chrome':
if (this._Versions.Chrome.test(string)) {
return RegExp.$1;
}
break;
case 'Chromium':
if (this._Versions.Chromium.test(string)) {
return RegExp.$1;
}
break;
case 'Safari':
if (this._Versions.Safari.test(string)) {
return RegExp.$1;
}
break;
case 'Opera':
if (this._Versions.Opera.test(string)) {
return RegExp.$1;
}
break;
case 'Firefox':
if (this._Versions.Firefox.test(string)) {
return RegExp.$1;
}
break;
case 'WinJs':
if (this._Versions.WinJs.test(string)) {
return RegExp.$1;
}
break;
case 'IE':
if (this._Versions.IE.test(string)) {
return RegExp.$2 ? RegExp.$2 : RegExp.$1;
}
break;
case 'ps3':
if (this._Versions.Ps3.test(string)) {
return RegExp.$1;
}
break;
case 'psp':
if (this._Versions.Psp.test(string)) {
return RegExp.$1;
}
break;
case 'Amaya':
if (this._Versions.Amaya.test(string)) {
return RegExp.$1;
}
break;
case 'Epiphany':
if (this._Versions.Epiphany.test(string)) {
return RegExp.$1;
}
break;
case 'SeaMonkey':
if (this._Versions.SeaMonkey.test(string)) {
return RegExp.$1;
}
break;
case 'Flock':
if (this._Versions.Flock.test(string)) {
return RegExp.$1;
}
break;
case 'OmniWeb':
if (this._Versions.OmniWeb.test(string)) {
return RegExp.$1;
}
break;
default:
regex = /#{name}[\/ ]([\d\w\.\-]+)/i;
if (regex.test(string)) {
return RegExp.$1;
}
}
};
if (version === 7 && tridentVersion === 5) {
ua.Agent.isIECompatibilityMode = true;
ua.Agent.Version = 9.0;
}
this.getOS = function (string) {
switch (true) {
case this._OS.WindowsVista.test(string):
this.Agent.isWindows = true;
return 'Windows Vista';
case this._OS.Windows7.test(string):
this.Agent.isWindows = true;
return 'Windows 7';
case this._OS.Windows8.test(string):
this.Agent.isWindows = true;
return 'Windows 8';
case this._OS.Windows81.test(string):
this.Agent.isWindows = true;
return 'Windows 8.1';
case this._OS.Windows10.test(string):
this.Agent.isWindows = true;
return 'Windows 10.0';
case this._OS.Windows2003.test(string):
this.Agent.isWindows = true;
return 'Windows 2003';
case this._OS.WindowsXP.test(string):
this.Agent.isWindows = true;
return 'Windows XP';
case this._OS.Windows2000.test(string):
this.Agent.isWindows = true;
return 'Windows 2000';
case this._OS.WindowsPhone8.test(string):
return 'Windows Phone 8';
case this._OS.Linux64.test(string):
this.Agent.isLinux = true;
this.Agent.isLinux64 = true;
return 'Linux 64';
case this._OS.Linux.test(string):
this.Agent.isLinux = true;
return 'Linux';
case this._OS.ChromeOS.test(string):
this.Agent.isChromeOS = true;
return 'Chrome OS';
case this._OS.Wii.test(string):
return 'Wii';
case this._OS.PS3.test(string):
return 'Playstation';
case this._OS.PSP.test(string):
return 'Playstation';
case this._OS.Mac.test(string):
this.Agent.isMac = true;
return 'OS X';
case this._OS.OSX.test(string):
this.Agent.isMac = true;
return string.match(this._OS.OSX)[0].replace('_', '.');
case this._OS.iPad.test(string):
this.Agent.isiPad = true;
return string.match(this._OS.iPad)[0].replace('_', '.');
case this._OS.iPhone.test(string):
this.Agent.isiPhone = true;
return string.match(this._OS.iPhone)[0].replace('_', '.');
case this._OS.Bada.test(string):
this.Agent.isBada = true;
return 'Bada';
case this._OS.Curl.test(string):
this.Agent.isCurl = true;
return 'Curl';
default:
return 'unknown';
}
};
if (version === 7 && tridentVersion === 4) {
ua.Agent.isIECompatibilityMode = true;
ua.Agent.Version = 8.0;
this.getPlatform = function (string) {
switch (true) {
case this._Platform.Windows.test(string):
return 'Microsoft Windows';
case this._Platform.WindowsPhone.test(string):
this.Agent.isWindowsPhone = true;
return 'Microsoft Windows Phone';
case this._Platform.Mac.test(string):
return 'Apple Mac';
case this._Platform.Curl.test(string):
return 'Curl';
case this._Platform.Android.test(string):
this.Agent.isAndroid = true;
return 'Android';
case this._Platform.Blackberry.test(string):
this.Agent.isBlackberry = true;
return 'Blackberry';
case this._Platform.Linux.test(string):
return 'Linux';
case this._Platform.Wii.test(string):
return 'Wii';
case this._Platform.Playstation.test(string):
return 'Playstation';
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:
return 'unknown';
}
};
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.testSilk = function() {
var ua = this;
switch (true) {
case new RegExp('silk', 'gi').test(ua.Agent.source):
this.Agent.isSilk = true;
default:
}
this.testSilk = function () {
var ua = this;
switch (true) {
case new RegExp('silk', 'gi').test(ua.Agent.source):
this.Agent.isSilk = true;
break;
default:
}
if (/Silk-Accelerated=true/gi.test(ua.Agent.source)) {
if (/Silk-Accelerated=true/gi.test(ua.Agent.source)) {
this.Agent.SilkAccelerated = true;
}
return this.Agent.isSilk ? 'Silk' : false;
};
}
return this.Agent.isSilk ? 'Silk' : false;
};
this.testKindleFire = function() {
var ua = this;
switch (true) {
case /KFOT/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire';
case /KFTT/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HD';
case /KFJWI/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HD 8.9';
case /KFJWA/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HD 8.9 4G';
case /KFSOWI/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HD 7';
case /KFTHWI/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HDX 7';
case /KFTHWA/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HDX 7 4G';
case /KFAPWI/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HDX 8.9';
case /KFAPWA/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HDX 8.9 4G';
default:
return false;
}
};
this.testKindleFire = function () {
var ua = this;
switch (true) {
case /KFOT/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire';
case /KFTT/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HD';
case /KFJWI/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HD 8.9';
case /KFJWA/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HD 8.9 4G';
case /KFSOWI/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HD 7';
case /KFTHWI/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HDX 7';
case /KFTHWA/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HDX 7 4G';
case /KFAPWI/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HDX 8.9';
case /KFAPWA/gi.test(ua.Agent.source):
this.Agent.isKindleFire = true;
return 'Kindle Fire HDX 8.9 4G';
default:
return false;
}
};
this.reset = function reset() {
var ua = this;
for (var key in ua.DefaultAgent) {
ua.Agent[key] = ua.DefaultAgent[key];
}
return ua;
};
this.reset = function reset() {
var ua = this;
for (var key in ua.DefaultAgent) {
ua.Agent[key] = ua.DefaultAgent[key];
}
return ua;
};
this.testMobile = function testMobile() {
var ua = this;
switch (true) {
case ua.Agent.isWindows:
case ua.Agent.isLinux:
case ua.Agent.isMac:
case ua.Agent.isChromeOS:
ua.Agent.isDesktop = true;
break;
case ua.Agent.isAndroid:
case ua.Agent.isSamsung:
this.testMobile = function testMobile() {
var ua = this;
switch (true) {
case ua.Agent.isWindows:
case ua.Agent.isLinux:
case ua.Agent.isMac:
case ua.Agent.isChromeOS:
ua.Agent.isDesktop = true;
break;
case ua.Agent.isAndroid:
case ua.Agent.isSamsung:
ua.Agent.isMobile = true;
ua.Agent.isDesktop = false;
break;
default:
}
switch (true) {
case ua.Agent.isiPad:
case ua.Agent.isiPod:
case ua.Agent.isiPhone:
case ua.Agent.isBada:
case ua.Agent.isBlackberry:
case ua.Agent.isAndroid:
case ua.Agent.isWindowsPhone:
ua.Agent.isMobile = true;
ua.Agent.isDesktop = false;
break;
default:
}
if (/mobile/i.test(ua.Agent.source)) {
ua.Agent.isMobile = true;
ua.Agent.isDesktop = false;
break;
default:
}
switch (true) {
case ua.Agent.isiPad:
case ua.Agent.isiPod:
case ua.Agent.isiPhone:
case ua.Agent.isBada:
case ua.Agent.isBlackberry:
case ua.Agent.isAndroid:
case ua.Agent.isWindowsPhone:
ua.Agent.isMobile = true;
ua.Agent.isDesktop = false;
break;
default:
}
if (/mobile/i.test(ua.Agent.source)) {
ua.Agent.isMobile = true;
ua.Agent.isDesktop = false;
}
};
this.testTablet = function testTablet() {
var ua = this;
switch (true) {
case ua.Agent.isiPad:
case ua.Agent.isAndroidTablet:
case ua.Agent.isKindleFire:
ua.Agent.isTablet = true;
break;
}
if(/tablet/i.test(ua.Agent.source)) {
ua.Agent.isTablet = true;
}
};
}
};
this.testNginxGeoIP = function testNginxGeoIP(headers) {
var ua = this;
Object.keys(headers).forEach(function(key) {
if (/^GEOIP/i.test(key)) {
ua.Agent.GeoIP[key] = headers[key];
this.testTablet = function testTablet() {
var ua = this;
switch (true) {
case ua.Agent.isiPad:
case ua.Agent.isAndroidTablet:
case ua.Agent.isKindleFire:
ua.Agent.isTablet = true;
break;
}
});
};
if (/tablet/i.test(ua.Agent.source)) {
ua.Agent.isTablet = true;
}
};
this.testBot = function testBot() {
var ua = this;
if (/googlebot|baiduspider|gurujibot|yandexbot|slurp|msnbot|bingbot|facebookexternalhit|linkedinbot|twitterbot|slackbot/i.test(ua.Agent.source)) {
ua.Agent.isBot = true;
}
};
this.testNginxGeoIP = function testNginxGeoIP(headers) {
var ua = this;
Object.keys(headers).forEach(function (key) {
if (/^GEOIP/i.test(key)) {
ua.Agent.geoIp[key] = headers[key];
}
});
};
this.testAndroidTablet = function testAndroidTablet() {
var ua = this;
if (ua.Agent.isAndroid && !/mobile/i.test(ua.Agent.source)) {
ua.Agent.isAndroidTablet = true;
}
};
this.testBot = function testBot() {
var ua = this;
if (/googlebot|baiduspider|gurujibot|yandexbot|slurp|msnbot|bingbot|facebookexternalhit|linkedinbot|twitterbot|slackbot/i.test(ua.Agent.source)) {
ua.Agent.isBot = true;
}
};
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.testBot();
ua.testMobile();
ua.testAndroidTablet();
ua.testTablet();
ua.testCompatibilityMode();
ua.testSilk();
ua.testKindleFire();
return ua.Agent;
};
this.testAndroidTablet = function testAndroidTablet() {
var ua = this;
if (ua.Agent.isAndroid && !/mobile/i.test(ua.Agent.source)) {
ua.Agent.isAndroidTablet = true;
}
};
this.express = function() {
return function(req, res, next) {
var source = req.headers['user-agent'] || '',
ua = new UserAgent();
if (typeof source === 'undefined') {
source = "unknown";
}
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.testNginxGeoIP(req.headers);
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.testBot();

@@ -562,15 +537,12 @@ ua.testMobile();

ua.testKindleFire();
req.useragent = ua.Agent;
if ('function' === typeof res.locals) {
res.locals({useragent: ua.Agent});
} else {
res.locals.useragent = ua.Agent;
}
next();
return ua.Agent;
};
this.Agent = this.DefaultAgent;
return this;
};
this.Agent = this.DefaultAgent;
};
exports.UserAgent = UserAgent;
return new UserAgent();
exports = module.exports = new UserAgent();
})(this);
{
"name": "express-useragent",
"description": "ExpressJS/Connect/TrinteJS user-agent middleware exposing",
"version": "0.1.7",
"version": "0.1.8",
"homepage": "https://github.com/biggora/express-useragent/",

@@ -10,7 +10,13 @@ "repository": {

},
"author": {
"name": "Aleksej Gordejev",
"email" : "aleksej@gordejev.lv",
"url": "https://github.com/biggora"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/biggora/express-useragent/blob/master/LICENSE"
}
],
"author": {
"name": "Alexey Gordeyev",
"email": "aleksej@gordejev.lv",
"url": "https://github.com/biggora"
},
"contributors": [

@@ -47,3 +53,3 @@ {

"trinte",
"railway",
"browser",
"compound",

@@ -53,5 +59,11 @@ "middleware"

"main": "./index.js",
"scripts": {
"test": "nodeunit test/browsers.js",
"express": "node test/express.js",
"http": "node test/http.js",
"build-js": "grunt build"
},
"directories": {
"lib": "lib",
"tests": "tests"
"test": "test"
},

@@ -63,9 +75,10 @@ "engines": {

"devDependencies": {
"connect": ">= 2.5.0",
"express": ">= 3.0.0",
"nodeunit": ">= 0.5.4"
},
"scripts": {
"test": "nodeunit tests/browsers.js"
"express": ">= 3.0.0",
"nodeunit":"*",
"bower":"*",
"grunt": "*",
"grunt-contrib-clean": "*",
"grunt-contrib-uglify":"*"
}
}

@@ -12,7 +12,7 @@ [![build status](https://secure.travis-ci.org/biggora/express-useragent.png)](http://travis-ci.org/biggora/express-useragent)

$ npm install express-useragent
$ npm install express-useragent --save
## Usage overview
### Simple
### Simple Node App

@@ -43,3 +43,3 @@ ```js

module.exports = function (app, express) {
app.configure(function () {
app.use(function () {
app.use(useragent.express());

@@ -53,5 +53,5 @@ });

```js
var express = require('express')
, app = express.createServer()
, useragent = require('express-useragent');
var express = require('express');
var app = express();
var useragent = require('express-useragent');

@@ -65,20 +65,2 @@ app.use(useragent.express());

### for [CompoundJS](http://compoundjs.com)
$ compound install https://github.com/biggora/express-useragent.git
#### or manual setup in project config/environment.js
```js
var useragent = require('express-useragent');
app.configure(function () {
// init useragent
app.use(useragent.express());
app.use(app.router);
});
```
module provides details such as the following:

@@ -96,3 +78,3 @@

"Platform":"Microsoft Windows",
"source":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11"
"source":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79..."
}

@@ -110,3 +92,39 @@

## Client Side
* Clone the repo: `git clone git://github.com/biggora/express-useragent.git`
* Or Install with [Bower](http://twitter.github.com/bower): `bower install express-useragent`.
The client side version of express-useragent available in the `lib/` subdirectory.
#### Include file in your HTML. The minimum required for this plugin are:
```
<script type="text/javascript" src="/path/to/express-useragent.js"></script>
```
#### Execute the plugin:
```javascript
var userAgent = new UserAgent().parse(navigator.userAgent);
```
## Running Tests
To run the test suite, first install the dependencies, then run `npm test`:
```bash
npm install
npm test
```
#### Run Example Node App
```bash
npm run-script http
```
#### Run Example Express App
```bash
npm run-script express
```
## In the Wild

@@ -113,0 +131,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc