项目作者: MethodGrab

项目描述 :
Browser detection from a user agent string
高级语言: JavaScript
项目地址: git://github.com/MethodGrab/is.git
创建时间: 2016-06-24T10:36:13Z
项目社区:https://github.com/MethodGrab/is

开源协议:

下载


is Build Status @methodgrab/is"">npm

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

  1. npm install --save @methodgrab/is

Usage

Basic

  1. const is = require( '@methodgrab/is' );
  2. is.ios();
  3. // No UA specified, `navigator.userAgent` is used if possible
  4. // → `true` on iOS devices, `false` elsewhere

Custom User Agent

You can pass a custom user agent when initializing the library:

  1. 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' );
  2. is.chrome();
  3. // → always `true`
  4. is.ios();
  5. // → always `false`

Or at run time:

  1. const is = require( '@methodgrab/is' );
  2. 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' );
  3. // → always `true`
  4. 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' );
  5. // → 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.