true on macOS, false otherwise.
isMac(); // true on macOS
export function isMac(): boolean {
// `userAgentData` is a not-yet-standardized browser API absent from the DOM lib types;
// widen the trusted `navigator` global to read it safely.
const uaData = (navigator as Navigator & { userAgentData?: { platform?: string } }).userAgentData;
if (uaData?.platform) return /mac/i.test(uaData.platform);
return /mac/i.test(navigator.platform);
}
Detects whether the current platform is macOS. Used to expand the
modtoken and to select themacbranch of a platform-awareKeyBinding. Falls back tonavigator.platformfor broad compatibility; the neweruserAgentDataAPI is preferred when available.