{"id":17865199,"url":"https://github.com/oieduardorabelo/use-user-agent","last_synced_at":"2025-07-23T15:04:35.411Z","repository":{"id":35087275,"uuid":"202252873","full_name":"oieduardorabelo/use-user-agent","owner":"oieduardorabelo","description":"⚛️  React Hooks to detect browsers user-agent using ua-parser-js as main dependency.","archived":false,"fork":false,"pushed_at":"2022-06-27T03:12:06.000Z","size":241,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T16:58:22.458Z","etag":null,"topics":["agent","browser","hooks","react","react-hooks","reactjs","ua-parser-js","user","user-agent"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oieduardorabelo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-14T01:50:45.000Z","updated_at":"2024-11-07T01:56:34.000Z","dependencies_parsed_at":"2022-08-17T22:31:26.302Z","dependency_job_id":null,"html_url":"https://github.com/oieduardorabelo/use-user-agent","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/oieduardorabelo/use-user-agent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oieduardorabelo%2Fuse-user-agent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oieduardorabelo%2Fuse-user-agent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oieduardorabelo%2Fuse-user-agent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oieduardorabelo%2Fuse-user-agent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oieduardorabelo","download_url":"https://codeload.github.com/oieduardorabelo/use-user-agent/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oieduardorabelo%2Fuse-user-agent/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266699503,"owners_count":23970513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent","browser","hooks","react","react-hooks","reactjs","ua-parser-js","user","user-agent"],"created_at":"2024-10-28T09:19:45.255Z","updated_at":"2025-07-23T15:04:35.383Z","avatar_url":"https://github.com/oieduardorabelo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @oieduardorabelo/use-user-agent\n\nReact Hooks to detect browsers user-agent using [`ua-parser-js`](https://github.com/faisalman/ua-parser-js) as main dependency.\n\nTo install it:\n\n```\nyarn add @oieduardorabelo/use-user-agent\n```\n\n## Example\n\nAn online demo is available at CodeSandbox:\n\n- **Live demo:** https://codesandbox.io/s/live-demo-use-user-agent-d7iyg\n\nIf you've any issues, **open an issue with a CodeSandbox link** with your issue\n\n## API Explained\n\nIn your app, you can add:\n\n```javascript\nimport { useUserAgent } from '@oieduardorabelo/use-user-agent';\n\nfunction App() {\n  let details = useUserAgent(uastring)\n  ...\n}\n```\n\n### `details` object is composed of:\n\n- `details`: It is either `null` or an ua-parser-js object.\n- `details.os`: It is a `Object`, with keys `name` and `version` as `string|undefined`\n- `details.browser`: It is a `Object`, with keys `name`, `version` and `major` as `string|undefined`\n- `details.cpu`: It is a `Object`, with keys `architecture` as `string|undefined`\n- `details.device`: It is a `Object`, with keys `vendor`, `model` and `type` as `string|undefined`\n- `details.engine`: It is a `Object`, with keys `name` and `version`  as `string|undefined`\n\nFor full documentation, refer to [ua-parser-js repository](https://github.com/faisalman/ua-parser-js#example).\n\n### `uastring` parameter is composed of:\n\n- `uastring`: It is a `String`, should be a user-agent string, if none is passed, we default to `window.navigator.userAgent`\n\n## Examples\n\nUsing default value from `useUserAgent()`:\n\n```javascript\nimport { useUserAgent } from '@oieduardorabelo/use-user-agent';\n\nfunction App() {\n  let details = useUserAgent(); // default is `window.navigator.userAgent`\n\n  if (!details) {\n    return null;\n  }\n\n  let { os, browser, cpu, device, engine } = details;\n\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003eMy OS is {os.name}, on version {os.version}\u003c/p\u003e\n      \u003cp\u003eMy Browser is {browser.name}, on version {browser.version} with major {browser.major}\u003c/p\u003e\n      \u003cp\u003eMy CPU architecture is {cpu.architecture}\u003c/p\u003e\n      \u003cp\u003eMy Device is {device.vendor}, with model {device.model} of type {device.type}\u003c/p\u003e\n      \u003cp\u003eMy Engine is {engine.name} with version {engine.version}\u003c/p\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\nPassing a custom user-agent string:\n\n```javascript\nimport { useUserAgent } from '@oieduardorabelo/use-user-agent';\n\nfunction App() {\n  let uastring = \"Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11\";\n  let details = useUserAgent(uastring);\n\n  if (!details) {\n    return null;\n  }\n\n  let { os, browser, cpu, device, engine } = details;\n\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003eMy OS is {os.name}, on version {os.version}\u003c/p\u003e\n      \u003cp\u003eMy Browser is {browser.name}, on version {browser.version} with major {browser.major}\u003c/p\u003e\n      \u003cp\u003eMy CPU architecture is {cpu.architecture}\u003c/p\u003e\n      \u003cp\u003eMy Device is {device.vendor}, with model {device.model} of type {device.type}\u003c/p\u003e\n      \u003cp\u003eMy Engine is {engine.name} with version {engine.version}\u003c/p\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n### License\n\n[MIT License](https://oss.ninja/mit/oieduardorabelo/) © [Eduardo Rabelo](https://eduardorabelo.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foieduardorabelo%2Fuse-user-agent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foieduardorabelo%2Fuse-user-agent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foieduardorabelo%2Fuse-user-agent/lists"}