1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function testUserAgent(re: RegExp) {
|
14 | if (typeof window === 'undefined' || window.navigator == null) {
|
15 | return false;
|
16 | }
|
17 | return (
|
18 | window.navigator['userAgentData']?.brands.some((brand: {brand: string, version: string}) => re.test(brand.brand))
|
19 | ) ||
|
20 | re.test(window.navigator.userAgent);
|
21 | }
|
22 |
|
23 | function testPlatform(re: RegExp) {
|
24 | return typeof window !== 'undefined' && window.navigator != null
|
25 | ? re.test(window.navigator['userAgentData']?.platform || window.navigator.platform)
|
26 | : false;
|
27 | }
|
28 |
|
29 | export function isMac() {
|
30 | return testPlatform(/^Mac/i);
|
31 | }
|
32 |
|
33 | export function isIPhone() {
|
34 | return testPlatform(/^iPhone/i);
|
35 | }
|
36 |
|
37 | export function isIPad() {
|
38 | return testPlatform(/^iPad/i) ||
|
39 |
|
40 | (isMac() && navigator.maxTouchPoints > 1);
|
41 | }
|
42 |
|
43 | export function isIOS() {
|
44 | return isIPhone() || isIPad();
|
45 | }
|
46 |
|
47 | export function isAppleDevice() {
|
48 | return isMac() || isIOS();
|
49 | }
|
50 |
|
51 | export function isWebKit() {
|
52 | return testUserAgent(/AppleWebKit/i) && !isChrome();
|
53 | }
|
54 |
|
55 | export function isChrome() {
|
56 | return testUserAgent(/Chrome/i);
|
57 | }
|
58 |
|
59 | export function isAndroid() {
|
60 | return testUserAgent(/Android/i);
|
61 | }
|
62 |
|
63 | export function isFirefox() {
|
64 | return testUserAgent(/Firefox/i);
|
65 | }
|