Comparing version 3.0.0 to 3.1.0
@@ -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|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|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i | ||
@@ -10,0 +10,0 @@ const tabletRE = /android|ipad|playbook|silk/i |
{ | ||
"name": "is-mobile", | ||
"description": "Check if mobile browser.", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"repository": { | ||
@@ -18,8 +18,8 @@ "type": "git", | ||
"devDependencies": { | ||
"np": "^7.4.0", | ||
"np": "^7.6.0", | ||
"prettier-standard": "^16.4.1", | ||
"standard": "^16.0.3", | ||
"tape": "~5.2.2", | ||
"standard": "^16.0.4", | ||
"tape": "~5.3.2", | ||
"tape-describe": "^1.0.3", | ||
"user-agents": "^1.0.581" | ||
"user-agents": "^1.0.845" | ||
}, | ||
@@ -26,0 +26,0 @@ "keywords": [ |
@@ -60,2 +60,4 @@ | ||
Armv7l support added by [@antongolub](https://github.com/antongolub). | ||
## License | ||
@@ -62,0 +64,0 @@ |
43
test.js
@@ -17,2 +17,4 @@ const test = require('tape') | ||
'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' | ||
const samsung = | ||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/16.0 Chrome/92.0.4515.166 Safari/537.36' | ||
@@ -30,2 +32,3 @@ test('is mobile', function (t) { | ||
t.notOk(isMobile({ ua: { headers: { 'user-agent': null } } })) | ||
t.ok(isMobile({ ua: samsung })) | ||
@@ -55,16 +58,28 @@ global.navigator = {} | ||
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 | ||
})) | ||
], | ||
const checks = [ | ||
{ deviceCategory: 'mobile', result: true }, | ||
{ deviceCategory: 'tablet', result: true, tablet: true }, | ||
{ deviceCategory: 'desktop', result: false } | ||
] | ||
const testCases = checks.reduce( | ||
(cases, { deviceCategory, result, tablet }) => { | ||
// The same user-agent string belongs to both `desktop` and `mobile` type entries. No chance to detect `deviceType` properly. | ||
// https://github.com/intoli/user-agents/blob/867e318bc00880ae00437e5e8efaa8e5e7ac0696/src/user-agents.json.gz | ||
// user-agents v1.0.843 | ||
const exclude = | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36' | ||
const ua = new UserAgent([ | ||
({ userAgent }) => userAgent !== exclude, | ||
{ deviceCategory } | ||
]) | ||
return [ | ||
...cases, | ||
...new Array(limit).fill().map(() => ({ | ||
ua: ua.random().toString(), | ||
result, | ||
tablet | ||
})) | ||
] | ||
}, | ||
[] | ||
@@ -71,0 +86,0 @@ ) |
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
8351
124
85