Files
Sable/src/app/utils/user-agent.ts
T
2026-07-04 00:07:31 -05:00

30 lines
880 B
TypeScript

import { UAParser } from 'ua-parser-js';
const result = new UAParser(window.navigator.userAgent).getResult();
const isMobileOrTablet = (() => {
const { os, device } = result;
if (device.type === 'mobile' || device.type === 'tablet') return true;
if (os.name === 'Android' || os.name === 'iOS') return true;
return false;
})();
const normalizeMacName = (os?: string) => {
if (!os) return os;
if (os === 'Mac OS') return 'macOS';
return os;
};
const isMac = result.os.name === 'Mac OS' || result.os.name === 'macOS';
export const ua = () => result;
export const isMacOS = () => isMac;
export const mobileOrTablet = () => isMobileOrTablet;
export const deviceDisplayName = (): string => {
const browser = result.browser.name;
const os = normalizeMacName(result.os.name);
if (!browser || !os) return 'Sable Web';
return `Sable on ${browser} for ${os}`;
};