Skip to content

Instantly share code, notes, and snippets.

@yinkakun
Created October 1, 2023 09:26
Show Gist options
  • Save yinkakun/660e7bc7abcc8d5d76ff2519d5897c90 to your computer and use it in GitHub Desktop.
Save yinkakun/660e7bc7abcc8d5d76ff2519d5897c90 to your computer and use it in GitHub Desktop.
is mobile?
export function isAndroid(): boolean {
return (
typeof navigator !== 'undefined' && /android/i.test(navigator.userAgent)
);
}
export function isSmallIOS(): boolean {
return (
typeof navigator !== 'undefined' && /iPhone|iPod/.test(navigator.userAgent)
);
}
export function isLargeIOS(): boolean {
return (
typeof navigator !== 'undefined' &&
(/iPad/.test(navigator.userAgent) ||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1))
);
}
export function isIOS(): boolean {
return isSmallIOS() || isLargeIOS();
}
export function isMobile(): boolean {
return isAndroid() || isIOS();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment