UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

34 lines (32 loc) 1.11 kB
import { utils_exports } from "../../utils/index.js"; import { useEnvironment } from "../../core/system/environment-provider.js"; //#region src/hooks/use-os/index.ts const getOS = ({ navigator: { userAgent } }) => { const macos = /(Macintosh)|(MacIntel)|(MacPPC)|(Mac68K)/i; const windows = /(Win32)|(Win64)|(Windows)|(WinCE)/i; const ios = /(iPhone)|(iPad)|(iPod)/i; const android = /Android/i; const linux = /Linux/i; const chromeos = /CrOS/i; if (macos.test(userAgent)) return "macos"; if (ios.test(userAgent)) return "ios"; if (windows.test(userAgent)) return "windows"; if (android.test(userAgent)) return "android"; if (linux.test(userAgent)) return "linux"; if (chromeos.test(userAgent)) return "chromeos"; return "undetermined"; }; /** * `useOS` is a custom hook that returns the user's OS. * * @see https://yamada-ui.com/docs/hooks/use-os */ const useOS = () => { const { getWindow } = useEnvironment(); const win = getWindow(); if (!(0, utils_exports.isUndefined)(win)) return getOS(win); return "undetermined"; }; //#endregion export { useOS }; //# sourceMappingURL=index.js.map