Socket
Socket
Sign inDemoInstall

is-mobile

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-mobile - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

6

index.js

@@ -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 @@

@@ -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();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc