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