Skip to content

Commit

Permalink
add PahntomJS, close #58, #54
Browse files Browse the repository at this point in the history
  • Loading branch information
biggora committed Sep 24, 2016
1 parent c12e236 commit 5713f10
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "express-useragent",
"description": "Fast User-Agent exposing",
"version": "1.0.1",
"version": "1.0.2",
"homepage": "https://github.com/biggora/express-useragent/",
"repository": {
"type": "git",
Expand Down
13 changes: 12 additions & 1 deletion lib/express-useragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
var IS_BOT_REGEXP = new RegExp('^.*(' + BOTS.join('|') + ').*$');

var UserAgent = function () {
this.version = '0.2.4';
this.version = '1.0.2';
this._Versions = {
Edge: /Edge\/([\d\w\.\-]+)/i,
Firefox: /firefox\/([\d\w\.\-]+)/i,
Expand All @@ -45,6 +45,7 @@
Flock: /flock\/([\d\w\.\-]+)/i,
Epiphany: /epiphany\/([\d\w\.\-]+)/i,
WinJs: /msapphost\/([\d\w\.\-]+)/i,
PhantomJS: /phantomjs\/([\d\w\.\-]+)/i,
UC: /UCBrowser\/([\d\w\.]+)/i
};
this._Browsers = {
Expand All @@ -64,6 +65,7 @@
PSP: /playstation portable/i,
Firefox: /firefox/i,
WinJs: /msapphost/i,
PhantomJS: /phantomjs/i,
UC: /UCBrowser/i
};
this._OS = {
Expand Down Expand Up @@ -140,6 +142,7 @@
isSeaMonkey: false,
isFlock: false,
isAmaya: false,
isPhantomJS: false,
isEpiphany: false,
isDesktop: false,
isWindows: false,
Expand Down Expand Up @@ -175,6 +178,9 @@
case this._Browsers.Edge.test(string):
this.Agent.isEdge = true;
return 'Edge';
case this._Browsers.PhantomJS.test(string):
this.Agent.isPhantomJS = true;
return 'PhantomJS';
case this._Browsers.Konqueror.test(string):
this.Agent.isKonqueror = true;
return 'Konqueror';
Expand Down Expand Up @@ -239,6 +245,11 @@
return RegExp.$1;
}
break;
case 'PhantomJS':
if (this._Versions.PhantomJS.test(string)) {
return RegExp.$1;
}
break;
case 'Chrome':
if (this._Versions.Chrome.test(string)) {
return RegExp.$1;
Expand Down
4 changes: 2 additions & 2 deletions lib/express-useragent.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "express-useragent",
"description": "ExpressJS/Connect/TrinteJS user-agent middleware exposing",
"version": "1.0.1",
"version": "1.0.2",
"homepage": "https://github.com/biggora/express-useragent/",
"repository": {
"type": "git",
Expand Down Expand Up @@ -72,7 +72,9 @@
"engines": {
"node": ">=0.8"
},
"dependencies": {},
"dependencies": {
"nodeunit": "0.10.2"
},
"devDependencies": {
"nodeunit": "*",
"jshint": "*",
Expand Down
33 changes: 33 additions & 0 deletions test/browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,3 +1162,36 @@ exports['Microsoft Edge Mobile'] = function (test) {

test.done();
};

exports['PhantomJS'] = function (test) {

var s = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34';

var a = ua.parse(s);

test.ok(a.isAuthoritative, 'Authoritative');
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.isEdge, 'Edge');
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.ok(!a.isWindowsPhone, 'Windows Phone');
test.ok(a.isPhantomJS, 'PhantomJS');
test.equal(a.version, '1.9.8');
test.ok(!a.isIECompatibilityMode);

test.done();
};

0 comments on commit 5713f10

Please sign in to comment.