# All files / src/lib/services/platform platform.service.ts

56.52% Statements 13/23
22.22% Branches 10/45
33.33% Functions 3/9
47.05% Lines 8/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    421x
    1x
    1x
    1x
    1x

    1x

    1x
    1x

     import { Injectable } from '@angular/core';

    @InjIectable({
    	providedIn: 'root'
    })
    export class PlatformService {
    	constructor() {}

    	isMobile(): boolean {
    		return this.isAndroid() || this.isIos();
    	}

    	isFirefox(): boolean {
    		return /Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent);
    	}

    	private isAndroid(): boolean {
    		return /\b(\w*Android\w*)\b/.test(navigator.userAgent) && /\b(\w*Mobile\w*)\b/.test(navigator.userAgent);
    	}

    	private isIos(): boolean {
    		return this.isIPhoneOrIPad(navigator?.userAgent) && this.isIOSWithSafari(navigator?.userAgent);
    	}
    	private isIPhoneOrIPad(userAgent): boolean {
    		const isIPad = /\b(\w*Macintosh\w*)\b/.test(userAgent);
    		const isIPhone = /\b(\w*iPhone\w*)\b/.test(userAgent) && /\b(\w*Mobile\w*)\b/.test(userAgent);
    		// && /\b(\w*iPhone\w*)\b/.test(navigator.platform);
    		const isTouchable = 'ontouchend' in document;

    		return (isIPad || isIPhone) && isTouchable;
    	}

    	private isIOSWithSafari(userAgent): boolean {
    		return (
    			/\b(\w*Apple\w*)\b/.test(navigator.vendor) &&
    			/\b(\w*Safari\w*)\b/.test(userAgent) &&
    			!/\b(\w*CriOS\w*)\b/.test(userAgent) &&
    			!/\b(\w*FxiOS\w*)\b/.test(userAgent)
    		);
    	}
    }