Comparing version 1.1.1 to 2.0.0
@@ -10,4 +10,5 @@ 'use strict' | ||
function isMobile (ua, opts) { | ||
if (!opts && ua !== null && typeof ua === 'object') opts = ua; | ||
function isMobile (opts) { | ||
if (!opts) opts = {} | ||
var ua = opts.ua | ||
if (!ua && typeof navigator !== 'undefined') ua = navigator.userAgent; | ||
@@ -18,3 +19,2 @@ if (ua && ua.headers && typeof ua.headers['user-agent'] === 'string') { | ||
if (typeof ua !== 'string') return false; | ||
if (!opts) opts = {}; | ||
@@ -21,0 +21,0 @@ return opts.tablet |
{ | ||
"name": "is-mobile", | ||
"description": "Check if mobile browser.", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
@@ -19,11 +19,13 @@ | ||
### mobile([user-agent], [options]) | ||
### mobile({ [ua], [tablet] }) | ||
Returns true if a mobile browser is being used. If you don't specify | ||
`user-agent` it will use `navigator.userAgent`. To detect tablet, pass `{ tablet: true }` as `options` argument. | ||
Returns true if a mobile browser is being used. | ||
### mobile(request, [options]) | ||
If you don't specify `opts.ua` it will use `navigator.userAgent`. | ||
Returns true if the given [node.js http request](http://nodejs.org/api/http.html#http_http_incomingmessage) comes with a mobile user agent header. | ||
To add support for tablets, set `tablet: true`. | ||
`opts.ua` can also be an instance of a [node.js http request](http://nodejs.org/api/http.html#http_http_incomingmessage), in which | ||
case it will reader the user agent header. | ||
Example: | ||
@@ -30,0 +32,0 @@ |
36
test.js
@@ -10,14 +10,28 @@ var test = require('tape'); | ||
test('is mobile', function (t) { | ||
t.ok(isMobile(iphone)); | ||
t.ok(isMobile(ffos)); | ||
t.notOk(isMobile(ipad)); | ||
t.ok(isMobile(ipad, {tablet: true})); | ||
t.ok(isMobile({ headers: { 'user-agent': iphone } })); | ||
t.notOk(isMobile(chrome)); | ||
t.notOk(isMobile({ headers: { 'user-agent': chrome } })); | ||
t.notOk(isMobile(null)); | ||
t.notOk(isMobile({ headers: null })); | ||
t.notOk(isMobile({ headers: { 'user-agent': null } })); | ||
t.ok(isMobile({ ua: iphone })); | ||
t.ok(isMobile({ ua: ffos })); | ||
t.notOk(isMobile({ ua: ipad })); | ||
t.ok(isMobile({ ua: ipad, tablet: true })); | ||
t.ok(isMobile({ ua: { headers: { 'user-agent': iphone } } })); | ||
t.notOk(isMobile({ ua: chrome })); | ||
t.notOk(isMobile({ ua: { headers: { 'user-agent': chrome } } })); | ||
t.notOk(isMobile()); | ||
t.notOk(isMobile({ ua: { headers: null } })); | ||
t.notOk(isMobile({ ua: { headers: { 'user-agent': null } } })); | ||
global.navigator = {}; | ||
global.navigator.userAgent = iphone; | ||
t.ok(isMobile()); | ||
t.ok(isMobile({ tablet: true })); | ||
global.navigator.userAgent = chrome; | ||
t.notOk(isMobile()); | ||
t.notOk(isMobile({ tablet: true })); | ||
global.navigator.userAgent = ipad; | ||
t.notOk(isMobile()); | ||
t.ok(isMobile({ tablet: true })); | ||
t.end(); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5857
49
81