-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeviceDetect.ts
More file actions
28 lines (24 loc) · 872 Bytes
/
Copy pathdeviceDetect.ts
File metadata and controls
28 lines (24 loc) · 872 Bytes
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
// Device detection utilities
export function isMobileDevice(): boolean {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
export function isIOSDevice(): boolean {
return /iPad|iPhone|iPod/.test(navigator.userAgent);
}
export function isTouchDevice(): boolean {
return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
}
export function getDeviceType(): 'mobile' | 'tablet' | 'desktop' {
const width = window.innerWidth;
if (width < 768) return 'mobile';
if (width < 1024) return 'tablet';
return 'desktop';
}
export function getBrowserName(): string {
const ua = navigator.userAgent;
if (ua.includes('Firefox')) return 'Firefox';
if (ua.includes('Chrome')) return 'Chrome';
if (ua.includes('Safari')) return 'Safari';
if (ua.includes('Edge')) return 'Edge';
return 'Unknown';
}