device detection (phone, tablet, desktop, os)
# npm
$ npm install @xg4/device --save
# yarn
$ yarn add @xg4/device
// commonjs in node or browser
const Device = require('@xg4/device').default
// es module
import Device from '@xg4/device'
const device = new Device() // or new Device(userAgent)
name | description |
---|---|
type | device type (mobile, tablet, desktop, null ) |
os | device os (ios, android, blackberry, mac, windows, firefox, meego, tv, null ) |
name | description | return |
---|---|---|
find(value:string) | 传入字符串,进行字符串 includes 匹配 |
Boolean |
match(pattern: RegExp) | 传入正则,进行正则 test 匹配 |
Boolean |
isMac | / | Boolean |
isIphone | / | Boolean |
isIpod | / | Boolean |
isIpad | / | Boolean |
isIos | / | Boolean |
isWindows | / | Boolean |
isWindowsPhone | / | Boolean |
isWindowsTablet | / | Boolean |
isAndroid | / | Boolean |
isAndroidPhone | / | Boolean |
isAndroidTablet | / | Boolean |
isBlackberry | / | Boolean |
isBlackberryPhone | / | Boolean |
isBlackberryTablet | / | Boolean |
isFirefox | firefox os, not browser | Boolean |
isFirefoxPhone | firefox os, not browser | Boolean |
isFirefoxTablet | firefox os, not browser | Boolean |
isMeego | / | Boolean |
isCordova | / | Boolean |
isNode | / | Boolean |
isMobile | / | Boolean |
isTablet | / | Boolean |
isDesktop | / | Boolean |
isTv | / | Boolean |
// commonjs in node or browser
const Orientation = require('@xg4/device').Orientation
// es module
import { Orientation } from '@xg4/device'
const orientation = new Orientation()
orientation.listen(function(event, type) {
// type === 'landscape' || 'portrait'
})
type
: 'landscape' || 'portrait'
-
isPortrait
: Boolean -
isLandscape
: Boolean -
listen
: void
Welcome
-
Fork it
-
Submit pull request
MIT