File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ // Device detection utilities
2+ export function isMobileDevice ( ) : boolean {
3+ return / A n d r o i d | w e b O S | i P h o n e | i P a d | i P o d | B l a c k B e r r y | I E M o b i l e | O p e r a M i n i / i. test ( navigator . userAgent ) ;
4+ }
5+
6+ export function isIOSDevice ( ) : boolean {
7+ return / i P a d | i P h o n e | i P o d / . 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+ }
You can’t perform that action at this time.
0 commit comments