https://github.com/pirxpilot/ua-query
Lazy user agent string checker for connect compatible requests
https://github.com/pirxpilot/ua-query
Last synced: over 1 year ago
JSON representation
Lazy user agent string checker for connect compatible requests
- Host: GitHub
- URL: https://github.com/pirxpilot/ua-query
- Owner: pirxpilot
- Created: 2016-12-29T01:04:42.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-03-29T06:40:45.000Z (over 2 years ago)
- Last Synced: 2025-03-01T00:48:04.192Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
# ua-query
Lazy user agent string checker for connect compatible requests
## Install
```sh
$ npm install --save ua-query
```
## Usage
```js
var ua = require('ua-query');
function middleware(req, res, next) {
if (ua.isChrome(req, 45) || ua.isFirefox(req, 40)) {
res.locals.polyfills = false;
}
}
```
## API
`ua-query` functions take request as the first parameter and optionally version number as the second.
browsers:
- `isChrome(req[, version])`
- `isFirefox(req[, version])`
- `isSafari(req[, version])`
- `isIE(req[, version])`
- `isEdge(req[, version])`
- `isBot(req[, version])` - a few strange bots
- `isOld(browser, version)` - true if browser type matches but the version is older than specified version
OS:
- `isWindowsXP(req)`
## In-browser usage
When used in the browser `ua-query` will check self.navigator.userAgent. Browser-side API is similar to
server-side API but it skips `req` parameter.
```js
var ua = require('ua-query');
function isModern(req, res, next) {
return ua.isChrome(45) || ua.isFirefox(40);
}
```
## License
MIT © [Damian Krzeminski](https://pirxpilot.me)
[npm-image]: https://img.shields.io/npm/v/ua-query
[npm-url]: https://npmjs.org/package/ua-query
[build-url]: https://github.com/pirxpilot/ua-query/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/ua-query/check.yaml?branch=main