Socket
Socket
Sign inDemoInstall

is-mobile

Package Overview
Dependencies
0
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-mobile


Version published
Weekly downloads
349K
decreased by-15.37%
Maintainers
1
Created
Weekly downloads
 

Package description

What is is-mobile?

The is-mobile npm package is a lightweight utility that helps in detecting if a user is accessing a website from a mobile device. It can be used to tailor user experiences based on the type of device being used.

What are is-mobile's main functionalities?

Basic Mobile Detection

This feature allows you to detect if the user is accessing the website from a mobile device. The function returns a boolean value.

const isMobile = require('is-mobile');

if (isMobile()) {
  console.log('User is on a mobile device');
} else {
  console.log('User is not on a mobile device');
}

Custom User-Agent String

This feature allows you to pass a custom User-Agent string to the isMobile function to determine if it corresponds to a mobile device.

const isMobile = require('is-mobile');

const userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1';

if (isMobile({ ua: userAgent })) {
  console.log('User-Agent indicates a mobile device');
} else {
  console.log('User-Agent does not indicate a mobile device');
}

Custom HTTP Headers

This feature allows you to pass custom HTTP headers to the isMobile function to determine if they indicate a mobile device.

const isMobile = require('is-mobile');

const headers = { 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1' };

if (isMobile({ headers })) {
  console.log('HTTP headers indicate a mobile device');
} else {
  console.log('HTTP headers do not indicate a mobile device');
}

Other packages similar to is-mobile

Readme

Source

is-mobile

Check if mobile browser, based on useragent string.

build status

testling badge

Example

var mobile = require('is-mobile');

console.log(mobile());
// => false

API

mobile([user-agent])

Returns true if a mobile browser is being used. If you don't specify user-agent it will use navigator.userAgent.

mobile(request)

Returns true if the given node.js http request comes with a mobile user agent header.

Example:

var http = require('http');
var mobile = require('is-mobile');

var server = http.createServer(function (req, res) {
  res.end(mobile(req));
});

server.listen(8000);

Installation

With npm do:

npm install is-mobile

Bundle for the browser with browserify.

Kudos

Taken from detectmobilebrowsers.com.

License

(MIT)

Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Last updated on 16 Sep 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc