@sebgroup/frontend-tools
Version:
A set of frontend tools
36 lines (32 loc) • 1.18 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Get the version of the current browser
* @note This method detects the browser version by the navigator's user agent (`navigator.userAgent`)
* @returns {number} The browser version, it will return `0` if it fails to find it
*/
function getBrowserVersion() {
const userAgent = navigator.userAgent;
let temp;
let match = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if (/trident/i.test(match[1])) {
temp = /\brv[ :]+(\d+)/g.exec(userAgent) || [];
return +(temp[1] || 0);
}
if (match[1] === "Chrome") {
temp = userAgent.match(/\bOPR|Edge\/(\d+)/);
if (temp != null) {
return +temp[1] || 0;
}
}
match = match[2]
? [match[1], match[2]]
: [navigator.appName, navigator.appVersion, "-?"];
temp = userAgent.match(/version\/(\d+)/i);
if (temp != null) {
match.splice(1, 1, temp[1]);
}
return +match[1] || 0;
}
exports.getBrowserVersion = getBrowserVersion;
//# sourceMappingURL=getBrowserVersion.js.map