https://github.com/thillmann/bowser-jr
A lightweight browser detector utility
https://github.com/thillmann/bowser-jr
browser-detection browser-detector detect-browser device-detection javascript os-detection typescript user-agent-parser useragent useragentparser
Last synced: 5 months ago
JSON representation
A lightweight browser detector utility
- Host: GitHub
- URL: https://github.com/thillmann/bowser-jr
- Owner: thillmann
- License: other
- Created: 2022-05-26T09:57:51.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-29T12:04:50.000Z (almost 2 years ago)
- Last Synced: 2024-12-02T12:54:55.317Z (6 months ago)
- Topics: browser-detection, browser-detector, detect-browser, device-detection, javascript, os-detection, typescript, user-agent-parser, useragent, useragentparser
- Language: TypeScript
- Homepage:
- Size: 159 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bowser Jr.
A small, lightweight and *composable* browser detection utility heavily inspired by [`bowser`](https://github.com/lancedikson/bowser).
[](https://github.com/thillmann/bowser-jr/actions/workflows/test.yaml)
## Installation
Install it using your favourite package manager:
```bash
$ npm install bowser-jr
# or
$ yarn add bowser-jr
# or
$ pnpm add bowser-jr
```## Usage
Now just import `getParser` and the `parsers` you need:
```ts
import { getParser } from 'bowser-jr';
import { getBrowserName, browserParser } from 'bowser-jr/browser';const parser = getParser(window.navigator.userAgent, { use: [browserParser] });
console.log(getBrowserName(parser)); // outputs `Firefox`
```### Using multiple parsers
You can use multiple parsers to extract more information from the user agent:
```ts
import { getParser } from 'bowser-jr';
import { browserParser } from 'bowser-jr/browser';
import { engineParser } from 'bowser-jr/engine';
import { osParser } from 'bowser-jr/os';
import { platformParser } from 'bowser-jr/platform';const parser = getParser(window.navigator.userAgent, {
use: [browserParser, engineParser, osParser, platformParser],
});console.log(parser.getResult());
```### Bowser compat utilities
`bowser-jr` also comes with a compatibility utility for [`bowser`](https://github.com/lancedikson/bowser) to make adoption a little easier:
```ts
import BowserCompat from 'bowser-jr/compat';const browser = BowserCompat.getParser(window.navigator.userAgent);
console.log(browser.getBrowser());// outputs
{
name: "Internet Explorer"
version: "11.0"
}
```