diff --git a/.vscode/launch.json b/.vscode/launch.json index 6a7a1b4..e9a2d2b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,12 +7,10 @@ { "type": "node", "request": "launch", - "name": "Launch via NPM", - "runtimeExecutable": "npm", - "runtimeArgs": [ - "test" - ], - "port": 5858 - } + "name": "Gulp test-server", + "program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js", + "args": ["test"], + "outputCapture": "std" + } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/bower.json b/bower.json index 595e9dc..abe2021 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ng-device-detector", - "version": "4.0.4", + "version": "5.0.1", "homepage": "https://github.com/srfrnk/ng-device-detector", "authors": [ "srfrnk " @@ -24,6 +24,7 @@ "tests" ], "dependencies": { - "re-tree": "^0.0.2" + "re-tree": "^0.0.2", + "ua-device-detector": "^1.0.1" } } diff --git a/changelog.md b/changelog.md index bd40c2f..bf35e6a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -#Version 1.1.7 +# Version 1.1.7 * device id "firefoxos" was changed to "firefox-os" * os id "firefoxos" was changed to "firefox-os" @@ -6,3 +6,8 @@ * Breaking changes * Removed OS and BROWSER for device types. * Should now detect those by using the 'device' property + +# Version 5.0.1 +* Breaking changes: +* ua-device-detector script must now be loaded before ng-device-detector script. Consult [README](readme.md) for more details. + diff --git a/karma.conf.js b/karma.conf.js index edde727..7dba0a0 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -11,6 +11,7 @@ module.exports = function (config) { 'node_modules/angular/angular.js', 'node_modules/angular-mocks/angular-mocks.js', 'node_modules/re-tree/re-tree.js', + 'node_modules/ua-device-detector/ua-device-detector.js', 'ng-device-detector.js', 'test/*.js' ], diff --git a/ng-device-detector.js b/ng-device-detector.js index b81b679..59dd07d 100644 --- a/ng-device-detector.js +++ b/ng-device-detector.js @@ -1,199 +1,9 @@ (function (angular) { "use strict"; - var BROWSERS = { - CHROME: "chrome", - FIREFOX: "firefox", - SAFARI: "safari", - OPERA: "opera", - IE: "ie", - MS_EDGE: "ms-edge", - FB_MESSENGER: "fb-messenger", - CORDOVA: "cordova", - UNKNOWN: "unknown" - }; - - var DEVICES = { - ANDROID: "android", - I_PAD: "ipad", - IPHONE: "iphone", - I_POD: "ipod", - BLACKBERRY: "blackberry", - FIREFOX_OS: "firefox-os", - CHROME_BOOK: "chrome-book", - WINDOWS_PHONE: "windows-phone", - PS4: "ps4", - VITA: "vita", - CHROMECAST: "chromecast", - APPLE_TV: "apple-tv", - GOOGLE_TV: "google-tv", - UNKNOWN: "unknown" - }; - - var OS = { - WINDOWS: "windows", - MAC: "mac", - IOS: "ios", - ANDROID: "android", - LINUX: "linux", - UNIX: "unix", - FIREFOX_OS: "firefox-os", - CHROME_OS: "chrome-os", - WINDOWS_PHONE: "windows-phone", - UNKNOWN: "unknown" - }; - - var OS_VERSIONS = { - WINDOWS_3_11: "windows-3-11", - WINDOWS_95: "windows-95", - WINDOWS_ME: "windows-me", - WINDOWS_98: "windows-98", - WINDOWS_CE: "windows-ce", - WINDOWS_2000: "windows-2000", - WINDOWS_XP: "windows-xp", - WINDOWS_SERVER_2003: "windows-server-2003", - WINDOWS_VISTA: "windows-vista", - WINDOWS_7: "windows-7", - WINDOWS_8_1: "windows-8-1", - WINDOWS_8: "windows-8", - WINDOWS_10: "windows-10", - WINDOWS_PHONE_7_5: "windows-phone-7-5", - WINDOWS_PHONE_8_1: "windows-phone-8-1", - WINDOWS_PHONE_10: "windows-phone-10", - WINDOWS_NT_4_0: "windows-nt-4-0", - MACOSX_15: "mac-os-x-15", - MACOSX_14: "mac-os-x-14", - MACOSX_13: "mac-os-x-13", - MACOSX_12: "mac-os-x-12", - MACOSX_11: "mac-os-x-11", - MACOSX_10: "mac-os-x-10", - MACOSX_9: "mac-os-x-9", - MACOSX_8: "mac-os-x-8", - MACOSX_7: "mac-os-x-7", - MACOSX_6: "mac-os-x-6", - MACOSX_5: "mac-os-x-5", - MACOSX_4: "mac-os-x-4", - MACOSX_3: "mac-os-x-3", - MACOSX_2: "mac-os-x-2", - MACOSX: "mac-os-x", - UNKNOWN: "unknown" - }; - - var OS_RE = { - WINDOWS: { and: [{ or: [/\bWindows|(Win\d\d)\b/, /\bWin 9x\b/] }, { not: /\bWindows Phone\b/ }] }, - MAC: { and: [/\bMac OS\b/, { not: /Windows Phone/ }] }, - IOS: { and: [{ or: [/\biPad\b/, /\biPhone\b/, /\biPod\b/] }, { not: /Windows Phone/ }] }, - ANDROID: { and: [/\bAndroid\b/, { not: /Windows Phone/ }] }, - LINUX: /\bLinux\b/, - UNIX: /\bUNIX\b/, - FIREFOX_OS: { and: [/\bFirefox\b/, /Mobile\b/] }, - CHROME_OS: /\bCrOS\b/, - WINDOWS_PHONE: { or: [/\bIEMobile\b/, /\bWindows Phone\b/] }, - PS4: /\bMozilla\/5.0 \(PlayStation 4\b/, - VITA: /\bMozilla\/5.0 \(Play(S|s)tation Vita\b/ - }; - - var BROWSERS_RE = { - CHROME: { and: [{ or: [/\bChrome\b/, /\bCriOS\b/] }, { not: { or: [/\bOPR\b/, /\bEdge\b/, /\bCordova\b/] } }] }, - FIREFOX: { and: [{ or: [/\bFirefox\b/, /\bFxiOS\b/] }, { not: /\bCordova\b/ }] }, - SAFARI: { and: [/^((?!CriOS).)*\Safari\b.*$/, { not: { or: [/\bOPR\b/, /\bEdge\b/, /Windows Phone/, /\bCordova\b/, /\bChrome\b/] } }] }, - OPERA: { or: [/Opera\b/, /\bOPR\b/] }, - IE: { or: [/\bMSIE\b/, /\bTrident\b/, /^Mozilla\/5\.0 \(Windows NT 10\.0; Win64; x64\)$/] }, - MS_EDGE: { or: [/\bEdge\b/] }, - PS4: /\bMozilla\/5.0 \(PlayStation 4\b/, - VITA: /\bMozilla\/5.0 \(Play(S|s)tation Vita\b/, - CORDOVA: /\bCordova\b/, - FB_MESSENGER: /\bFBAN\/MessengerForiOS\b/ - }; - - var DEVICES_RE = { - ANDROID: { and: [/\bAndroid\b/, { not: /Windows Phone/ }] }, - I_PAD: /\biPad\b/, - IPHONE: { and: [/\biPhone\b/, { not: /Windows Phone/ }] }, - I_POD: /\biPod\b/, - BLACKBERRY: /\bblackberry\b/, - FIREFOX_OS: { and: [/\bFirefox\b/, /\bMobile\b/] }, - CHROME_BOOK: /\bCrOS\b/, - WINDOWS_PHONE: { or: [/\bIEMobile\b/, /\bWindows Phone\b/] }, - PS4: /\bMozilla\/5.0 \(PlayStation 4\b/, - CHROMECAST: /\bCrKey\b/, - APPLE_TV: /^iTunes-AppleTV\/4.1$/, - GOOGLE_TV: /\bGoogleTV\b/, - VITA: /\bMozilla\/5.0 \(Play(S|s)tation Vita\b/ - }; - - var OS_VERSIONS_RE = { - WINDOWS_3_11: /Win16/, - WINDOWS_95: /(Windows 95|Win95|Windows_95)/, - WINDOWS_ME: /(Win 9x 4.90|Windows ME)/, - WINDOWS_98: /(Windows 98|Win98)/, - WINDOWS_CE: /Windows CE/, - WINDOWS_2000: /(Windows NT 5.0|Windows 2000)/, - WINDOWS_XP: /(Windows NT 5.1|Windows XP)/, - WINDOWS_SERVER_2003: /Windows NT 5.2/, - WINDOWS_VISTA: /Windows NT 6.0/, - WINDOWS_7: /(Windows 7|Windows NT 6.1)/, - WINDOWS_8_1: /(Windows 8.1|Windows NT 6.3)/, - WINDOWS_8: /(Windows 8|Windows NT 6.2)/, - WINDOWS_10: /(Windows NT 10.0)/, - WINDOWS_PHONE_7_5: /(Windows Phone OS 7.5)/, - WINDOWS_PHONE_8_1: /(Windows Phone 8.1)/, - WINDOWS_PHONE_10: /(Windows Phone 10)/, - WINDOWS_NT_4_0: { and: [/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/, { not: /Windows NT 10.0/ }] }, - MACOSX: /(MAC OS X\s*[^ 0-9])/, - MACOSX_3: /(Darwin 10.3|Mac OS X 10.3)/, - MACOSX_4: /(Darwin 10.4|Mac OS X 10.4)/, - MACOSX_5: /(Mac OS X 10.5)/, - MACOSX_6: /(Mac OS X 10.6)/, - MACOSX_7: /(Mac OS X 10.7)/, - MACOSX_8: /(Mac OS X 10.8)/, - MACOSX_9: /(Mac OS X 10.9)/, - MACOSX_10: /(Mac OS X 10.10)/, - MACOSX_11: /(Mac OS X 10.11)/, - MACOSX_12: /(Mac OS X 10.12)/, - MACOSX_13: /(Mac OS X 10.13)/, - MACOSX_14: /(Mac OS X 10.14)/, - MACOSX_15: /(Mac OS X 10.15)/ - }; - - var BROWSER_VERSIONS_RE_MAP = { - CHROME: [/\bChrome\/([\d\.]+)\b/, /\bCriOS\/([\d\.]+)\b/], - FIREFOX: [/\bFirefox\/([\d\.]+)\b/, /\bFxiOS\/([\d\.]+)\b/], - SAFARI: /\bVersion\/([\d\.]+)\b/, - OPERA: [/\bVersion\/([\d\.]+)\b/, /\bOPR\/([\d\.]+)\b/], - IE: [/\bMSIE ([\d\.]+\w?)\b/, /\brv:([\d\.]+\w?)\b/], - CORDOVA: /\bCordova\/([\d\.]+)\b/, - MS_EDGE: /\bEdge\/([\d\.]+)\b/ - }; - - var BROWSER_VERSIONS_RE = Object.keys(BROWSER_VERSIONS_RE_MAP).reduce(function (obj, key) { - obj[BROWSERS[key]] = BROWSER_VERSIONS_RE_MAP[key]; - return obj; - }, {}); - - angular.module("ng.deviceDetector", ["reTree"]) - .constant("OS_RE", OS_RE) - - .constant("BROWSERS_RE", BROWSERS_RE) - - .constant("DEVICES_RE", DEVICES_RE) - - .constant("OS_VERSIONS_RE", OS_VERSIONS_RE) - - .constant("BROWSER_VERSIONS_RE_MAP", BROWSER_VERSIONS_RE_MAP) - - .constant("BROWSER_VERSIONS_RE", BROWSER_VERSIONS_RE) - - .constant("BROWSERS", BROWSERS) - - .constant("DEVICES", DEVICES) - - .constant("OS", OS) - - .constant("OS_VERSIONS", OS_VERSIONS) - - .service("detectUtils", ["deviceDetector", "DEVICES", "BROWSERS", "OS", - function (deviceDetector, DEVICES, BROWSERS, OS) { + angular.module("ng.deviceDetector", ["reTree", "uaDeviceDetector"]) + .service("detectUtils", ["deviceDetector", "uaDeviceDetector", + function (deviceDetector, uaDeviceDetector) { var deviceInfo = deviceDetector; this.isMobile = function () { @@ -201,11 +11,12 @@ }; this.isAndroid = function () { - return (deviceInfo.device === DEVICES.ANDROID || deviceInfo.OS === OS.ANDROID); + return (deviceInfo.device === uaDeviceDetector.DEVICES.ANDROID || deviceInfo.OS === uaDeviceDetector.OS.ANDROID); }; this.isIOS = function () { - return (deviceInfo.os === OS.IOS || deviceInfo.device === DEVICES.I_POD || deviceInfo.device === DEVICES.IPHONE); + return (deviceInfo.os === uaDeviceDetector.OS.IOS || deviceInfo.device === uaDeviceDetector.DEVICES.I_POD || + deviceInfo.device === uaDeviceDetector.DEVICES.IPHONE); }; } ]) @@ -216,273 +27,17 @@ }; this.$get = [ "$window", - "DEVICES", - "BROWSERS", - "OS", - "OS_VERSIONS", + "uaDeviceDetector", "reTree", - "OS_RE", - "BROWSERS_RE", - "DEVICES_RE", - "OS_VERSIONS_RE", - "BROWSER_VERSIONS_RE_MAP", - "BROWSER_VERSIONS_RE", function ( $window, - DEVICES, - BROWSERS, - OS, - OS_VERSIONS, - reTree, - OS_RE, - BROWSERS_RE, - DEVICES_RE, - OS_VERSIONS_RE, - BROWSER_VERSIONS_RE_MAP, - BROWSER_VERSIONS_RE + uaDeviceDetector, + reTree ) { - /* ES5 polyfills Start*/ - - // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys - if (!Object.keys) { - Object.keys = (function () { - 'use strict'; - var hasOwnProperty = Object.prototype.hasOwnProperty, - hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'), - dontEnums = [ - 'toString', - 'toLocaleString', - 'valueOf', - 'hasOwnProperty', - 'isPrototypeOf', - 'propertyIsEnumerable', - 'constructor' - ], - dontEnumsLength = dontEnums.length; - - return function (obj) { - if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) { - throw new TypeError('Object.keys called on non-object'); - } - - var result = [], prop, i; - - for (prop in obj) { - if (hasOwnProperty.call(obj, prop)) { - result.push(prop); - } - } - - if (hasDontEnumBug) { - for (i = 0; i < dontEnumsLength; i++) { - if (hasOwnProperty.call(obj, dontEnums[i])) { - result.push(dontEnums[i]); - } - } - } - return result; - }; - }()); - } - - // Production steps of ECMA-262, Edition 5, 15.4.4.21 - // Reference: http://es5.github.io/#x15.4.4.21 - if (!Array.prototype.reduce) { - Array.prototype.reduce = function (callback /*, initialValue*/) { - 'use strict'; - if (this == null) { - throw new TypeError('Array.prototype.reduce called on null or undefined'); - } - if (typeof callback !== 'function') { - throw new TypeError(callback + ' is not a function'); - } - var t = Object(this), len = t.length >>> 0, k = 0, value; - if (arguments.length == 2) { - value = arguments[1]; - } else { - while (k < len && !(k in t)) { - k++; - } - if (k >= len) { - throw new TypeError('Reduce of empty array with no initial value'); - } - value = t[k++]; - } - for (; k < len; k++) { - if (k in t) { - value = callback(value, t[k], k, t); - } - } - return value; - }; - } - /* ES5 polyfills End*/ - var ua = $window.navigator.userAgent; - var deviceInfo = parseUserAgent(ua); - deviceInfo.parseUserAgent = parseUserAgent; + var deviceInfo = uaDeviceDetector.parseUserAgent(ua); + deviceInfo.parseUserAgent = uaDeviceDetector.parseUserAgent; return deviceInfo; - - function parseUserAgent(ua) { - var deviceInfo = { - raw: { - userAgent: ua, - os: {}, - browser: {}, - device: {} - } - }; - - deviceInfo.raw.os = Object.keys(OS).reduce(function (obj, item) { - obj[OS[item]] = reTree.test(ua, OS_RE[item]); - return obj; - }, {}); - - deviceInfo.raw.browser = Object.keys(BROWSERS).reduce(function (obj, item) { - obj[BROWSERS[item]] = reTree.test(ua, BROWSERS_RE[item]); - return obj; - }, {}); - - deviceInfo.raw.device = Object.keys(DEVICES).reduce(function (obj, item) { - obj[DEVICES[item]] = reTree.test(ua, DEVICES_RE[item]); - return obj; - }, {}); - - deviceInfo.raw.os_version = Object.keys(OS_VERSIONS).reduce(function (obj, item) { - obj[OS_VERSIONS[item]] = reTree.test(ua, OS_VERSIONS_RE[item]); - return obj; - }, {}); - - deviceInfo.os = [ - OS.WINDOWS, - OS.IOS, - OS.MAC, - OS.ANDROID, - OS.LINUX, - OS.UNIX, - OS.FIREFOX_OS, - OS.CHROME_OS, - OS.WINDOWS_PHONE - ].reduce(function (previousValue, currentValue) { - return (previousValue === OS.UNKNOWN && deviceInfo.raw.os[currentValue]) ? currentValue : previousValue; - }, OS.UNKNOWN); - - deviceInfo.browser = [ - BROWSERS.CHROME, - BROWSERS.FIREFOX, - BROWSERS.SAFARI, - BROWSERS.OPERA, - BROWSERS.IE, - BROWSERS.MS_EDGE, - BROWSERS.CORDOVA, - BROWSERS.FB_MESSENGER - ].reduce(function (previousValue, currentValue) { - return (previousValue === BROWSERS.UNKNOWN && deviceInfo.raw.browser[currentValue]) ? currentValue : previousValue; - }, BROWSERS.UNKNOWN); - - deviceInfo.device = [ - DEVICES.ANDROID, - DEVICES.I_PAD, - DEVICES.IPHONE, - DEVICES.I_POD, - DEVICES.BLACKBERRY, - DEVICES.FIREFOX_OS, - DEVICES.CHROME_BOOK, - DEVICES.WINDOWS_PHONE, - DEVICES.PS4, - DEVICES.CHROMECAST, - DEVICES.APPLE_TV, - DEVICES.GOOGLE_TV, - DEVICES.VITA - ].reduce(function (previousValue, currentValue) { - return (previousValue === DEVICES.UNKNOWN && deviceInfo.raw.device[currentValue]) ? currentValue : previousValue; - }, DEVICES.UNKNOWN); - - deviceInfo.os_version = [ - OS_VERSIONS.WINDOWS_3_11, - OS_VERSIONS.WINDOWS_95, - OS_VERSIONS.WINDOWS_ME, - OS_VERSIONS.WINDOWS_98, - OS_VERSIONS.WINDOWS_CE, - OS_VERSIONS.WINDOWS_2000, - OS_VERSIONS.WINDOWS_XP, - OS_VERSIONS.WINDOWS_SERVER_2003, - OS_VERSIONS.WINDOWS_VISTA, - OS_VERSIONS.WINDOWS_7, - OS_VERSIONS.WINDOWS_8_1, - OS_VERSIONS.WINDOWS_8, - OS_VERSIONS.WINDOWS_10, - OS_VERSIONS.WINDOWS_PHONE_7_5, - OS_VERSIONS.WINDOWS_PHONE_8_1, - OS_VERSIONS.WINDOWS_PHONE_10, - OS_VERSIONS.WINDOWS_NT_4_0, - OS_VERSIONS.MACOSX, - OS_VERSIONS.MACOSX_3, - OS_VERSIONS.MACOSX_4, - OS_VERSIONS.MACOSX_5, - OS_VERSIONS.MACOSX_6, - OS_VERSIONS.MACOSX_7, - OS_VERSIONS.MACOSX_8, - OS_VERSIONS.MACOSX_9, - OS_VERSIONS.MACOSX_10, - OS_VERSIONS.MACOSX_11, - OS_VERSIONS.MACOSX_12, - OS_VERSIONS.MACOSX_13, - OS_VERSIONS.MACOSX_14, - OS_VERSIONS.MACOSX_15 - ].reduce(function (previousValue, currentValue) { - return (previousValue === OS_VERSIONS.UNKNOWN && deviceInfo.raw.os_version[currentValue]) ? currentValue : previousValue; - }, OS_VERSIONS.UNKNOWN); - - deviceInfo.browser_version = "0"; - if (deviceInfo.browser !== BROWSERS.UNKNOWN) { - var re = BROWSER_VERSIONS_RE[deviceInfo.browser]; - var res = reTree.exec(ua, re); - if (!!res) { - deviceInfo.browser_version = res[1]; - } - } - - deviceInfo.isMobile = function () { - return [ - DEVICES.ANDROID, - DEVICES.I_PAD, - DEVICES.IPHONE, - DEVICES.I_POD, - DEVICES.BLACKBERRY, - DEVICES.FIREFOX_OS, - DEVICES.WINDOWS_PHONE, - DEVICES.VITA - ].some(function (item) { - return deviceInfo.device == item; - }); - }; - - deviceInfo.isTablet = function () { - return [ - DEVICES.I_PAD, - DEVICES.FIREFOX_OS - ].some(function (item) { - return deviceInfo.device == item; - }); - }; - - deviceInfo.isDesktop = function () { - return [ - DEVICES.PS4, - DEVICES.CHROME_BOOK, - DEVICES.UNKNOWN - ].some(function (item) { - return deviceInfo.device == item; - }); - }; - - deviceInfo.custom = customDetectors.reduce(function (custom, customDetector) { - custom[customDetector.name] = reTree.test(ua, customDetector.re); - return custom; - }, {}); - return deviceInfo; - } }]; } ) diff --git a/ng-device-detector.min.js b/ng-device-detector.min.js index 8fd1656..65e8421 100644 --- a/ng-device-detector.min.js +++ b/ng-device-detector.min.js @@ -1 +1 @@ -!function(o){"use strict";var n={CHROME:"chrome",FIREFOX:"firefox",SAFARI:"safari",OPERA:"opera",IE:"ie",MS_EDGE:"ms-edge",FB_MESSENGER:"fb-messenger",CORDOVA:"cordova",UNKNOWN:"unknown"},e={ANDROID:"android",I_PAD:"ipad",IPHONE:"iphone",I_POD:"ipod",BLACKBERRY:"blackberry",FIREFOX_OS:"firefox-os",CHROME_BOOK:"chrome-book",WINDOWS_PHONE:"windows-phone",PS4:"ps4",VITA:"vita",CHROMECAST:"chromecast",APPLE_TV:"apple-tv",GOOGLE_TV:"google-tv",UNKNOWN:"unknown"},O={WINDOWS:"windows",MAC:"mac",IOS:"ios",ANDROID:"android",LINUX:"linux",UNIX:"unix",FIREFOX_OS:"firefox-os",CHROME_OS:"chrome-os",WINDOWS_PHONE:"windows-phone",UNKNOWN:"unknown"},r={WINDOWS_3_11:"windows-3-11",WINDOWS_95:"windows-95",WINDOWS_ME:"windows-me",WINDOWS_98:"windows-98",WINDOWS_CE:"windows-ce",WINDOWS_2000:"windows-2000",WINDOWS_XP:"windows-xp",WINDOWS_SERVER_2003:"windows-server-2003",WINDOWS_VISTA:"windows-vista",WINDOWS_7:"windows-7",WINDOWS_8_1:"windows-8-1",WINDOWS_8:"windows-8",WINDOWS_10:"windows-10",WINDOWS_PHONE_7_5:"windows-phone-7-5",WINDOWS_PHONE_8_1:"windows-phone-8-1",WINDOWS_PHONE_10:"windows-phone-10",WINDOWS_NT_4_0:"windows-nt-4-0",MACOSX_15:"mac-os-x-15",MACOSX_14:"mac-os-x-14",MACOSX_13:"mac-os-x-13",MACOSX_12:"mac-os-x-12",MACOSX_11:"mac-os-x-11",MACOSX_10:"mac-os-x-10",MACOSX_9:"mac-os-x-9",MACOSX_8:"mac-os-x-8",MACOSX_7:"mac-os-x-7",MACOSX_6:"mac-os-x-6",MACOSX_5:"mac-os-x-5",MACOSX_4:"mac-os-x-4",MACOSX_3:"mac-os-x-3",MACOSX_2:"mac-os-x-2",MACOSX:"mac-os-x",UNKNOWN:"unknown"},i={WINDOWS:{and:[{or:[/\bWindows|(Win\d\d)\b/,/\bWin 9x\b/]},{not:/\bWindows Phone\b/}]},MAC:{and:[/\bMac OS\b/,{not:/Windows Phone/}]},IOS:{and:[{or:[/\biPad\b/,/\biPhone\b/,/\biPod\b/]},{not:/Windows Phone/}]},ANDROID:{and:[/\bAndroid\b/,{not:/Windows Phone/}]},LINUX:/\bLinux\b/,UNIX:/\bUNIX\b/,FIREFOX_OS:{and:[/\bFirefox\b/,/Mobile\b/]},CHROME_OS:/\bCrOS\b/,WINDOWS_PHONE:{or:[/\bIEMobile\b/,/\bWindows Phone\b/]},PS4:/\bMozilla\/5.0 \(PlayStation 4\b/,VITA:/\bMozilla\/5.0 \(Play(S|s)tation Vita\b/},S={CHROME:{and:[{or:[/\bChrome\b/,/\bCriOS\b/]},{not:{or:[/\bOPR\b/,/\bEdge\b/,/\bCordova\b/]}}]},FIREFOX:{and:[{or:[/\bFirefox\b/,/\bFxiOS\b/]},{not:/\bCordova\b/}]},SAFARI:{and:[/^((?!CriOS).)*\Safari\b.*$/,{not:{or:[/\bOPR\b/,/\bEdge\b/,/Windows Phone/,/\bCordova\b/,/\bChrome\b/]}}]},OPERA:{or:[/Opera\b/,/\bOPR\b/]},IE:{or:[/\bMSIE\b/,/\bTrident\b/,/^Mozilla\/5\.0 \(Windows NT 10\.0; Win64; x64\)$/]},MS_EDGE:{or:[/\bEdge\b/]},PS4:/\bMozilla\/5.0 \(PlayStation 4\b/,VITA:/\bMozilla\/5.0 \(Play(S|s)tation Vita\b/,CORDOVA:/\bCordova\b/,FB_MESSENGER:/\bFBAN\/MessengerForiOS\b/},t={ANDROID:{and:[/\bAndroid\b/,{not:/Windows Phone/}]},I_PAD:/\biPad\b/,IPHONE:{and:[/\biPhone\b/,{not:/Windows Phone/}]},I_POD:/\biPod\b/,BLACKBERRY:/\bblackberry\b/,FIREFOX_OS:{and:[/\bFirefox\b/,/\bMobile\b/]},CHROME_BOOK:/\bCrOS\b/,WINDOWS_PHONE:{or:[/\bIEMobile\b/,/\bWindows Phone\b/]},PS4:/\bMozilla\/5.0 \(PlayStation 4\b/,CHROMECAST:/\bCrKey\b/,APPLE_TV:/^iTunes-AppleTV\/4.1$/,GOOGLE_TV:/\bGoogleTV\b/,VITA:/\bMozilla\/5.0 \(Play(S|s)tation Vita\b/},s={WINDOWS_3_11:/Win16/,WINDOWS_95:/(Windows 95|Win95|Windows_95)/,WINDOWS_ME:/(Win 9x 4.90|Windows ME)/,WINDOWS_98:/(Windows 98|Win98)/,WINDOWS_CE:/Windows CE/,WINDOWS_2000:/(Windows NT 5.0|Windows 2000)/,WINDOWS_XP:/(Windows NT 5.1|Windows XP)/,WINDOWS_SERVER_2003:/Windows NT 5.2/,WINDOWS_VISTA:/Windows NT 6.0/,WINDOWS_7:/(Windows 7|Windows NT 6.1)/,WINDOWS_8_1:/(Windows 8.1|Windows NT 6.3)/,WINDOWS_8:/(Windows 8|Windows NT 6.2)/,WINDOWS_10:/(Windows NT 10.0)/,WINDOWS_PHONE_7_5:/(Windows Phone OS 7.5)/,WINDOWS_PHONE_8_1:/(Windows Phone 8.1)/,WINDOWS_PHONE_10:/(Windows Phone 10)/,WINDOWS_NT_4_0:{and:[/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/,{not:/Windows NT 10.0/}]},MACOSX:/(MAC OS X\s*[^ 0-9])/,MACOSX_3:/(Darwin 10.3|Mac OS X 10.3)/,MACOSX_4:/(Darwin 10.4|Mac OS X 10.4)/,MACOSX_5:/(Mac OS X 10.5)/,MACOSX_6:/(Mac OS X 10.6)/,MACOSX_7:/(Mac OS X 10.7)/,MACOSX_8:/(Mac OS X 10.8)/,MACOSX_9:/(Mac OS X 10.9)/,MACOSX_10:/(Mac OS X 10.10)/,MACOSX_11:/(Mac OS X 10.11)/,MACOSX_12:/(Mac OS X 10.12)/,MACOSX_13:/(Mac OS X 10.13)/,MACOSX_14:/(Mac OS X 10.14)/,MACOSX_15:/(Mac OS X 10.15)/},_={CHROME:[/\bChrome\/([\d\.]+)\b/,/\bCriOS\/([\d\.]+)\b/],FIREFOX:[/\bFirefox\/([\d\.]+)\b/,/\bFxiOS\/([\d\.]+)\b/],SAFARI:/\bVersion\/([\d\.]+)\b/,OPERA:[/\bVersion\/([\d\.]+)\b/,/\bOPR\/([\d\.]+)\b/],IE:[/\bMSIE ([\d\.]+\w?)\b/,/\brv:([\d\.]+\w?)\b/],CORDOVA:/\bCordova\/([\d\.]+)\b/,MS_EDGE:/\bEdge\/([\d\.]+)\b/},W=Object.keys(_).reduce(function(o,e){return o[n[e]]=_[e],o},{});o.module("ng.deviceDetector",["reTree"]).constant("OS_RE",i).constant("BROWSERS_RE",S).constant("DEVICES_RE",t).constant("OS_VERSIONS_RE",s).constant("BROWSER_VERSIONS_RE_MAP",_).constant("BROWSER_VERSIONS_RE",W).constant("BROWSERS",n).constant("DEVICES",e).constant("OS",O).constant("OS_VERSIONS",r).service("detectUtils",["deviceDetector","DEVICES","BROWSERS","OS",function(o,n,e,O){var r=o;this.isMobile=function(){return"unknown"!==r.device},this.isAndroid=function(){return r.device===n.ANDROID||r.OS===O.ANDROID},this.isIOS=function(){return r.os===O.IOS||r.device===n.I_POD||r.device===n.IPHONE}}]).provider("deviceDetector",function(){var o=[];this.addCustom=function(n,e){o.push({name:n,re:e})},this.$get=["$window","DEVICES","BROWSERS","OS","OS_VERSIONS","reTree","OS_RE","BROWSERS_RE","DEVICES_RE","OS_VERSIONS_RE","BROWSER_VERSIONS_RE_MAP","BROWSER_VERSIONS_RE",function(n,e,O,r,i,S,t,s,_,W,N,b){Object.keys||(Object.keys=function(){var o=Object.prototype.hasOwnProperty,n=!{toString:null}.propertyIsEnumerable("toString"),e=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],O=e.length;return function(r){if("object"!=typeof r&&("function"!=typeof r||null===r))throw new TypeError("Object.keys called on non-object");var i,S,t=[];for(i in r)o.call(r,i)&&t.push(i);if(n)for(S=0;S>>0,r=0;if(2==arguments.length)n=arguments[1];else{for(;r=O)throw new TypeError("Reduce of empty array with no initial value");n=e[r++]}for(;r + ``` Adding `'ng.deviceDetector'` to your app module dependencies diff --git a/test/unit.js b/test/unit.js index c7ea843..a299c9b 100644 --- a/test/unit.js +++ b/test/unit.js @@ -49,274 +49,6 @@ describe("ng-device-detector", function () { }); }); - describe("with user-agent", function () { - - function describeUserAgent(userAgent, os, os_version, browser, browser_version, device, isMobile, isTablet, isDesktop, extras) { - describe(userAgent, function () { - beforeEach(function () { - loadDetector(userAgent); - }); - - it("should detect os = " + os, function () { - expect(deviceDetector.os).toBe(os); - }); - it("should detect os version = " + os_version, function () { - expect(deviceDetector.os_version).toBe(os_version); - }); - it("should detect browser = " + browser, function () { - expect(deviceDetector.browser).toBe(browser); - }); - it("should detect browser version= " + browser_version, function () { - expect(deviceDetector.browser_version).toBe(browser_version); - }); - it("should detect device = " + device, function () { - expect(deviceDetector.device).toBe(device); - }); - it("should have isMobile = " + isMobile, function () { - expect(deviceDetector.isMobile()).toBe(isMobile); - }); - it("should have isTablet = " + isTablet, function () { - expect(deviceDetector.isTablet()).toBe(isTablet); - }); - it("should have isDesktop = " + isDesktop, function () { - expect(deviceDetector.isDesktop()).toBe(isDesktop); - }); - if (!!extras) { - extras.apply(null, []); - } - }); - } - - // Chrome - describeUserAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-8-1", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1664.3 Safari/537.36", - "mac", "mac-os-x-9", "chrome", "32.0.1664.3", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21", - "linux", "unknown", "chrome", "19.0.1042.0", "unknown", false, false, true); - - // Firefox - describeUserAgent("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0", - "windows", "windows-xp", "firefox", "31.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:25.0) Gecko/20100101 Firefox/25.0", - "mac", "mac-os-x-6", "firefox", "25.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0", - "linux", "unknown", "firefox", "24.0", "unknown", false, false, true); - - // Safari - describeUserAgent("Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25", - "ios", "unknown", "safari", "6.0", "ipad", true, true, false); - describeUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2", - "mac", "mac-os-x-6", "safari", "5.1.7", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+", - "linux", "unknown", "safari", "5.0", "unknown", false, false, true); - - // Issue #10 - describeUserAgent("Mozilla/5.0 (iPad; CPU OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) CriOS/38.0.2125.59 Mobile/12A405 Safari/600.1.4 (000767)", - "ios", "unknown", "chrome", "38.0.2125.59", "ipad", true, true, false); - - // Issue #14 - describeUserAgent("Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)", - "windows-phone", "windows-phone-7-5", "ie", "9.0", "windows-phone", true, false, false); - - // Issue #15 - describeUserAgent("Mozilla/5.0 (PlayStation 4 1.52) AppleWebKit/536.26 (KHTML, like Gecko)", - "unknown", "unknown", "unknown", "0", "ps4", false, false, true); - describeUserAgent("Mozilla/5.0 (Playstation Vita 1.61) AppleWebKit/531.22.8 (KHTML, like Gecko) Silk/3.2", - "unknown", "unknown", "unknown", "0", "vita", true, false, false); - - // Issue #18 - describeUserAgent("Mozilla/5.0 (Win16; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-3-11", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows 95; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-95", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Win95; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-95", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows_95; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-95", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Win 9x 4.90; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-me", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows ME; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-me", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows 98; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-98", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Win98; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-98", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows CE; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-ce", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows NT 5.0; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-2000", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows 2000; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-2000", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows NT 5.1; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-xp", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows XP; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-xp", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows NT 5.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-server-2003", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows NT 6.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-vista", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-7", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows 7; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-7", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-8-1", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows 8.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-8-1", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-8", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows 8; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-8", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows NT 4.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-nt-4-0", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (WinNT4.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-nt-4-0", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (WinNT; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-nt-4-0", "chrome", "37.0.2049.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows NT; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - "windows", "windows-nt-4-0", "chrome", "37.0.2049.0", "unknown", false, false, true); - - describeUserAgent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)", - "windows", "windows-nt-4-0", "ie", "6.0", "unknown", false, false, true); - describeUserAgent("Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 4.0)", - "windows", "windows-nt-4-0", "ie", "6.0b", "unknown", false, false, true); - describeUserAgent("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 4.0)", - "windows", "windows-nt-4-0", "ie", "7.0", "unknown", false, false, true); - describeUserAgent("Mozilla/4.0 (compatible; MSIE 10.0; Windows NT 4.0)", - "windows", "windows-nt-4-0", "ie", "10.0", "unknown", false, false, true); - describeUserAgent("Mozilla/4.0 (compatible; MSIE 11; Windows NT 4.0)", - "windows", "windows-nt-4-0", "ie", "11", "unknown", false, false, true); - - // Issue 21 - describeUserAgent("Mozilla/5.0 (Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko", - "windows", "windows-8-1", "ie", "11.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; rv:11.0) like Gecko", - "windows", "windows-7", "ie", "11.0", "unknown", false, false, true); - - // Issue 24 - describeUserAgent("Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36 OPR/29.0.1795.47", - "windows", "windows-8-1", "opera", "29.0.1795.47", "unknown", false, false, true); - - // Issue 27 - describeUserAgent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0", - "windows", "windows-10", "ms-edge", "12.0", "unknown", false, false, true); - describeUserAgent("Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; DEVICE INFO) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Mobile Safari/537.36 Edge/12.0", - "windows-phone", "windows-phone-10", "ms-edge", "12.0", "windows-phone", true, false, false); - - // Issue 29 - describeUserAgent("Mozilla/5.0 (X11; CrOS x86_64 4731.85.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36", - "chrome-os", "unknown", "chrome", "31.0.1650.63", "chrome-book", false, false, true); - - // Issue 32 - describeUserAgent("Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 930) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537", - "windows-phone", "windows-phone-8-1", "ie", "11.0", "windows-phone", true, false, false); - - // Issue 42 - describeUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/47.0.2526.107 Mobile/13C75 Safari/601.1.46", - "ios", "unknown", "chrome", "47.0.2526.107", "iphone", true, false, false); - - // Issue 43 - describe("ES5 support", function () { - beforeEach(function () { - Object.keys = undefined; - Array.prototype.reduce = undefined; - }); - - it("should load", function () { - loadDetector(""); - expect(deviceDetector).not.toBeNull(); - }); - }); - - // Issue 39 - describeUserAgent("Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13B143 [FBAN/MessengerForiOS;FBAV/48.0.0.20.47;FBBV/17291106;FBDV/iPad2,5;FBMD/iPad;FBSN/iPhone OS;FBSV/9.1;FBSS/1; FBCR/;FBID/tablet;FBLC/cs_CZ;FBOP/1]", - "ios", "unknown", "fb-messenger", "0", "ipad", true, true, false); - - // Issue 40 - describeUserAgent("Mozilla/5.0 (CrKey armv7l 1.4.15250) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.0 Safari/537.36", - "unknown", "unknown", "chrome", "31.0.1650.0", "chromecast", false, false, false); - describeUserAgent("iTunes-AppleTV/4.1", - "unknown", "unknown", "unknown", "0", "apple-tv", false, false, false); - describeUserAgent("Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Large Screen Safari/533.4 GoogleTV/ 162671", - "linux", "unknown", "chrome", "5.0.375.127", "google-tv", false, false, false); - - // Issue 44 - describeUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)", - "windows", "windows-10", "ie", "0", "unknown", false, false, true); - - // Issue 45 - describeUserAgent("Mozilla/5.0 (iPad; CPU OS 9_2_1 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/49.0.2623.73 Mobile/13D15 Safari/601.1.46", - "ios", "unknown", "chrome", "49.0.2623.73", "ipad", true, true, false); - - // Issue 53 - describeUserAgent("Mozilla/5.0 (iPad; CPU OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) FxiOS/6.0 Mobile/14C92 Safari/602.3.12", - "ios", "unknown", "firefox", "6.0", "ipad", true, true, false); - describeUserAgent("Mozilla/5.0 (iPad; CPU OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0 Mobile/14C92 Safari/602.1", - "ios", "unknown", "safari", "10.0", "ipad", true, true, false); - - // Issue 59 - describeUserAgent("Mozilla/5.0 (Linux; U; Android 4.0.4; es-ve; LT22i Build/ 6.1.1.B.1.54) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/ 534.30", - "android", "unknown", "safari", "4.0", "android", true, false, false); - describeUserAgent("Mozilla/5.0 (Linux; U; Android 4.0.4; es-ve; LT22i Build/ 6.1.1.B.1.54) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/ 534.30 Cordova/6.2.0", - "android", "unknown", "cordova", "6.2.0", "android", true, false, false); - - // Issue 61 - describeUserAgent("Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19", - "android", "unknown", "chrome", "18.0.1025.133", "android", true, false, false); - describeUserAgent("Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19 Cordova/6.2.0", - "android", "unknown", "cordova", "6.2.0", "android", true, false, false); - describeUserAgent("Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0", - "android", "unknown", "firefox", "41.0", "android", true, false, false); - describeUserAgent("Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0 Cordova/6.2.0", - "android", "unknown", "cordova", "6.2.0", "android", true, false, false); - - // Issue 62 - describeUserAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.88 Safari/537.36", - "windows", "windows-8-1", "chrome", "57.0.2987.88", "unknown", false, false, true, function () { - it("Should not have safari detected", function () { - expect(deviceDetector.raw.browser.safari).toBe(false); - }) - }); - }); - - describe("with custom detection", function () { - it("should detect custom entry is missing", function () { - loadDetector("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", function (deviceDetectorProvider) { - deviceDetectorProvider.addCustom("Custom_UA_Entry", /\bCustom_UA_Entry\b/); - }); - expect(deviceDetector.custom["Custom_UA_Entry"]).toBe(false); - }); - - it("should detect custom entry", function () { - loadDetector("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36 Custom_UA_Entry/1.1", function (deviceDetectorProvider) { - deviceDetectorProvider.addCustom("Custom_UA_Entry", /\bCustom_UA_Entry\b/); - }); - expect(deviceDetector.custom["Custom_UA_Entry"]).toBe(true); - }); - - it("should detect custom entry as string", function () { - loadDetector("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36 Custom_UA_Entry/1.1", function (deviceDetectorProvider) { - deviceDetectorProvider.addCustom("Custom_UA_Entry", "\\bCustom_UA_Entry\\b"); - }); - expect(deviceDetector.custom["Custom_UA_Entry"]).toBe(true); - }); - - it("should detect custom entry as reTree", function () { - loadDetector("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36 Custom_UA_Entry/1.1", function (deviceDetectorProvider) { - deviceDetectorProvider.addCustom("Custom_UA_Entry", { or: ["\\bCustom_UA_Entry\\b"] }); - }); - expect(deviceDetector.custom["Custom_UA_Entry"]).toBe(true); - }); - - it("should detect custom entry as complex reTree", function () { - loadDetector("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36 Custom_UA_Entry/1.1", function (deviceDetectorProvider) { - deviceDetectorProvider.addCustom("Custom_UA_Entry", { and: ["\\bCustom_UA_Entry\\b", { not: "\\bChrome\\b" }] }); - }); - expect(deviceDetector.custom["Custom_UA_Entry"]).toBe(false); - }); - }); - // Issue 72 describe("Test custom UA string parsing", function () { it("Should parse the specified UA", function () {