Skip to content

Commit 74c040e

Browse files
authored
Merge pull request #24 from maitamdev/pair/device-detect
feat(utils): add device detection
2 parents 85345ee + b0ad1cc commit 74c040e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/utils/deviceDetect.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Device detection utilities
2+
export function isMobileDevice(): boolean {
3+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
4+
}
5+
6+
export function isIOSDevice(): boolean {
7+
return /iPad|iPhone|iPod/.test(navigator.userAgent);
8+
}
9+
10+
export function isTouchDevice(): boolean {
11+
return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
12+
}
13+
14+
export function getDeviceType(): 'mobile' | 'tablet' | 'desktop' {
15+
const width = window.innerWidth;
16+
if (width < 768) return 'mobile';
17+
if (width < 1024) return 'tablet';
18+
return 'desktop';
19+
}
20+
21+
export function getBrowserName(): string {
22+
const ua = navigator.userAgent;
23+
if (ua.includes('Firefox')) return 'Firefox';
24+
if (ua.includes('Chrome')) return 'Chrome';
25+
if (ua.includes('Safari')) return 'Safari';
26+
if (ua.includes('Edge')) return 'Edge';
27+
return 'Unknown';
28+
}

0 commit comments

Comments
 (0)