{"id":28417465,"url":"https://github.com/ua-parser/uap-scala","last_synced_at":"2026-01-05T20:04:53.798Z","repository":{"id":25676719,"uuid":"29112636","full_name":"ua-parser/uap-scala","owner":"ua-parser","description":"Scala port of ua-parser","archived":false,"fork":false,"pushed_at":"2025-06-02T23:08:09.000Z","size":682,"stargazers_count":100,"open_issues_count":2,"forks_count":50,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-06-13T03:29:07.778Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ua-parser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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,"zenodo":null}},"created_at":"2015-01-12T01:06:31.000Z","updated_at":"2025-06-11T02:48:24.000Z","dependencies_parsed_at":"2023-01-14T03:06:06.954Z","dependency_job_id":"797a7649-7732-4746-8cf8-b8eefd78b396","html_url":"https://github.com/ua-parser/uap-scala","commit_stats":{"total_commits":247,"total_committers":18,"mean_commits":"13.722222222222221","dds":0.728744939271255,"last_synced_commit":"16eef78829dc68375196d169c4209036fbb4ed52"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/ua-parser/uap-scala","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ua-parser%2Fuap-scala","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ua-parser%2Fuap-scala/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ua-parser%2Fuap-scala/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ua-parser%2Fuap-scala/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ua-parser","download_url":"https://codeload.github.com/ua-parser/uap-scala/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ua-parser%2Fuap-scala/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260376481,"owners_count":22999529,"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":[],"created_at":"2025-06-04T05:43:22.957Z","updated_at":"2026-01-05T20:04:53.792Z","avatar_url":"https://github.com/ua-parser.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"uap-scala\n=========\n\n[![Codecov status](https://codecov.io/gh/ua-parser/uap-scala/branch/master/graph/badge.svg)](https://codecov.io/gh/ua-parser/uap-scala)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.uaparser/uap-scala_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.uaparser/uap-scala_2.11)\n\nA Scala user-agent string parser based on [ua-parser/uap-core](https://github.com/ua-parser/uap-core). It extracts browser, OS and device information.\n\n### Usage\n\nTo use this library in your own project, add the following dependency in `build.sbt`:\n\n```\nlibraryDependencies += \"org.uaparser\" %% \"uap-scala\" % \"0.16.0\"\n```\n\n#### Note about these examples\n\nInstantiating Parser.default also instantiates secondary classes and reads in YAML files. This is slow.\nIf performance is critical or you are handling user agents in real time, be sure not to do this on the\ncritical path for processing requests.\n\n#### Retrieve data on a user-agent string\n\n```scala\nimport org.uaparser.scala.Parser\n\nval ua = \"Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3\"\nval client = Parser.default.parse(ua) // you can also use CachingParser\nprintln(client) // Client(UserAgent(Mobile Safari,Some(5),Some(1),None),OS(iOS,Some(5),Some(1),Some(1),None),Device(iPhone))\n```\n#### Extract partial data from user-agent string\n\nThe time costs of parsing all the data may be high.\nTo reduce the costs, we can just parse partial data.\n\n```scala\nimport org.uaparser.scala.Parser\n\nval raw = \"Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3\"\nval parser = Parser.default\n\nval os = parser.osParser.parse(raw)\nprintln(os) // OS(iOS,Some(5),Some(1),Some(1),None)\n\nval userAgent = parser.userAgentParser.parse(raw)\nprintln(userAgent) // UserAgent(Mobile Safari,Some(5),Some(1),None)\n\nval device = parser.deviceParser.parse(raw)\nprintln(device) // Device(iPhone,Some(Apple),Some(iPhone))\n```\n\n### Development\n\nThe code for this repository can be checked out normally. It uses a [git submodule](https://git-scm.com/docs/git-submodule) to include the files needed from [uap-core](https://github.com/ua-parser/uap-core) so care must be taken to make sure the `core` directory is properly checked out and initialized.\n\nChecking out the repo for the first time\n```\ngit clone --recursive https://github.com/ua-parser/uap-scala.git\n```\nIf uap-scala was checked out and core was not properly initialized, the following can be done\n\n```\ncd uap-scala\ngit submodule update --init --recursive\n```\n\n#### Build\n\nTo build and publish locally for the default Scala (currently 2.13.11):\n\n```scala\nsbt publishLocal\n```\n\nTo cross-build for different Scala versions:\n\n```scala\nsbt +publishLocal\n```\n\n### Details about the implementation using `regexes.yaml` file\n\nThis project uses the 'regexes.yaml' file from [ua-parser/uap-core](https://github.com/ua-parser/uap-core/) repository to\nperform user-agent string parsing according to the [documented specification](https://github.com/ua-parser/uap-core/blob/master/docs/specification.md).\nThe file is included as a git submodule in the `core` directory.\n\nBelow, follows a summary of that same specification.\n\n#### Summary\n\nThis implementation (and others) works by applying three independent ordered rule lists to the same input user‑agent \nstring:\n\n- User agent parser ('user_agent_parsers' definitions): provides the \"browser\" name and version.\n- OS parser ('os_parsers' definitions): provides operating system name and version.\n- Device parser ('device_parsers'): provides device family and optional brand and model.\n\nEach list is evaluated top‑to‑bottom. The first matching regex wins, and parsing for that list stops immediately.\n\n#### Data file format\n\nAt a high level, 'regexes.yaml' is a YAML map with top-level keys like:\n\n- `user_agent_parsers:`\n- `os_parsers:`\n- `device_parsers:`\n\nEach value is a YAML list. Each list item is a small map that always contains a regex and may contain `*_replacement` \nfields.\n\n##### Examples:\n\nUser agent parser example:\n```yaml\nuser_agent_parsers:\n  - regex: '(Namoroka|Shiretoko|Minefield)/(\\d+)\\.(\\d+)\\.(\\d+(?:pre|))'\n    family_replacement: 'Firefox ($1)'\n```\n\nOS parser example:\n```yaml\nos_parsers:\n  - regex: 'CFNetwork/.{0,100} Darwin/22\\.([0-5])\\.\\d+'\n    os_replacement: 'iOS'\n    os_v1_replacement: '16'\n    os_v2_replacement: '$1'\n```\n\nDevice parser example:\n```yaml\ndevice_parsers:\n  - regex: '; *(PEDI)_(PLUS)_(W) Build'\n    device_replacement: 'Odys $1 $2 $3'\n    brand_replacement: 'Odys'\n    model_replacement: '$1 $2 $3'\n```\n\n#### Capturing groups and default field mapping\n\nThe spec’s core idea is to put capturing groups `(...)` in your regex to extract parts of the UA string. If you don't \nsupply replacements, fields map by group order.\n\n#### User agent default mapping\n\nIf a user agent rule matches and it provides no replacements:\n- group 1: _family_\n- group 2: _major_\n- group 3: _minor_\n- group 4: _patch_\n\n#### OS default mapping\n\nSimilarly, OS rules map:\n\n- group 1: _family_\n- group 2: _major_\n- group 3: _minor_\n- group 4: _patch_\n- group 5: _patchMinor_\n\n#### Device default mapping\n\nDevices are slightly different: if no replacements are given, the first match defines the device family and model, \nand brand/model may be undefined depending on the rule and implementation.\n\nIn case no matching regex is found, the value for family shall be \"Other\". Brand and model shall not be defined. \nLeading and trailing whitespaces shall be trimmed from the result.\n\n\n### Maintainers\n\n* Piotr Adamski ([@mcveat](https://twitter.com/mcveat)) (Author. Based on the java implementation by Steve Jiang [@sjiang](https://twitter.com/sjiang) and using agent data from BrowserScope)\n* [Ahmed Sobhi](https://github.com/humanzz) ([@humanzz](https://twitter.com/humanzz))\n* [Travis Brown](https://github.com/travisbrown) ([@travisbrown](https://twitter.com/travisbrown))\n* [Nguyen Hong Phuc](https://github.com/phucnh) ([@phuc89](https://twitter.com/phuc89))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fua-parser%2Fuap-scala","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fua-parser%2Fuap-scala","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fua-parser%2Fuap-scala/lists"}