Files
cinny/src/app/utils/user-agent.ts
T

19 lines
639 B
TypeScript
Raw Normal View History

2023-06-12 21:15:23 +10:00
import { UAParser } from 'ua-parser-js';
export const ua = () => UAParser(window.navigator.userAgent);
// 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;
};