library-ts/browser/dom/UserAgentInfo.ts

50 lines
1.0 KiB
TypeScript
Raw 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 );
}
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;
}
}