Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "sniff-fns", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/js-fns/sniff-fns", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -0,1 +1,7 @@ | ||
## v0.4.0 (6 May 2016) | ||
- Add `isIE` function | ||
- Add `whichBrowserVersion` function which supports Chrome, Mobile Chrome, | ||
Firefox, IE and Opera. | ||
## v0.1.0 (19 Dec 2014) |
@@ -57,15 +57,23 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
// Browsers | ||
var isChrome = __webpack_require__(1); | ||
var isChromeMobile = __webpack_require__(4); | ||
var isFF = __webpack_require__(6); | ||
var isOpera = __webpack_require__(7); | ||
var isSafari = __webpack_require__(8); | ||
var isIE = __webpack_require__(9); | ||
var whichBrowser = __webpack_require__(10); | ||
var whichBrowserVersion = __webpack_require__(11); | ||
// OSes | ||
var isAndroid = __webpack_require__(5); | ||
var isAndroidMobile = __webpack_require__(6); | ||
var isBB = __webpack_require__(7); | ||
var isFF = __webpack_require__(8); | ||
var isOpera = __webpack_require__(9); | ||
var isSafari = __webpack_require__(10); | ||
var isIphone = __webpack_require__(11); | ||
var isIpad = __webpack_require__(12); | ||
var isMac = __webpack_require__(13); | ||
var isWP = __webpack_require__(14); | ||
var isMobile = __webpack_require__(15); | ||
var isAndroidMobile = __webpack_require__(12); | ||
var isBB = __webpack_require__(13); | ||
var isIphone = __webpack_require__(14); | ||
var isIpad = __webpack_require__(15); | ||
var isMac = __webpack_require__(16); | ||
var isWindows = __webpack_require__(17); | ||
var isWP = __webpack_require__(18); | ||
var isMobile = __webpack_require__(19); | ||
var whichOs = __webpack_require__(20); | ||
@@ -81,3 +89,6 @@ var sniffFns = { | ||
isOpera: isOpera, | ||
isSafari: isSafari | ||
isSafari: isSafari, | ||
isIE: isIE, | ||
whichBrowser: whichBrowser, | ||
whichBrowserVersion: whichBrowserVersion | ||
}, | ||
@@ -87,4 +98,6 @@ isIphone: isIphone, | ||
isMac: isMac, | ||
isWindows: isWindows, | ||
isWindowsPhone: isWP, | ||
isMobile: isMobile | ||
isMobile: isMobile, | ||
whichOs: whichOs | ||
} | ||
@@ -158,10 +171,6 @@ | ||
var testString = __webpack_require__(2) | ||
var testString = __webpack_require__(2); | ||
var isAndroid = function(str){ | ||
if (testString(str, 'android')) { | ||
return parseFloat(str.replace(/^.* android (\d+)\.(\d+).*$/, "$1.$2")) || true | ||
} else { | ||
return false | ||
} | ||
var isAndroid = function (str) { | ||
return testString(str, '; android'); | ||
}; | ||
@@ -177,9 +186,8 @@ | ||
var testString = __webpack_require__(2); | ||
var sniffAndroid = __webpack_require__(5); | ||
var isAndroidMobile = function(str){ | ||
return sniffAndroid(str) && testString(str, 'mobile'); | ||
var isFirefox = function(str){ | ||
return testString(str, 'firefox'); | ||
} | ||
module.exports = isAndroidMobile; | ||
module.exports = isFirefox; | ||
@@ -193,9 +201,10 @@ | ||
var isBB = function(str){ | ||
return testString(str, 'bb10'); | ||
var isOpera = function(str){ | ||
return testString(str, 'OPR/') || testString(str, 'opera'); | ||
} | ||
module.exports = isBB; | ||
module.exports = isOpera; | ||
/***/ }, | ||
@@ -206,8 +215,10 @@ /* 8 */ | ||
var testString = __webpack_require__(2); | ||
var isChrome = __webpack_require__(1); | ||
var isAndroid = __webpack_require__(5); | ||
var isFirefox = function(str){ | ||
return testString(str, 'firefox'); | ||
var isSafari = function(str){ | ||
return testString(str, 'safari') && testString(str, 'apple') && !(isChrome(str) && isAndroid(str)); | ||
} | ||
module.exports = isFirefox; | ||
module.exports = isSafari; | ||
@@ -221,10 +232,10 @@ | ||
var isOpera = function(str){ | ||
return testString(str, 'OPR/') || testString(str, 'opera'); | ||
var isIE = function(str){ | ||
return testString(str, 'MSIE') || // Common IE pattern | ||
testString(str, 'Trident/7'); // IE11 | ||
} | ||
module.exports = isOpera; | ||
module.exports = isIE; | ||
/***/ }, | ||
@@ -234,11 +245,28 @@ /* 10 */ | ||
var testString = __webpack_require__(2); | ||
var isChrome = __webpack_require__(1); | ||
var isAndroid = __webpack_require__(5); | ||
var isChromeMobile = __webpack_require__(4); | ||
var isFF = __webpack_require__(6); | ||
var isOpera = __webpack_require__(7); | ||
var isSafari = __webpack_require__(8); | ||
var isIE = __webpack_require__(9); | ||
var isSafari = function(str){ | ||
return testString(str, 'safari') && testString(str, 'apple') && !(isChrome(str) && isAndroid(str)); | ||
} | ||
var whichBrowser = function (str) { | ||
if (isOpera(str)) { | ||
return 'opera' | ||
} else if (isChromeMobile(str)) { | ||
return 'chrome mobile' | ||
} else if (isChrome(str)) { | ||
return 'chrome' | ||
} else if (isFF(str)) { | ||
return 'firefox' | ||
} else if (isSafari(str)) { | ||
return 'safari' | ||
} else if (isIE(str)) { | ||
return 'ie' | ||
} else { | ||
return 'unknown browser' | ||
} | ||
}; | ||
module.exports = isSafari; | ||
module.exports = whichBrowser; | ||
@@ -250,2 +278,83 @@ | ||
var whichBrowser = __webpack_require__(10); | ||
var whichBrowserVersion = function (str) { | ||
var capturedVersion | ||
switch (whichBrowser(str)) { | ||
case 'chrome': | ||
capturedVersion = str.match(/Chrome\/(\d+)\./); | ||
return capturedVersion ? parseInt(capturedVersion[1]) : null; | ||
case 'chrome mobile': | ||
capturedVersion = str.match(/(?:Chrome|CriOS)\/(\d+)\./); | ||
return capturedVersion ? parseInt(capturedVersion[1]) : null; | ||
case 'firefox': | ||
capturedVersion = str.match(/Firefox\/(\d+)\./); | ||
return capturedVersion ? parseInt(capturedVersion[1]) : null; | ||
case 'ie': | ||
capturedVersion = str.match(/MSIE\s(\d+)\./); | ||
if (capturedVersion) { | ||
return parseInt(capturedVersion[1]); | ||
} else { | ||
return /Trident\/7/.test(str) ? 11 : null; | ||
} | ||
case 'safari': | ||
capturedVersion = str.match(/Version\/(\d+)\./); | ||
if (capturedVersion) { | ||
return parseInt(capturedVersion[1]); | ||
} else { | ||
capturedVersion = str.match(/Safari\/(\d+)\./); | ||
if (capturedVersion) { | ||
return parseInt(capturedVersion[1]) < 412 ? 1 : 2; | ||
} else { | ||
return null | ||
} | ||
} | ||
case 'opera': | ||
capturedVersion = str.match(/Version\/(\d+)\./); | ||
return capturedVersion ? parseInt(capturedVersion[1]) : null; | ||
default: | ||
return null | ||
} | ||
}; | ||
module.exports = whichBrowserVersion; | ||
/***/ }, | ||
/* 12 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var testString = __webpack_require__(2); | ||
var sniffAndroid = __webpack_require__(5); | ||
var isAndroidMobile = function(str){ | ||
return sniffAndroid(str) && testString(str, 'mobile'); | ||
} | ||
module.exports = isAndroidMobile; | ||
/***/ }, | ||
/* 13 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var testString = __webpack_require__(2); | ||
var isBB = function(str){ | ||
return testString(str, 'bb10'); | ||
} | ||
module.exports = isBB; | ||
/***/ }, | ||
/* 14 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var testString = __webpack_require__(2) | ||
@@ -262,3 +371,3 @@ | ||
/***/ }, | ||
/* 12 */ | ||
/* 15 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -277,3 +386,3 @@ | ||
/***/ }, | ||
/* 13 */ | ||
/* 16 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -292,5 +401,20 @@ | ||
/***/ }, | ||
/* 14 */ | ||
/* 17 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var testString = __webpack_require__(2) | ||
var isWindowsPhone = __webpack_require__(18) | ||
var isWindows = function(str) { | ||
return testString(str, 'windows') && !isWindowsPhone(str) | ||
}; | ||
module.exports = isWindows; | ||
/***/ }, | ||
/* 18 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var testString = __webpack_require__(2); | ||
@@ -310,11 +434,11 @@ | ||
/***/ }, | ||
/* 15 */ | ||
/* 19 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var testString = __webpack_require__(2); | ||
var isAndroidMobile = __webpack_require__(6); | ||
var isIphone = __webpack_require__(11); | ||
var isIpad = __webpack_require__(12); | ||
var isWP = __webpack_require__(14); | ||
var isBB = __webpack_require__(7); | ||
var isAndroidMobile = __webpack_require__(12); | ||
var isIphone = __webpack_require__(14); | ||
var isIpad = __webpack_require__(15); | ||
var isWP = __webpack_require__(18); | ||
var isBB = __webpack_require__(13); | ||
@@ -328,2 +452,35 @@ var isMobile = function(str){ | ||
/***/ }, | ||
/* 20 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var isAndroid = __webpack_require__(5); | ||
var isAndroidMobile = __webpack_require__(12); | ||
var isBB = __webpack_require__(13); | ||
var isIphone = __webpack_require__(14); | ||
var isMac = __webpack_require__(16); | ||
var isWindows = __webpack_require__(17); | ||
var isWP = __webpack_require__(18); | ||
var whichOs = function (str) { | ||
if (isAndroid(str)) { | ||
return 'android' | ||
} else if (isBB(str)) { | ||
return 'blackberry' | ||
} else if (isIphone(str)) { | ||
return 'iphone' | ||
} else if (isWP(str)) { | ||
return 'windows mobile' | ||
} else if (isMac(str)) { | ||
return 'mac' | ||
} else if (isWindows(str)) { | ||
return 'windows' | ||
} else { | ||
return 'unknown os' | ||
} | ||
}; | ||
module.exports = whichOs; | ||
/***/ } | ||
@@ -330,0 +487,0 @@ /******/ ]) |
{ | ||
"name": "sniff-fns", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"author": "Ivan Shornikov <paraboom@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Browser agent sniffing functions", |
@@ -14,2 +14,7 @@ var isChrome = require('../is_browser_chrome'); | ||
it("returns true if it's Chromium's user agent", function() { | ||
expect(isChrome('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.10 Chromium/18.0.1025.142 Chrome/18.0.1025.142 Safari/535.19')) | ||
.to.be.true | ||
}) | ||
it('returns false if string doesn\'t belongs to chrome\'s user agent', function(){ | ||
@@ -16,0 +21,0 @@ var NotChromeUserAgents = [ |
@@ -7,3 +7,5 @@ // Browsers | ||
var isSafari = require('./is_browser_safari'); | ||
var isIE = require('./is_browser_ie'); | ||
var whichBrowser = require('./which_browser'); | ||
var whichBrowserVersion = require('./which_browser_version'); | ||
@@ -32,3 +34,5 @@ // OSes | ||
isSafari: isSafari, | ||
whichBrowser: whichBrowser | ||
isIE: isIE, | ||
whichBrowser: whichBrowser, | ||
whichBrowserVersion: whichBrowserVersion | ||
}, | ||
@@ -35,0 +39,0 @@ isIphone: isIphone, |
@@ -6,2 +6,3 @@ var isChrome = require('./is_browser_chrome'); | ||
var isSafari = require('./is_browser_safari'); | ||
var isIE = require('./is_browser_ie'); | ||
@@ -19,2 +20,4 @@ var whichBrowser = function (str) { | ||
return 'safari' | ||
} else if (isIE(str)) { | ||
return 'ie' | ||
} else { | ||
@@ -21,0 +24,0 @@ return 'unknown browser' |
63615
56
1298