Skip to content

Instantly share code, notes, and snippets.

@AvocadoVenom
Last active July 8, 2022 07:24
Show Gist options
  • Select an option

  • Save AvocadoVenom/f0c89425e2c8f5928bb3405301343e15 to your computer and use it in GitHub Desktop.

Select an option

Save AvocadoVenom/f0c89425e2c8f5928bb3405301343e15 to your computer and use it in GitHub Desktop.
const userAgent: string = navigator.userAgent || navigator.vendor || window.opera
const isMobileDevice = (): boolean => {
const regexs = [/(Android)(.+)(Mobile)/i, /BlackBerry/i, /iPhone|iPod/i, /Opera Mini/i, /IEMobile/i]
return regexs.some((b) => userAgent.match(b))
}
const isTabletDevice = (): boolean => {
const regex = /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/
return regex.test(userAgent.toLowerCase())
}
const isDesktopDevice = (): boolean => !isMobileDevice() && !isTabletDevice()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment