https://github.com/methodgrab/is
Browser detection from a user agent string
https://github.com/methodgrab/is
browser-detection user-agent
Last synced: 9 months ago
JSON representation
Browser detection from a user agent string
- Host: GitHub
- URL: https://github.com/methodgrab/is
- Owner: MethodGrab
- Created: 2016-06-24T10:36:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-31T07:46:18.000Z (about 3 years ago)
- Last Synced: 2025-04-29T04:41:53.455Z (9 months ago)
- Topics: browser-detection, user-agent
- Language: JavaScript
- Size: 1.74 MB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# is [](https://travis-ci.org/MethodGrab/is) [](https://www.npmjs.com/package/@methodgrab/is)
> Browser detection from a user agent string.
## Why
Feature detection is preferable but sometimes it's not enough to deal with device specific quirks.
## Install
```bash
npm install --save @methodgrab/is
```
## Usage
### Basic
```js
const is = require( '@methodgrab/is' );
is.ios();
// No UA specified, `navigator.userAgent` is used if possible
// → `true` on iOS devices, `false` elsewhere
```
### Custom User Agent
You can pass a custom user agent when initializing the library:
```js
const is = require( '@methodgrab/is' )( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36' );
is.chrome();
// → always `true`
is.ios();
// → always `false`
```
Or at run time:
```js
const is = require( '@methodgrab/is' );
is.chrome( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36' );
// → always `true`
is.ios( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36' );
// → always `false`
```
## API
### `is.iosVersion()`
Get the `major`, `minor` & `patch` versions of iOS.
The values for each will be `-1` if undefined or not iOS.
Example: iOS 9.3.2 → `{ major: 9, minor: 3, patch: 2 }`
Example: iOS 9.0 → `{ major: 9, minor: 0, patch: -1 }`
Example: OS X → `{ major: -1, minor: -1, patch: -1 }`
### `is.ios()`
Check if the user agent indicates that the device is iOS.
### `is.safari()`
Check if the user agent indicates that the device is Safari.
### `is.chrome()`
Check if the user agent indicates that the device is Chrome.
### `is.ie()`
Check if the user agent indicates that the device is Internet Explorer.
### `is.ie9()`
Check if the user agent indicates that the device is Internet Explorer 9.
### `is.ie10()`
Check if the user agent indicates that the device is Internet Explorer 10.
### `is.ie11()`
Check if the user agent indicates that the device is Internet Explorer 11.
### `is.edge()`
Check if the user agent indicates that the device is Microsoft Edge.