all files / common/ user-agent.js

95.83% Statements 46/48
91.67% Branches 44/48
100% Functions 7/7
95.83% Lines 46/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   11099× 11099×   64954× 3576×   61378× 1865×   59513× 541×   58972× 51851×   7121× 1427×   5694× 1880×   3814×   3787× 3787× 650× 650× 650× 650× 650×             3137× 2901×   236× 54×   182× 20×   162×   160×   3952× 153×   3799×   3481× 3481×        
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];
                    Eif (brand.brand === 'Google Chrome') {
                        return 'Chrome';
                    }
                    else if (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 && window.navigator.userAgentData.platform !== '') {
                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;
});