all files / common/ user-agent.js

97.92% Statements 47/48
95.74% Branches 45/47
100% Functions 7/7
97.92% Lines 47/48
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72   10226× 10226×   62249× 3371×   58878× 1827×   57051× 541×   56510× 49406×   7104× 1427×   5677× 1868×   3809×   3582× 3582× 632× 632× 1264× 1264× 632×   632×         2950× 2715×   235× 55×   180× 20×   160×   158×   3638× 137×   3501×   3305× 3305×        
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var CustomUserAgentData = (function () {
        function CustomUserAgentData(userAgent, testing) {
            this.userAgent = userAgent;
            this.isTesting = testing;
        }
        CustomUserAgentData.prototype.getPlatform = function () {
            if (!this.isTesting && window.navigator.userAgentData) {
                return window.navigator.userAgentData.platform;
            }
            if (/windows/i.test(this.userAgent)) {
                return 'Windows';
            }
            if (/macintosh|mac os/i.test(this.userAgent) && !(/iphone|ipad|ipod/i.test(this.userAgent))) {
                return 'macOS';
            }
            if (/linux/i.test(this.userAgent) && !(/android/i.test(this.userAgent))) {
                return 'Linux';
            }
            if (/iphone|ipad|ipod/i.test(this.userAgent)) {
                return 'iOS';
            }
            if (/android/i.test(this.userAgent)) {
                return 'Android';
            }
            return 'Unknown';
        };
        CustomUserAgentData.prototype.getBrowser = function () {
            var brands = [];
            if (!this.isTesting && window.navigator.userAgentData) {
                brands = window.navigator.userAgentData.brands;
                for (var _i = 0, brands_1 = brands; _i < brands_1.length; _i++) {
                    var brand = brands_1[_i];
                    if (brand.brand === 'Google Chrome') {
                        return 'Chrome';
                    }
                    else Iif (brand.brand === 'Microsoft Edge') {
                        return 'Edge';
                    }
                }
            }
            if (/chrome|chromium|crios/i.test(this.userAgent) && !/edg/i.test(this.userAgent)) {
                return 'Chrome';
            }
            if (/firefox|fxios/i.test(this.userAgent) && !/edg/i.test(this.userAgent)) {
                return 'Firefox';
            }
            if (/safari/i.test(this.userAgent) && !/chrome|chromium|crios/i.test(this.userAgent)) {
                return 'Safari';
            }
            if (/edg/i.test(this.userAgent)) {
                return 'Edge';
            }
            return 'Unknown';
        };
        CustomUserAgentData.prototype.isMobileDevice = function () {
            if (!this.isTesting && window.navigator.userAgentData) {
                return window.navigator.userAgentData.mobile;
            }
            return /(iphone|ipod|ipad|android|blackberry|bb|playbook|windows phone|webos|opera mini|mobile)/i.test(this.userAgent);
        };
        CustomUserAgentData.prototype.isSafari = function () {
            var platform = this.getPlatform();
            return this.getBrowser() === 'Safari' && (platform === 'macOS' || platform === 'iOS');
        };
        return CustomUserAgentData;
    }());
    exports.CustomUserAgentData = CustomUserAgentData;
});