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 3.1.1 to 4.0.0

2

index.js

@@ -7,3 +7,3 @@ 'use strict'

const mobileRE = /(android|bb\d+|meego).+mobile|armv7l|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series[46]0|samsungbrowser|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i
const mobileRE = /(android|bb\d+|meego).+mobile|armv7l|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series[46]0|samsungbrowser.*mobile|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i
const notMobileRE = /CrOS/

@@ -10,0 +10,0 @@

{
"name": "is-mobile",
"description": "Check if mobile browser.",
"version": "3.1.1",
"version": "4.0.0",
"repository": {

@@ -15,3 +15,3 @@ "type": "git",

"test": "prettier-standard '**/*.js' && standard && npm run test:unit",
"test:unit": "tape test.js"
"test:unit": "node--test"
},

@@ -22,4 +22,3 @@ "devDependencies": {

"standard": "^16.0.4",
"tape": "~5.3.2",
"tape-describe": "^1.0.3",
"test": "^3.0.0",
"user-agents": "^1.0.845"

@@ -26,0 +25,0 @@ },

@@ -1,3 +0,5 @@

const test = require('tape')
const describe = require('tape-describe')
'use strict'
const assert = require('assert')
const test = require('test')
const UserAgent = require('user-agents')

@@ -19,19 +21,22 @@ const isMobile = require('./')

'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/16.0 Chrome/92.0.4515.166 Safari/537.36'
const samsungMobile =
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/16.0 Chrome/92.0.4515.166 Mobile Safari/537.36'
const chromeOS =
'Mozilla/5.0 (X11; CrOS armv7l 12105.100.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.144 Safari/537.36'
test('is mobile', function (t) {
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 } } }))
t.ok(isMobile({ ua: samsung }))
t.notOk(isMobile(chromeOS))
t.notOk(isMobile(chromeOS, { tablet: true }))
test('is mobile', function () {
assert(isMobile({ ua: iphone }))
assert(isMobile({ ua: ffos }))
assert(!isMobile({ ua: ipad }))
assert(isMobile({ ua: ipad, tablet: true }))
assert(isMobile({ ua: { headers: { 'user-agent': iphone } } }))
assert(!isMobile({ ua: chrome }))
assert(!isMobile({ ua: { headers: { 'user-agent': chrome } } }))
assert(!isMobile())
assert(!isMobile({ ua: { headers: null } }))
assert(!isMobile({ ua: { headers: { 'user-agent': null } } }))
assert(!isMobile({ ua: samsung }))
assert(isMobile({ ua: samsungMobile }))
assert(!isMobile(chromeOS))
assert(!isMobile(chromeOS, { tablet: true }))

@@ -41,21 +46,19 @@ global.navigator = {}

global.navigator.userAgent = iphone
t.ok(isMobile())
t.ok(isMobile({ tablet: true }))
assert(isMobile())
assert(isMobile({ tablet: true }))
global.navigator.userAgent = chrome
t.notOk(isMobile())
t.notOk(isMobile({ tablet: true }))
assert(!isMobile())
assert(!isMobile({ tablet: true }))
global.navigator.userAgent = ipad
t.notOk(isMobile())
t.ok(isMobile({ tablet: true }))
assert(!isMobile())
assert(isMobile({ tablet: true }))
global.navigator = { maxTouchPoints: 5 }
t.ok(isMobile({ ua: ios13ipad, tablet: true, featureDetect: true }))
t.ok(isMobile({ ua: ios13ipadpro, tablet: true, featureDetect: true }))
t.end()
assert(isMobile({ ua: ios13ipad, tablet: true, featureDetect: true }))
assert(isMobile({ ua: ios13ipadpro, tablet: true, featureDetect: true }))
})
describe('ua-bruteforce', function () {
test('ua-bruteforce', function () {
const limit = 300

@@ -92,7 +95,6 @@ const checks = [

testCases.forEach(({ ua, result, tablet }) => {
test(ua, t => {
t.equal(isMobile({ ua, tablet }), result)
t.end()
test(ua, () => {
assert.strictEqual(isMobile({ ua, tablet }), result)
})
})
})
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