Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eomm/fastify-user-agent
User-agent information plugin for Fastify
https://github.com/eomm/fastify-user-agent
fastify fastify-plugin user-agent
Last synced: 15 days ago
JSON representation
User-agent information plugin for Fastify
- Host: GitHub
- URL: https://github.com/eomm/fastify-user-agent
- Owner: Eomm
- License: mit
- Created: 2022-12-11T14:32:15.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-18T05:35:16.000Z (4 months ago)
- Last Synced: 2025-01-03T17:38:32.434Z (18 days ago)
- Topics: fastify, fastify-plugin, user-agent
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-user-agent
User-agent information plugin for Fastify.[![ci](https://github.com/Eomm/fastify-user-agent/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Eomm/fastify-user-agent/actions/workflows/ci.yml)
[![npm](https://img.shields.io/npm/v/fastify-user-agent)](https://www.npmjs.com/package/fastify-user-agent)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)## Install
```
npm install fastify-user-agent
```### Compatibility
| Plugin version | Fastify version |
| -------------- |:---------------:|
| `^2.0.0` | `^5.0.0` |
| `^1.0.0` | `^4.0.0` |## Usage
The plugin adds a `userAgent` property to the `request` object by parsing the `user-agent` header.
The object is an [`agent` instance](https://www.npmjs.com/package/useragent#agents-operatingsystem-and-device-instances) and it has the following properties:- `family` The browser family, or browser name, it defaults to Other.
- `major` The major version number of the family, it defaults to 0.
- `minor` The minor version number of the family, it defaults to 0.
- `patch` The patch version number of the family, it defaults to 0.
- `os` [OperatingSystem instance](https://www.npmjs.com/package/useragent#operatingsystemtostring)
- `device` [Device instance](https://www.npmjs.com/package/useragent#devicetostring)```js
const fastify = require('fastify')const app = fastify()
app.register(require('fastify-user-agent'))app.get('/', async (request, reply) => {
return request.userAgent
})app.listen({ port: 3000 })
```### Options
You can pass the following options during the registration:
| Option | Default | Description |
|--------|---------|-------------|
|`name` | `userAgent` | Change the `request` property name where the plugin will store the parsed user-agent information. |## License
Licensed under [MIT](./LICENSE).