New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ng-device-detector

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-device-detector - npm Package Compare versions

Comparing version 4.0.3 to 5.0.1

.vscode/launch.json

5

bower.json
{
"name": "ng-device-detector",
"version": "4.0.3",
"version": "5.0.1",
"homepage": "https://github.com/srfrnk/ng-device-detector",

@@ -27,4 +27,5 @@ "authors": [

"dependencies": {
"re-tree": "^0.0.2"
"re-tree": "^0.0.2",
"ua-device-detector": "^1.0.1"
}
}

7

changelog.md

@@ -1,2 +0,2 @@

#Version 1.1.7
# Version 1.1.7
* device id "firefoxos" was changed to "firefox-os"

@@ -9,1 +9,6 @@ * os id "firefoxos" was changed to "firefox-os"

* 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.

@@ -14,2 +14,3 @@ module.exports = function (config) {

'node_modules/re-tree/re-tree.js',
'node_modules/ua-device-detector/ua-device-detector.js',
'ng-device-detector.js',

@@ -16,0 +17,0 @@ 'test/*.js'

(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;

@@ -204,7 +14,8 @@

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);
};

@@ -214,272 +25,21 @@ }

.provider("deviceDetector", function () {
var customDetectors = [];
this.addCustom = function (customDetectorName, customDetectorRE) {
customDetectors.push({name: customDetectorName, re: customDetectorRE});
};
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 (
$window,
DEVICES,
BROWSERS,
OS,
OS_VERSIONS,
reTree,
OS_RE,
BROWSERS_RE,
DEVICES_RE,
OS_VERSIONS_RE,
BROWSER_VERSIONS_RE_MAP,
BROWSER_VERSIONS_RE
) {
/* 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 customDetectors = [];
this.addCustom = function (customDetectorName, customDetectorRE) {
customDetectors.push({ name: customDetectorName, re: customDetectorRE });
};
this.$get = [
"$window",
"uaDeviceDetector",
"reTree",
function (
$window,
uaDeviceDetector,
reTree
) {
var ua = $window.navigator.userAgent;
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;
}, {});
var deviceInfo = uaDeviceDetector.parseUserAgent(ua);
deviceInfo.parseUserAgent = uaDeviceDetector.parseUserAgent;
return deviceInfo;
}];
}
}
)

@@ -486,0 +46,0 @@ .directive('deviceDetector', ["deviceDetector", function (deviceDetector) {

@@ -1,1 +0,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<O;S++)o.call(r,e[S])&&t.push(e[S]);return t}}()),Array.prototype.reduce||(Array.prototype.reduce=function(o){if(null==this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof o)throw new TypeError(o+" is not a function");var n,e=Object(this),O=e.length>>>0,r=0;if(2==arguments.length)n=arguments[1];else{for(;r<O&&!(r in e);)r++;if(r>=O)throw new TypeError("Reduce of empty array with no initial value");n=e[r++]}for(;r<O;r++)r in e&&(n=o(n,e[r],r,e));return n});var a=n.navigator.userAgent,d={raw:{userAgent:a,os:{},browser:{},device:{}}};if(d.raw.os=Object.keys(r).reduce(function(o,n){return o[r[n]]=S.test(a,t[n]),o},{}),d.raw.browser=Object.keys(O).reduce(function(o,n){return o[O[n]]=S.test(a,s[n]),o},{}),d.raw.device=Object.keys(e).reduce(function(o,n){return o[e[n]]=S.test(a,_[n]),o},{}),d.raw.os_version=Object.keys(i).reduce(function(o,n){return o[i[n]]=S.test(a,W[n]),o},{}),d.os=[r.WINDOWS,r.IOS,r.MAC,r.ANDROID,r.LINUX,r.UNIX,r.FIREFOX_OS,r.CHROME_OS,r.WINDOWS_PHONE].reduce(function(o,n){return o===r.UNKNOWN&&d.raw.os[n]?n:o},r.UNKNOWN),d.browser=[O.CHROME,O.FIREFOX,O.SAFARI,O.OPERA,O.IE,O.MS_EDGE,O.CORDOVA,O.FB_MESSENGER].reduce(function(o,n){return o===O.UNKNOWN&&d.raw.browser[n]?n:o},O.UNKNOWN),d.device=[e.ANDROID,e.I_PAD,e.IPHONE,e.I_POD,e.BLACKBERRY,e.FIREFOX_OS,e.CHROME_BOOK,e.WINDOWS_PHONE,e.PS4,e.CHROMECAST,e.APPLE_TV,e.GOOGLE_TV,e.VITA].reduce(function(o,n){return o===e.UNKNOWN&&d.raw.device[n]?n:o},e.UNKNOWN),d.os_version=[i.WINDOWS_3_11,i.WINDOWS_95,i.WINDOWS_ME,i.WINDOWS_98,i.WINDOWS_CE,i.WINDOWS_2000,i.WINDOWS_XP,i.WINDOWS_SERVER_2003,i.WINDOWS_VISTA,i.WINDOWS_7,i.WINDOWS_8_1,i.WINDOWS_8,i.WINDOWS_10,i.WINDOWS_PHONE_7_5,i.WINDOWS_PHONE_8_1,i.WINDOWS_PHONE_10,i.WINDOWS_NT_4_0,i.MACOSX,i.MACOSX_3,i.MACOSX_4,i.MACOSX_5,i.MACOSX_6,i.MACOSX_7,i.MACOSX_8,i.MACOSX_9,i.MACOSX_10,i.MACOSX_11,i.MACOSX_12,i.MACOSX_13,i.MACOSX_14,i.MACOSX_15].reduce(function(o,n){return o===i.UNKNOWN&&d.raw.os_version[n]?n:o},i.UNKNOWN),d.browser_version="0",d.browser!==O.UNKNOWN){var c=b[d.browser],E=S.exec(a,c);E&&(d.browser_version=E[1])}return d.isMobile=function(){return[e.ANDROID,e.I_PAD,e.IPHONE,e.I_POD,e.BLACKBERRY,e.FIREFOX_OS,e.WINDOWS_PHONE,e.VITA].some(function(o){return d.device==o})},d.isTablet=function(){return[e.I_PAD,e.FIREFOX_OS].some(function(o){return d.device==o})},d.isDesktop=function(){return[e.PS4,e.CHROME_BOOK,e.UNKNOWN].some(function(o){return d.device==o})},d.custom=o.reduce(function(o,n){return o[n.name]=S.test(a,n.re),o},{}),d}]}).directive("deviceDetector",["deviceDetector",function(o){function n(o){return"is-"+o.toLowerCase().replace(/[^0-9a-z]+/g,"-")}return{restrict:"A",link:function(e,O){O.addClass("os-"+o.os),O.addClass("browser-"+o.browser),O.addClass("device-"+o.device),O.toggleClass("is-mobile",o.isMobile()),O.toggleClass("is-tablet",o.isTablet()),O.toggleClass("is-desktop",o.isDesktop()),Object.keys(o.custom).forEach(function(e){O.toggleClass(n(e),o.custom[e])})}}}])}(angular);
!function(e){"use strict";e.module("ng.deviceDetector",["reTree","uaDeviceDetector"]).service("detectUtils",["deviceDetector","uaDeviceDetector",function(e,t){var i=e;this.isMobile=function(){return"unknown"!==i.device},this.isAndroid=function(){return i.device===t.DEVICES.ANDROID||i.OS===t.OS.ANDROID},this.isIOS=function(){return i.os===t.OS.IOS||i.device===t.DEVICES.I_POD||i.device===t.DEVICES.IPHONE}}]).provider("deviceDetector",function(){var e=[];this.addCustom=function(t,i){e.push({name:t,re:i})},this.$get=["$window","uaDeviceDetector","reTree",function(e,t,i){var s=e.navigator.userAgent,r=t.parseUserAgent(s);return r.parseUserAgent=t.parseUserAgent,r}]}).directive("deviceDetector",["deviceDetector",function(e){function t(e){return"is-"+e.toLowerCase().replace(/[^0-9a-z]+/g,"-")}return{restrict:"A",link:function(i,s){s.addClass("os-"+e.os),s.addClass("browser-"+e.browser),s.addClass("device-"+e.device),s.toggleClass("is-mobile",e.isMobile()),s.toggleClass("is-tablet",e.isTablet()),s.toggleClass("is-desktop",e.isDesktop()),Object.keys(e.custom).forEach(function(i){s.toggleClass(t(i),e.custom[i])})}}}])}(angular);
{
"name": "ng-device-detector",
"version": "4.0.3",
"version": "5.0.1",
"devDependencies": {
"angular": "~1.6.2",
"angular-mocks": "~1.6.2",
"angular": "^1.6.7",
"angular-mocks": "^1.6.7",
"gulp": "~3.9.1",
"gulp-bump": "~2.7.0",
"gulp-concat": "~2.6.1",
"gulp-filter": "~5.0.0",
"gulp-git": "~2.0.0",
"gulp-filter": "^5.0.1",
"gulp-git": "^2.0.1",
"gulp-karma": "0.0.5",

@@ -17,7 +17,7 @@ "gulp-tag-version": "~1.3.0",

"karma": "~1.5.0",
"karma-jasmine": "~1.1.0",
"karma-nested-reporter": "~0.1.4",
"karma-phantomjs-launcher": "~1.0.2",
"karma-jasmine": "^1.1.1",
"karma-nested-reporter": "^0.1.6",
"karma-phantomjs-launcher": "^1.0.4",
"phantomjs": "~2.1.7",
"uglify-js": "~2.8.5"
"uglify-js": "^2.8.29"
},

@@ -43,4 +43,5 @@ "scripts": {

"dependencies": {
"re-tree": "~0.0.2"
"re-tree": "~0.0.2",
"ua-device-detector": "^1.0.1"
}
}

@@ -1,17 +0,37 @@

#ng-device-detector
##Angular module to detect OS / Browser / Device
# ng-device-detector
##### Angular module to detect OS / Browser / Device
[![Build Status](https://travis-ci.org/srfrnk/ng-device-detector.svg?branch=master)](https://travis-ci.org/srfrnk/ng-device-detector)
Uses user-agent to set css classes or directly usable via JS.
Uses user-agent to set CSS classes or directly usable via JS.
See website: [http://srfrnk.github.io/ng-device-detector](http://srfrnk.github.io/ng-device-detector)
### Install
* Run $ `bower install ng-device-detector --save`
* Add script load to HTML:`<script type="text/javascript" src=".../re-tree.js"></script>`
* Add script load to HTML:`<script type="text/javascript" src=".../ng-device-detector.js"></script>`
* Add module to your app dependencies: `...angular.module("...", [..."ng.deviceDetector"...])...`
* To add classes - add directive like so- `<div ... device-detector ...>`
* To use directly add `"deviceDetector"` service to your injectors...
NPM
```sh
$ npm install ng-device-detector --save
```
Bower
```sh
$ bower install ng-device-detector --save
```
Browser (Add scripts in HTML)
```sh
<script type="text/javascript" src=".../re-tree.js"></script>
<script type="text/javascript" src=".../ua-device-detector.js"></script>
<script type="text/javascript" src=".../ng-device-detector.js"></script>
```
Adding `'ng.deviceDetector'` to your app module dependencies
```js
angular.module('app', ['ng.deviceDetector']);
```
Injecting *DeviceDetector* service in controller
```js
angular.module('app').controller('Home', function($scope, deviceDetector){
// Awesome stuff
});
```
To add classes, add directive like: `<div device-detector>`
### Setup

@@ -22,12 +42,18 @@

```javascript
angular.module(..., ["ng.deviceDetector"])
angular.module('app', ["ng.deviceDetector"])
.config(['deviceDetectorProvider', function(deviceDetectorProvider) {
deviceDetectorProvider.addCustom("Custom_UA_Entry",{and:["\\bCustom_UA_Entry\\b",{not:"\\bChrome\\b"}]});
deviceDetectorProvider.addCustom("Custom_UA_Entry", {
and:["\\bCustom_UA_Entry\\b", {
not:"\\bChrome\\b"
}]
});
}])
.controller(..., ["$scope", "deviceDetector", function($scope, deviceDetector) {
$scope.customUAEntry = deviceDetector.custom["Custom_UA_Entry"]; // true / false
}]);
.controller('Home', function($scope, deviceDetector) {
// (true / false)
$scope.customUAEntry = deviceDetector.custom["Custom_UA_Entry"];
});
```
Custom detectors will also be added as CSS classes with 'is-' prefix and encoded into css class name casing.
> Custom detectors will also be added as CSS classes with 'is-' prefix and encoded into css class name casing.

@@ -43,4 +69,4 @@ ### deviceDetector service

At first I added just major browser, OS, device support.
With help from mariendries,javierprovecho and crisandretta more support was added.
[The current list of supported browser,OS, device can be easily viewed in here] (https://github.com/srfrnk/ng-device-detector/blob/master/ng-device-detector.js).
With help from mariendries, javierprovecho and crisandretta more support was added.
[The current list of supported browser, OS, device can be easily viewed in here] (https://github.com/srfrnk/ng-device-detector/blob/master/ng-device-detector.js).

@@ -47,0 +73,0 @@ Pull-requests with new stuff will be highly appreciated :)

@@ -52,269 +52,20 @@ "use strict";

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 72
describe("Test custom UA string parsing", function () {
it("Should parse the specified UA", function () {
loadDetector("");
var deviceInfo = deviceDetector.parseUserAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36");
expect(deviceDetector.browser).toBe("unknown");
expect(deviceDetector.os).toBe("unknown");
expect(deviceDetector.device).toBe("unknown");
expect(deviceInfo.os).toBe("windows");
expect(deviceInfo.os_version).toBe("windows-8-1");
expect(deviceInfo.browser).toBe("chrome");
expect(deviceInfo.browser_version).toBe("37.0.2049.0");
expect(deviceInfo.device).toBe("unknown");
expect(deviceInfo.isMobile()).toBeFalsy();
expect(deviceInfo.isTablet()).toBeFalsy();
expect(deviceInfo.isDesktop()).toBeTruthy();
});
// 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);
});
});
});
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