forked from DamonOehlman/detect-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser.js
32 lines (27 loc) · 935 Bytes
/
browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var browsers = [
[ 'chrome', /Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/ ],
[ 'firefox', /Firefox\/([0-9\.]+)(?:\s|$)/ ],
[ 'opera', /Opera\/([0-9\.]+)(?:\s|$)/ ],
[ 'ie', /Trident\/7\.0.*rv\:([0-9\.]+)\).*Gecko$/ ],
[ 'ie', /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/ ],
[ 'ie', /MSIE\s(7\.0)/ ],
[ 'bb10', /BB10;\sTouch.*Version\/([0-9\.]+)/ ],
[ 'android', /Android\s([0-9\.]+)/ ],
[ 'ios', /iPad\;\sCPU\sOS\s([0-9\._]+)/ ],
[ 'ios', /iPhone\;\sCPU\siPhone\sOS\s([0-9\._]+)/ ],
[ 'safari', /Safari\/([0-9\._]+)/ ]
];
var match = browsers.map(match).filter(isMatch)[0];
var parts = match && match[3].split(/[._]/).slice(0,3);
while (parts && parts.length < 3) {
parts.push('0');
}
// set the name and version
exports.name = match && match[0];
exports.version = parts && parts.join('.');
function match(pair) {
return pair.concat(pair[1].exec(navigator.userAgent));
}
function isMatch(pair) {
return !!pair[2];
}