Comparing version 2.2.2 to 3.0.0
@@ -0,0 +0,0 @@ interface HttpRequestHeadersInterfaceMock { |
@@ -7,9 +7,9 @@ 'use strict' | ||
var mobileRE = /(android|bb\d+|meego).+mobile|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|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|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i | ||
var tabletRE = /(android|bb\d+|meego).+mobile|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|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|android|ipad|playbook|silk/i | ||
const tabletRE = /android|ipad|playbook|silk/i | ||
function isMobile (opts) { | ||
if (!opts) opts = {} | ||
var ua = opts.ua | ||
let ua = opts.ua | ||
if (!ua && typeof navigator !== 'undefined') ua = navigator.userAgent | ||
@@ -21,3 +21,3 @@ if (ua && ua.headers && typeof ua.headers['user-agent'] === 'string') { | ||
var result = opts.tablet ? tabletRE.test(ua) : mobileRE.test(ua) | ||
let result = mobileRE.test(ua) || (!!opts.tablet && tabletRE.test(ua)) | ||
@@ -24,0 +24,0 @@ if ( |
{ | ||
"name": "is-mobile", | ||
"description": "Check if mobile browser.", | ||
"version": "2.2.2", | ||
"version": "3.0.0", | ||
"repository": { | ||
@@ -14,10 +14,12 @@ "type": "git", | ||
"release": "np", | ||
"test": "prettier-standard '**/*.js' && standard && tape test.js" | ||
"test": "prettier-standard '**/*.js' && standard && npm run test:unit", | ||
"test:unit": "tape test.js" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"np": "^6.1.0", | ||
"prettier-standard": "^8.0.1", | ||
"standard": "^12.0.1", | ||
"tape": "~1.0.4" | ||
"np": "^7.4.0", | ||
"prettier-standard": "^16.4.1", | ||
"standard": "^16.0.3", | ||
"tape": "~5.2.2", | ||
"tape-describe": "^1.0.3", | ||
"user-agents": "^1.0.581" | ||
}, | ||
@@ -24,0 +26,0 @@ "keywords": [ |
@@ -30,3 +30,3 @@ | ||
`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. | ||
case it will read the user agent header. | ||
@@ -40,3 +40,3 @@ Example: | ||
var server = http.createServer(function (req, res) { | ||
res.end(mobile(req)); | ||
res.end(mobile({ ua: req })); | ||
}); | ||
@@ -43,0 +43,0 @@ |
45
test.js
@@ -1,14 +0,16 @@ | ||
var test = require('tape') | ||
var isMobile = require('./') | ||
const test = require('tape') | ||
const describe = require('tape-describe') | ||
const UserAgent = require('user-agents') | ||
const isMobile = require('./') | ||
var iphone = | ||
const iphone = | ||
'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3' | ||
var chrome = | ||
const chrome = | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36' | ||
var ffos = 'Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0' | ||
var ipad = | ||
const ffos = 'Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0' | ||
const ipad = | ||
'Mozilla/5.0 (iPad; CPU OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1' | ||
var ios13ipad = | ||
const ios13ipad = | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1' | ||
var ios13ipadpro = | ||
const ios13ipadpro = | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Safari/605.1.15' | ||
@@ -48,1 +50,28 @@ | ||
}) | ||
describe('ua-bruteforce', function () { | ||
const limit = 300 | ||
const checks = { | ||
mobile: { result: true }, | ||
tablet: { result: true, tablet: true }, | ||
desktop: { result: false } | ||
} | ||
const testCases = Object.entries(checks).reduce( | ||
(cases, [deviceCategory, { result, tablet }]) => [ | ||
...cases, | ||
...new Array(limit).fill().map(() => ({ | ||
ua: new UserAgent({ deviceCategory }).toString(), | ||
result, | ||
tablet | ||
})) | ||
], | ||
[] | ||
) | ||
testCases.forEach(({ ua, result, tablet }) => { | ||
test(ua, t => { | ||
t.equal(isMobile({ ua, tablet }), result) | ||
t.end() | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
7489
110
6