{"id":16853758,"url":"https://github.com/faisalman/ua-client-hints-js","last_synced_at":"2025-03-23T15:31:41.998Z","repository":{"id":193552554,"uuid":"689025587","full_name":"faisalman/ua-client-hints-js","owner":"faisalman","description":"UAClientHints.js - Parse \u0026 serialize user-agent client hints (UA-CH) HTTP headers","archived":false,"fork":false,"pushed_at":"2023-09-11T07:01:57.000Z","size":27,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T21:54:35.186Z","etag":null,"topics":["client-hints","ua-parser-js","user-agent"],"latest_commit_sha":null,"homepage":"https://uaparser.dev/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faisalman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"faisalman","patreon":null,"open_collective":"ua-parser-js","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://www.paypal.me/faisalman/"]}},"created_at":"2023-09-08T16:08:01.000Z","updated_at":"2024-11-05T12:21:29.000Z","dependencies_parsed_at":"2024-10-23T08:55:19.371Z","dependency_job_id":"1f1eecfa-77e8-488c-ae59-532efab3b240","html_url":"https://github.com/faisalman/ua-client-hints-js","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"864bf98025fb3743002e60e6c6c3858062f0487e"},"previous_names":["faisalman/ua-client-hints-js"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faisalman%2Fua-client-hints-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faisalman%2Fua-client-hints-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faisalman%2Fua-client-hints-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faisalman%2Fua-client-hints-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faisalman","download_url":"https://codeload.github.com/faisalman/ua-client-hints-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244944992,"owners_count":20536294,"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","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":["client-hints","ua-parser-js","user-agent"],"created_at":"2024-10-13T13:53:06.274Z","updated_at":"2025-03-23T15:31:41.039Z","avatar_url":"https://github.com/faisalman.png","language":"TypeScript","funding_links":["https://github.com/sponsors/faisalman","https://opencollective.com/ua-parser-js","https://www.paypal.me/faisalman/"],"categories":[],"sub_categories":[],"readme":"# UAClientHints.js\nParse \u0026 serialize user-agent client hints (UA-CH) HTTP headers\n\n```sh\nnpm i ua-client-hints-js\n```\n\n## Methods\n\n```js\nsetValuesFromHeaders(headers:object): UAClientHints\n```\n\n```js\nsetValuesFromUAParser(iresult:object): UAClientHints\n```\n\n```js\nsetValues(data:object): UAClientHints\n```\n\n```js\ngetValues([fields:string[]]): object\n```\n\n```js\ngetValuesAsHeaders([fields:string[]]): object\n```\n\n## Code Example\n\n### From HTTP Headers\n\n```js\nimport { UAClientHints } from 'ua-client-hints-js';\n\n/* \n    Suppose we're in a server having this client hints data:\n\n    const req = {\n        headers : {\n            'sec-ch-ua' : '\"Chromium\";v=\"93\", \"Google Chrome\";v=\"93\", \" Not;A Brand\";v=\"99\"',\n            'sec-ch-ua-full-version-list' : '\"Chromium\";v=\"93.0.1.2\", \"Google Chrome\";v=\"93.0.1.2\", \" Not;A Brand\";v=\"99.0.1.2\"',\n            'sec-ch-ua-arch' : '\"arm\"',\n            'sec-ch-ua-bitness' : '\"64\"',\n            'sec-ch-ua-mobile' : '?1',\n            'sec-ch-ua-model' : '\"Pixel 99\"',\n            'sec-ch-ua-platform' : '\"Linux\"',\n            'sec-ch-ua-platform-version' : '\"13\"'\n    };\n*/\n\nconst ch = new UAClientHints();\nch.setValuesFromHeaders(req.headers);\n\nconst chData1 = ch.getValues(['architecture', 'bitness', 'mobile']);\nconsole.log(chData1);\n/*\n    {\n        \"architecture\": \"arm\",\n        \"bitness\": \"64\",\n        \"mobile\": true\n    }\n*/\n\nconst chData2 = ch.getValues();\nconsole.log(chData2);\n/*\n    {\n        \"architecture\": \"arm\",\n        \"bitness\": \"64\",\n        \"brands\": [\n            {\n                \"brand\": \"Chromium\",\n                \"version\": \"93\"\n            },\n            {\n                \"brand\": \"Google Chrome\",\n                \"version\": \"93\"\n            },\n            {\n                \"brand\": \" Not;A Brand\",\n                \"version\": \"99\"\n            }\n        ],\n        \"fullVersionList\": [\n            {\n                \"brand\": \"Chromium\",\n                \"version\": \"93.0.1.2\"\n            },\n            {\n                \"brand\": \"Google Chrome\",\n                \"version\": \"93.0.1.2\"\n            },\n            {\n                \"brand\": \" Not;A Brand\",\n                \"version\": \"99.0.1.2\"\n            }\n        ],\n        \"mobile\": true,\n        \"model\": \"Pixel 99\",\n        \"platform\": \"Linux\",\n        \"platformVersion\": \"13\",\n        \"wow64\": null,\n        \"formFactor\": null\n    }\n*/\n\nch.setValues({\n    'wow64' : true,\n    'formFactor' : 'Automotive'\n});\n\nconst headersData1 = ch.getValuesAsHeaders();\nconsole.log(headersData1);\n/*\n    {\n        'Sec-CH-UA' : '\"Chromium\"; v=\"93\", \"Google Chrome\"; v=\"93\", \" Not;A Brand\"; v=\"99\"',\n        'Sec-CH-UA-Full-Version-List' : '\"Chromium\"; v=\"93.0.1.2\", \"Google Chrome\"; v=\"93.0.1.2\", \" Not;A Brand\"; v=\"99.0.1.2\"',\n        'Sec-CH-UA-Arch' : '\"arm\"',\n        'Sec-CH-UA-Bitness' : '\"64\"',\n        'Sec-CH-UA-Mobile' : '?1',\n        'Sec-CH-UA-Model' : '\"Pixel 99\"',\n        'Sec-CH-UA-Platform' : '\"Linux\"',\n        'Sec-CH-UA-Platform-Version' : '\"13\"',\n        'Sec-CH-UA-WOW64' : '?1',\n        'Sec-CH-UA-Form-Factor' : '\"Automotive\"'\n    };\n*/\n\nconst headersData2 = ch.getValuesAsHeaders(['brand', 'mobile', 'model']);\nconsole.log(headersData2);\n/*\n    {\n        'Sec-CH-UA' : '\"Chromium\"; v=\"93\", \"Google Chrome\"; v=\"93\", \" Not;A Brand\"; v=\"99\"',\n        'Sec-CH-UA-Mobile' : '?1',\n        'Sec-CH-UA-Model' : '\"Pixel 99\"'\n    };\n*/\n```\n\n### From [UAParser.js](https://github.com/faisalman/ua-parser-js)\n\n```js\nimport { UAClientHints } from 'ua-client-hints-js';\nimport { UAParser } from 'ua-parser-js';\n\nconst ua = 'Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 635) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537';\nconst uap = new UAParser(ua).getResult();\n\nconst ch = new UAClientHints();\nch.setValuesFromUAParser(uap);\n\nconst chData = ch.getValues();\nconsole.log(chData);\n/*\n{\n    architecture: null,\n    bitness: null,\n    brands: [\n        {\n            brand: 'IEMobile', \n            version: '11.0'\n        } \n    ],\n    formFactor: ['Mobile'],\n    fullVersionList: [\n        { \n            brand: 'IEMobile', \n            version: '11.0'\n        }\n    ],\n    mobile: true,\n    model: 'Lumia 635',\n    platform: 'Windows Phone',\n    platformVersion: '8.1',\n    wow64: null\n};\n*/\n\nconst chHeaders = ch.getValuesAsHeaders();\nconsole.log(chHeaders);\n/*\n{\n    'Sec-CH-UA-Arch': '',\n    'Sec-CH-UA-Bitness': '',\n    'Sec-CH-UA': '\"IEMobile\"; v=\"11.0\"',\n    'Sec-CH-UA-Form-Factor': '\"Mobile\"',\n    'Sec-CH-UA-Full-Version-List': '\"IEMobile\"; v=\"11.0\"',\n    'Sec-CH-UA-Mobile': '?1',\n    'Sec-CH-UA-Model': '\"Lumia 635\"',\n    'Sec-CH-UA-Platform': '\"Windows Phone\"',\n    'Sec-CH-UA-Platform-Version': '\"8.1\"',\n    'Sec-CH-UA-WOW64': ''\n}\n*/\n```\n\n# License\n\nMIT License\n\nCopyright (c) 2023 Faisal Salman \u003c\u003cf@faisalman.com\u003e\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaisalman%2Fua-client-hints-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaisalman%2Fua-client-hints-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaisalman%2Fua-client-hints-js/lists"}