ua-parser-js
Advanced tools
Comparing version 0.4.4 to 0.4.6
{ | ||
"title": "UA-Parser.JS", | ||
"name": "ua-parser-js", | ||
"version": "0.4.4", | ||
"version": "0.4.6", | ||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)", | ||
@@ -6,0 +6,0 @@ "description": "Lightweight JavaScript-based user-agent string parser", |
109
ua-parser.js
@@ -1,2 +0,2 @@ | ||
// UA-Parser.JS v0.4.4 | ||
// UA-Parser.JS v0.4.6 | ||
// Lightweight JavaScript-based User-Agent string parser | ||
@@ -11,15 +11,15 @@ // https://github.com/faisalman/ua-parser-js | ||
'use strict'; | ||
var mapper = { | ||
regex : function () { | ||
var result, i, j, k, l, m, args = arguments; | ||
// loop through all regexes maps | ||
for (i = 0; i < args.length; i += 2) { | ||
var regex = args[i], // odd sequence (0,2,4,..) | ||
props = args[i + 1]; // even sequence (1,3,5,..) | ||
// construct object barebones | ||
@@ -39,3 +39,3 @@ if (typeof result === 'undefined') { | ||
} | ||
// try matching uastring with regexes | ||
@@ -62,3 +62,3 @@ for (j = 0; j < regex.length; j++) { | ||
} | ||
if(!!l) break; // break the loop immediately if match found | ||
@@ -68,5 +68,5 @@ } | ||
}, | ||
string : function (str, map) { | ||
for (var i in map) { | ||
@@ -77,7 +77,7 @@ if (map.hasOwnProperty(i)) { | ||
if (str.toLowerCase().indexOf(map[i][j].toLowerCase()) !== -1) { | ||
return i; | ||
return (i.toString() === 'undefined') ? undefined : i; | ||
} | ||
} | ||
} else if (str.toLowerCase().indexOf(map[i].toLowerCase()) !== -1) { | ||
return i; | ||
return (i.toString() === 'undefined') ? undefined : i; | ||
} | ||
@@ -91,2 +91,21 @@ } | ||
var maps = { | ||
browser : { | ||
oldsafari : { | ||
major : { | ||
'1' : ['/85', '/125', '/312'], | ||
'2' : ['/412', '/416', '/417', '/419'], | ||
'undefined' : '/' | ||
}, | ||
version : { | ||
'1.0' : '/85', | ||
'1.2' : '/125', | ||
'1.3' : '/312', | ||
'2.0' : '/412', | ||
'2.0.2' : '/416', | ||
'2.0.3' : '/417', | ||
'2.0.4' : '/419', | ||
'undefined' : '/' | ||
} | ||
} | ||
}, | ||
os : { | ||
@@ -107,3 +126,3 @@ windows : { | ||
}; | ||
var regexes = { | ||
@@ -118,3 +137,3 @@ | ||
/(opera)[\/\s]+((\d+)?[\w\.]+)/i, // Opera < 9.80 | ||
// Mixed | ||
@@ -124,3 +143,3 @@ /(kindle)\/((\d+)?[\w\.]+)/i, // Kindle | ||
// Lunascape/Maxthon/Netfront/Jasmine/Blazer | ||
// Trident based | ||
@@ -131,3 +150,3 @@ /(avant\sbrowser|iemobile|slimbrowser)[\/\s]?((\d+)?[\w\.]*)/i, // Avant/IEMobile/SlimBrowser | ||
// Webkit/KHTML based | ||
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|series60|bolt)\/((\d+)?[\w\.]+)/i, | ||
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|series60|bolt)\/((\d+)?[\w\.]+)/i, | ||
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/S60/Bolt | ||
@@ -137,9 +156,17 @@ /(chrome|omniweb|arora|dolfin|[tizenoka]{5}\s?browser)\/((\d+)?[\w\.]+)/i, | ||
], ['name', 'version', 'major'], [ | ||
/(?:android.+(crmo|crios))\/((\d+)?[\w\.]+)/i, // Chrome for Android/iOS | ||
], [['name', 'Chrome'], 'version', 'major'], [ | ||
/(mobile\ssafari|safari|konqueror)\/((\d+)?[\w\.]+)/i, // Safari/Konqueror | ||
/version\/((\d+)?[\w\.]+).+(mobile\s?safari|safari)/i // Safari & Safari Mobile | ||
], ['version', 'major', 'name'], [ | ||
/applewebkit.+(mobile\s?safari|safari)((\/[\w\.]+))/i // Safari < 3.0 | ||
], ['name', ['major', mapper.string, maps.browser.oldsafari.major], ['version', mapper.string, maps.browser.oldsafari.version]], [ | ||
/(konqueror)\/((\d+)?[\w\.]+)/i, // Konqueror | ||
/(applewebkit|khtml)\/((\d+)?[\w\.]+)/i, | ||
// Gecko based | ||
/(iceweasel|camino|fennec|maemo\sbrowser|minimo)[\/\s]?((\d+)?[\w\.\+]+)/i, | ||
/(iceweasel|camino|fennec|maemo\sbrowser|minimo)[\/\s]?((\d+)?[\w\.\+]+)/i, | ||
// Iceweasel/Camino/Fennec/Maemo/Minimo | ||
@@ -155,3 +182,3 @@ /(firefox|seamonkey|netscape|navigator|k-meleon|icecat|iceape)\/((\d+)?[\w\.]+)/i, | ||
], | ||
device : [[ | ||
@@ -168,3 +195,3 @@ | ||
/(blackberry)[\s-]?(\w+)/i, // BlackBerry | ||
/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|huawei|meizu|motorola)[\s_-]?([\w-]+)*/i, | ||
/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|huawei|meizu|motorola)[\s_-]?([\w-]+)*/i, | ||
// BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Huawei/Meizu/Motorola | ||
@@ -174,22 +201,22 @@ /(hp)\s([\w\s]+\w)/i, // HP iPAQ | ||
], ['vendor', 'model', ['type', 'Mobile']], [ | ||
/android.+((transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+))/i // Asus Tablets | ||
], [['vendor', 'Asus'], 'model', ['type', 'Tablet']], [ | ||
/(sony)\s(tablet\s[ps])/i // Sony Tablets | ||
], ['vendor', 'model', ['type', 'Tablet']], [ | ||
/(nintendo|playstation)\s([wids3portablev]+)/i // Nintendo/Playstation | ||
], ['vendor', 'model', ['type', 'Console']], [ | ||
/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC | ||
/(zte)-(\w+)*/i // ZTE | ||
], ['vendor', ['model', /_/g, ' '], ['type', 'Mobile']], [ | ||
/\s((milestone|droid[2x]?))[globa\s]*\sbuild\//i, // Motorola | ||
/(mot)[\s-]?(\w+)*/i | ||
], [['vendor', 'Motorola'], 'model', ['type', 'Mobile']], [ | ||
], [['vendor', 'Motorola'], 'model', ['type', 'Mobile']], [ | ||
/android.+\s((mz60\d|xoom[\s2]{0,2}))\sbuild\//i | ||
], [['vendor', 'Motorola'], 'model', ['type', 'Tablet']], [ | ||
/android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n8000|sgh-t8[56]9))/i | ||
@@ -203,10 +230,10 @@ ], [['vendor', 'Samsung'], 'model', ['type', 'Tablet']], [ // Samsung | ||
], [['vendor', 'Siemens'], 'model', ['type', 'Mobile']], [ | ||
/(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia | ||
/(nokia)[\s_-]?([\w-]+)*/i | ||
], [['vendor', 'Nokia'], 'model', ['type', 'Mobile']], [ | ||
/android\s3\.[\s\w-;]{10}((a\d{3}))/i // Acer | ||
], [['vendor', 'Acer'], 'model', ['type', 'Tablet']], [ | ||
/android\s3\.[\s\w-;]{10}(lg?)-([06cv9]{3,4})/i // LG | ||
@@ -217,3 +244,3 @@ ], [['vendor', 'LG'], 'model', ['type', 'Tablet']], [ | ||
], | ||
engine : [[ | ||
@@ -227,5 +254,5 @@ | ||
/rv\:([\w\.]+).*(gecko)/i // Gecko | ||
], ['version', 'name'] | ||
], ['version', 'name'] | ||
], | ||
os : [[ | ||
@@ -238,3 +265,3 @@ | ||
], [['name', 'Windows'], ['version', mapper.string, maps.os.windows.version]], [ | ||
// Mobile/Embedded OS | ||
@@ -248,3 +275,3 @@ /(blackberry).+version\/([\w\.]+)/i, // Blackberry | ||
], [['name', 'Symbian'], 'version'],[ | ||
/(nintendo|playstation)\s([wids3portable]+)/i, // Nintendo/Playstation | ||
@@ -280,3 +307,3 @@ | ||
/(macintosh|unix|minix|beos)[\/\s]?()*/i // UNIX/Minix/BeOS | ||
], ['name', 'version'] | ||
], ['name', 'version'] | ||
] | ||
@@ -287,6 +314,6 @@ }; | ||
var ua = uastring || (typeof window !== 'undefined' ? window.navigator.userAgent : ""); | ||
var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : ""); | ||
this.getBrowser = function () { | ||
return mapper.regex.apply(this, regexes.browser); | ||
return mapper.regex.apply(this, regexes.browser); | ||
}; | ||
@@ -314,3 +341,3 @@ | ||
}; | ||
this.getUA = function() { | ||
@@ -327,3 +354,3 @@ return ua; | ||
}; | ||
// check whether script is running inside node.js export as module | ||
@@ -330,0 +357,0 @@ if (typeof exports !== 'undefined' && this.toString() !== '[object DOMWindow]') { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20170
280