{
  "name": "use-os",
  "author": "Brendan Dash (https://shadcn-hooks.com)",
  "description": "A hook to detect the current operating system",
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/hooks/use-os.ts",
      "content": "import { useEffect, useState } from 'react'\n\nexport type UseOSReturnValue =\n  | 'undetermined'\n  | 'macos'\n  | 'ios'\n  | 'windows'\n  | 'android'\n  | 'linux'\n  | 'chromeos'\n\nexport interface UseOsOptions {\n  /**\n   * Defer browser OS detection until after mount to avoid server/client mismatches.\n   * @default true\n   */\n  getValueInEffect?: boolean\n}\n\ninterface NavigatorWithUserAgentData extends Navigator {\n  userAgentData?: {\n    platform?: string\n  }\n}\n\nfunction getPlatform(): string {\n  if (typeof navigator === 'undefined') {\n    return ''\n  }\n\n  const nav = navigator as NavigatorWithUserAgentData\n\n  return (nav.userAgentData?.platform ?? navigator.platform ?? '').toLowerCase()\n}\n\nfunction getUserAgent(): string {\n  if (typeof navigator === 'undefined') {\n    return ''\n  }\n\n  return navigator.userAgent.toLowerCase()\n}\n\n/**\n * Detect the current operating system from the browser environment.\n *\n * @param options Hook options.\n * @returns The detected operating system or `undetermined`.\n */\nexport function getOS(options: UseOsOptions = {}): UseOSReturnValue {\n  const { getValueInEffect = true } = options\n\n  if (getValueInEffect || typeof navigator === 'undefined') {\n    return 'undetermined'\n  }\n\n  const platform = getPlatform()\n  const userAgent = getUserAgent()\n  const maxTouchPoints = navigator.maxTouchPoints ?? 0\n\n  if (userAgent.includes('android')) {\n    return 'android'\n  }\n\n  if (\n    /iphone|ipad|ipod/.test(userAgent) ||\n    (platform === 'macintel' && maxTouchPoints > 1)\n  ) {\n    return 'ios'\n  }\n\n  if (userAgent.includes('cros')) {\n    return 'chromeos'\n  }\n\n  if (platform.includes('win') || userAgent.includes('win')) {\n    return 'windows'\n  }\n\n  if (platform.includes('mac') || userAgent.includes('mac')) {\n    return 'macos'\n  }\n\n  if (platform.includes('linux') || userAgent.includes('linux')) {\n    return 'linux'\n  }\n\n  return 'undetermined'\n}\n\n/**\n * Reactively detect the current operating system from `navigator.userAgent`.\n *\n * @param options Hook options.\n * @returns The detected operating system or `undetermined`.\n */\nexport function useOs(options: UseOsOptions = {}): UseOSReturnValue {\n  const { getValueInEffect = true } = options\n  const [os, setOs] = useState<UseOSReturnValue>(() =>\n    getOS({ getValueInEffect }),\n  )\n\n  useEffect(() => {\n    setOs(getOS({ getValueInEffect: false }))\n  }, [getValueInEffect])\n\n  return os\n}\n",
      "type": "registry:hook"
    }
  ],
  "type": "registry:hook"
}
