all files / common/ user-agent.js

95.83% Statements 46/48
93.62% Branches 44/47
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   8368× 8368×   48220× 25258×   22962× 600×   22362× 251×   22111× 17057×   5054× 916×   4138× 1209×   2929×   2924× 2924× 584× 584× 1752× 1752×     1752×         2924× 2708×   216× 55×   161× 14×   147×   145×       2661× 2661×        
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];
                    Iif (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;
});