library-ts/browser/dom/UserAgentInfo.ts

68 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2025-03-25 06:42:27 +00:00
export class UserAgentInfo
{
static is( regex:RegExp )
{
return regex.test( navigator.userAgent );
}
static get isIPhone()
{
return UserAgentInfo.is( /iphone/i );
}
static get isIPad()
{
return UserAgentInfo.is( /ipad/i );
}
static get isMac()
{
return UserAgentInfo.is( /macintosh/i );
}
static get isAndroid()
{
return UserAgentInfo.is( /android/i );
}
static get isTablet()
{
return UserAgentInfo.is( /tablet/i );
}
2025-09-06 11:33:04 +00:00
static get isChrome()
{
let ua = navigator.userAgent;
return ua.toLowerCase().includes( "chrome" ) && ! ua.toLowerCase().includes( "edg" );
}
static get isFirefox()
{
let ua = navigator.userAgent;
return ua.toLowerCase().includes( "firefox" );
}
static get isSafari()
{
let ua = navigator.userAgent;
return ua.toLowerCase().includes( "safari" );
}
2025-03-25 06:42:27 +00:00
static get isTV()
{
let isTV = UserAgentInfo.is( /smart\-?tv/i ) || UserAgentInfo.is( /net\-?cast/i ) ||
UserAgentInfo.is( /apple\s*tv/i ) || UserAgentInfo.is( /android\s*tv/i ) ||
UserAgentInfo.is( /opera\s*tv/i );
return isTV;
}
static get isOther()
{
let other = UserAgentInfo.is( /roku/i ) || UserAgentInfo.is( /tizen/i ) ||
UserAgentInfo.is( /netflix/i ) || UserAgentInfo.is( /crkey/i );
return other;
}
}