2023-06-12 21:15:23 +10:00
|
|
|
import { UAParser } from 'ua-parser-js';
|
|
|
|
|
|
|
|
|
|
export const ua = () => UAParser(window.navigator.userAgent);
|
|
|
|
|
|
2026-06-30 14:58:06 -04:00
|
|
|
// ua-parser-js reports macOS as 'macOS' (v2+); older versions used 'Mac OS'.
|
|
|
|
|
// Accept both so the ⌘-vs-Ctrl shortcut hints render correctly on real Macs.
|
|
|
|
|
export const isMacOS = () => {
|
|
|
|
|
const name = ua().os.name;
|
|
|
|
|
return name === 'macOS' || name === 'Mac OS';
|
|
|
|
|
};
|
2023-10-18 13:15:30 +11:00
|
|
|
|
|
|
|
|
export const mobileOrTablet = (): boolean => {
|
|
|
|
|
const userAgent = ua();
|
|
|
|
|
const { os, device } = userAgent;
|
|
|
|
|
if (device.type === 'mobile' || device.type === 'tablet') return true;
|
|
|
|
|
if (os.name === 'Android' || os.name === 'iOS') return true;
|
|
|
|
|
return false;
|
|
|
|
|
};
|