1
0
mirror of https://github.com/lancedikson/bowser synced 2026-03-02 03:40:27 +00:00

Parse user agent by default according to spec.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
see 14.43
This commit is contained in:
hsteinbr
2015-05-01 15:18:26 -07:00
parent 5a3d3766b9
commit cda48cb48a
2 changed files with 18 additions and 1 deletions

View File

@@ -16,6 +16,11 @@
return (match && match.length > 1 && match[1]) || '';
}
function getSecondMatch(regex) {
var match = ua.match(regex);
return (match && match.length > 1 && match[2]) || '';
}
var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase()
, likeAndroid = /like android/i.test(ua)
, android = !likeAndroid && /android/i.test(ua)
@@ -142,7 +147,12 @@
, version: versionIdentifier
}
}
else result = {}
else {
result = {
name: getFirstMatch(/^(.*)\/(.*) /),
version: getSecondMatch(/^(.*)\/(.*) /)
};
}
// set webkit or gecko flag for browsers based on these engines
if (/(apple)?webkit/i.test(ua)) {