# ua-parser2

> An improved user agent parser.

Latest version **0.5.1** (published 2021-01-28) · (MIT OR Apache-2.0) license · 0 weekly downloads

## Install

```sh
npm install ua-parser2
pnpm add ua-parser2
yarn add ua-parser2
bun add ua-parser2
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.1 |
| Published | 2021-01-28 |
| First published | 2014-08-06 |
| Weekly downloads | 0 |
| License | (MIT OR Apache-2.0) |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 1 |
| Unpacked size | 297 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Maintainers | commenthol |
| Keywords | Parser, User-Agent, ua-parser |

## Links

- npm: https://www.npmjs.com/package/ua-parser2
- Repository: https://github.com/commenthol/ua-parser2
- Homepage: https://github.com/commenthol/ua-parser2#readme
- Issues: https://github.com/commenthol/ua-parser2/issues
- npm.io page: https://npm.io/package/ua-parser2

## Dependencies (1)

- [js-yaml](https://npm.io/package/js-yaml.md) ^4.0.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.5.1 (latest) — 2021-01-28
- 0.5.0 — 2021-01-17
- 0.4.2 — 2019-02-11
- 0.4.1 — 2018-12-08
- 0.4.0 — 2018-08-11
- 0.3.4 — 2017-12-02
- 0.3.3 — 2017-09-18
- 0.3.2 — 2017-08-31
- 0.3.1 — 2017-07-07
- 0.3.0 — 2017-03-14
- 0.2.0 — 2017-03-11
- 0.1.40 — 2017-02-03
- 0.1.39 — 2016-12-27
- 0.1.38 — 2016-12-01
- 0.1.37 — 2016-11-12
- … 35 more at https://npm.io/package/ua-parser2/versions

## README

ua-parser2
==========

[![NPM version](https://badge.fury.io/js/ua-parser2.svg)](https://www.npmjs.com/package/ua-parser2/)
[![Build Status](https://secure.travis-ci.org/commenthol/ua-parser2.svg?branch=master)](https://travis-ci.org/commenthol/ua-parser2)

This is an improved fork from [ua-parser][ua-parser] which contains the following changes documented in the [Changelog][chan].

The crux of the original parser --the data collected by [Steve Souders][stev] over the years-- has been extracted into a separate [YAML file][yaml] so as to be reusable _as is_ by implementations in other programming languages.

The main differences to [ua-parser][ua-parser] are:

* Parsing Engines - Detection of MSIE compatibility modes
* Grouping of regexes - Speeds up User-Agent detection by > 200%
* Adding `type` attribute - tag a user-agent category with a specific type such as. 'bot', 'mail', 'feedreader', 'app', ...
* Bundled tools for contribution.
* Running your own `regexes.yaml` file
* Backwards Compatibility using the "old" UAParser result object is broken.


## Contributing Changes to regexes.yaml

Please read the [contributors' guide][guid]


## Specification

A [Specification][spec], e.g. for porting into other computer languages of the parsing rules for the `regexes.yaml` file is available.


## Usage

[API Documentation][api]

```javascript
var uaParser = require('ua-parser2')(/* [optional] path to your regexes.yaml file */);

var res,
    userAgent = "Mozilla/5.0 (Linux; Android 4.3.1; LG-E980 Build/JLS36I) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36";

res = uaParser.parse(userAgent);

console.log(res);
```

There is a sample in `./js/test/sample.js` which can be executed from the commandline.

```bash
node js/test/sample.js "Mozilla/5.0 (Linux; Android 4.3.1; LG-E980 Build/JLS36I) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36"
#> {
  "ua": {
    "family": "Chrome Mobile",
    "major": "31",
    "minor": "0",
    "patch": "1650"
  },
  "engine": {
    "family": "Blink",
    "major": "31",
    "minor": "0",
    "patch": "1650"
  },
  "os": {
    "family": "Android",
    "major": "4",
    "minor": "3",
    "patch": "1",
    "patchMinor": null
  },
  "device": {
    "family": "LG-E980",
    "brand": "LG",
    "model": "E980",
    "type": "smartphone"
  },
  "string": "Mozilla/5.0 (Linux; Android 4.3.1; LG-E980 Build/JLS36I) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36"
}

node js/test/sample.js "AdsBot-Google-Mobile ( http://www.google.com/mobile/adsbot.html) Mozilla (iPhone; U; CPU iPhone OS 3 0 like Mac OS X) AppleWebKit (KHTML, like Gecko)"
#> {
  "ua": {
    "family": "AdsBot-Google-Mobile",
    ...
    "type": "bot"
  },
  "engine": {
    "family": "Webkit",
    ...
    "type": "Apple"
  },
  "os": {
    "family": "Other",
    ...
  },
  "device": {
    "family": "iPhone",
    "brand": "Apple",
    "model": "iPhone",
    "type": "smartphone"    
  },
  "string": "AdsBot-Google-Mobile ( http://www.google.com/mobile/adsbot.html) Mozilla (iPhone; U; CPU iPhone OS 3 0 like Mac OS X) AppleWebKit (KHTML, like Gecko)"
}
```

Note if you're only interested in one of the `ua`, `device` or `os` objects, you will getter better performance by using the more specific methods (`uaParser.parseUA`, `uaParser.parseOS` and `uaParser.parseDevice` respectively), e.g.:

```js
var p = require('ua-parser2')();

var userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) CriOS/27.0.1453.10 Mobile/9B179 Safari/7534.48.3";

console.log(p.parseUA(userAgent).toString());
//> "Chrome Mobile iOS 27.0.1453"
console.log(p.parseEngine(userAgent).toString());
//> "AppleWebkit 534.46"
console.log(p.parseOS(userAgent).toString());
//> "iOS 5.1"
console.log(p.parseDevice(userAgent).toString());
//> "Apple iPhone"
```


## Benchmarks

In folder `benchmarks` you'll find a benchmark test which compares [useragent][], [node-uap][] with `ua-parser2`.

Results on my laptop:

- node-uap@0.0.3
- useragent@2.2.1
- ua-parser2@0.3.2

```
Starting the benchmark, parsing 63 useragent strings per run

Executed benchmark against node module: "useragent"
Count (3), Cycles (2), Elapsed (5.782), Hz (40.84696387495286)

Executed benchmark against node module: "node-uap"
Count (3), Cycles (2), Elapsed (5.628), Hz (41.23226067803832)

Executed benchmark against node module: "ua-parser2"
Count (7), Cycles (4), Elapsed (5.568), Hz (108.4435776239968)

Module: "ua-parser2" is the user agent fastest parser.
```


## Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license.
For contribution to the `regexes.yaml` you are implicitly allowing your code to be distributed under the Apache License license
You are also implicitly verifying that all code is your original work.


## License

The data contained in `regexes.yaml` is Copyright 2014 commenthol, 2009 Google Inc. and available under the [Apache License, Version 2.0][apac].

The JS port is Copyright 2014 commenthol, 2010 Tobie Langel and is available under [your choice of MIT or Apache Version 2.0 license][lice].

[node]: http://nodejs.org
[stev]: http://stevesouders.com/
[apac]: http://www.apache.org/licenses/LICENSE-2.0
[lice]: LICENSE
[spec]: doc/specification.md
[api]:  js/doc/uaparser.md
[guid]: CONTRIBUTING.md
[chan]: CHANGELOG.md
[yaml]: https://raw.github.com/commenthol/ua-parser2/master/regexes.yaml
[ua-parser]: http://github.com/tobie/ua-parser
[useragent]: https://github.com/3rd-Eden/useragent
[node-uap]: https://github.com/fedot/node-uap

---
_Source: https://npm.io/package/ua-parser2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
