This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
62 lines (46 loc) · 1.51 KB
/
index.ts
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
import Bowser from 'bowser';
import { BrowserStats } from './types';
export class BrowserService {
private browser: Bowser.Parser.Parser;
constructor() {
this.browser = Bowser.getParser(navigator.userAgent);
}
public get clientStats(): BrowserStats {
return this.browser.getResult();
}
public get isFirefox(): boolean {
return this.browser.isBrowser(Bowser.BROWSER_MAP.firefox);
}
public get isSafari(): boolean {
return this.browser.isBrowser(Bowser.BROWSER_MAP.safari);
}
public get isChrome(): boolean {
return this.browser.isBrowser(Bowser.BROWSER_MAP.chrome);
}
public get isIE(): boolean {
return this.browser.isBrowser(Bowser.BROWSER_MAP.ie);
}
public get isEdge(): boolean {
return this.browser.isBrowser(Bowser.BROWSER_MAP.edge);
}
public get isMobileDevice(): boolean {
const isMobile =
this.browser.is(Bowser.PLATFORMS_MAP.mobile) || this.browser.is(Bowser.PLATFORMS_MAP.tablet);
return isMobile && !navigator.userAgent.match(/iPad/i);
}
public get isTabletDevice(): boolean {
return this.browser.is(Bowser.PLATFORMS_MAP.tablet);
}
public get isAndroid(): boolean {
return this.isMobileDevice && !!navigator.userAgent.match(/Android/i);
}
public get isIpad(): boolean {
return !!navigator.userAgent.match(/iPad/i);
}
public get isIphone(): boolean {
return this.isMobileDevice && !!navigator.userAgent.match(/iPhone/i);
}
public get isAppleMobileDevice(): boolean {
return this.isIpad || this.isIphone;
}
}