ismobilejs
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -5,6 +5,6 @@ "use strict"; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.__esModule = true; | ||
__export(require("./isMobile")); | ||
var isMobile_1 = require("./isMobile"); | ||
exports.default = isMobile_1.default; | ||
exports["default"] = isMobile_1["default"]; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const appleIphone = /iPhone/i; | ||
const appleIpod = /iPod/i; | ||
const appleTablet = /iPad/i; | ||
const androidPhone = /\bAndroid(?:.+)Mobile\b/i; | ||
const androidTablet = /Android/i; | ||
const amazonPhone = /(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i; | ||
const amazonTablet = /Silk/i; | ||
const windowsPhone = /Windows Phone/i; | ||
const windowsTablet = /\bWindows(?:.+)ARM\b/i; | ||
const otherBlackBerry = /BlackBerry/i; | ||
const otherBlackBerry10 = /BB10/i; | ||
const otherOpera = /Opera Mini/i; | ||
const otherChrome = /\b(CriOS|Chrome)(?:.+)Mobile/i; | ||
const otherFirefox = /Mobile(?:.+)Firefox\b/i; | ||
function match(regex, userAgent) { | ||
return regex.test(userAgent); | ||
exports.__esModule = true; | ||
var appleIphone = /iPhone/i; | ||
var appleIpod = /iPod/i; | ||
var appleTablet = /iPad/i; | ||
var appleUniversal = /\biOS-universal(?:.+)Mac\b/i; | ||
var androidPhone = /\bAndroid(?:.+)Mobile\b/i; | ||
var androidTablet = /Android/i; | ||
var amazonPhone = /(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i; | ||
var amazonTablet = /Silk/i; | ||
var windowsPhone = /Windows Phone/i; | ||
var windowsTablet = /\bWindows(?:.+)ARM\b/i; | ||
var otherBlackBerry = /BlackBerry/i; | ||
var otherBlackBerry10 = /BB10/i; | ||
var otherOpera = /Opera Mini/i; | ||
var otherChrome = /\b(CriOS|Chrome)(?:.+)Mobile/i; | ||
var otherFirefox = /Mobile(?:.+)Firefox\b/i; | ||
function createMatch(userAgent) { | ||
return function (regex) { return regex.test(userAgent); }; | ||
} | ||
@@ -23,3 +24,3 @@ function isMobile(userAgent) { | ||
userAgent || (typeof navigator !== 'undefined' ? navigator.userAgent : ''); | ||
let tmp = userAgent.split('[FBAN'); | ||
var tmp = userAgent.split('[FBAN'); | ||
if (typeof tmp[1] !== 'undefined') { | ||
@@ -32,53 +33,54 @@ userAgent = tmp[0]; | ||
} | ||
const result = { | ||
var match = createMatch(userAgent); | ||
var result = { | ||
apple: { | ||
phone: match(appleIphone, userAgent) && !match(windowsPhone, userAgent), | ||
ipod: match(appleIpod, userAgent), | ||
tablet: !match(appleIphone, userAgent) && | ||
match(appleTablet, userAgent) && | ||
!match(windowsPhone, userAgent), | ||
device: (match(appleIphone, userAgent) || | ||
match(appleIpod, userAgent) || | ||
match(appleTablet, userAgent)) && | ||
!match(windowsPhone, userAgent), | ||
phone: match(appleIphone) && !match(windowsPhone), | ||
ipod: match(appleIpod), | ||
tablet: !match(appleIphone) && match(appleTablet) && !match(windowsPhone), | ||
universal: match(appleUniversal), | ||
device: (match(appleIphone) || | ||
match(appleIpod) || | ||
match(appleTablet) || | ||
match(appleUniversal)) && | ||
!match(windowsPhone) | ||
}, | ||
amazon: { | ||
phone: match(amazonPhone, userAgent), | ||
tablet: !match(amazonPhone, userAgent) && match(amazonTablet, userAgent), | ||
device: match(amazonPhone, userAgent) || match(amazonTablet, userAgent), | ||
phone: match(amazonPhone), | ||
tablet: !match(amazonPhone) && match(amazonTablet), | ||
device: match(amazonPhone) || match(amazonTablet) | ||
}, | ||
android: { | ||
phone: (!match(windowsPhone, userAgent) && match(amazonPhone, userAgent)) || | ||
(!match(windowsPhone, userAgent) && match(androidPhone, userAgent)), | ||
tablet: !match(windowsPhone, userAgent) && | ||
!match(amazonPhone, userAgent) && | ||
!match(androidPhone, userAgent) && | ||
(match(amazonTablet, userAgent) || match(androidTablet, userAgent)), | ||
device: (!match(windowsPhone, userAgent) && | ||
(match(amazonPhone, userAgent) || | ||
match(amazonTablet, userAgent) || | ||
match(androidPhone, userAgent) || | ||
match(androidTablet, userAgent))) || | ||
match(/\bokhttp\b/i, userAgent), | ||
phone: (!match(windowsPhone) && match(amazonPhone)) || | ||
(!match(windowsPhone) && match(androidPhone)), | ||
tablet: !match(windowsPhone) && | ||
!match(amazonPhone) && | ||
!match(androidPhone) && | ||
(match(amazonTablet) || match(androidTablet)), | ||
device: (!match(windowsPhone) && | ||
(match(amazonPhone) || | ||
match(amazonTablet) || | ||
match(androidPhone) || | ||
match(androidTablet))) || | ||
match(/\bokhttp\b/i) | ||
}, | ||
windows: { | ||
phone: match(windowsPhone, userAgent), | ||
tablet: match(windowsTablet, userAgent), | ||
device: match(windowsPhone, userAgent) || match(windowsTablet, userAgent), | ||
phone: match(windowsPhone), | ||
tablet: match(windowsTablet), | ||
device: match(windowsPhone) || match(windowsTablet) | ||
}, | ||
other: { | ||
blackberry: match(otherBlackBerry, userAgent), | ||
blackberry10: match(otherBlackBerry10, userAgent), | ||
opera: match(otherOpera, userAgent), | ||
firefox: match(otherFirefox, userAgent), | ||
chrome: match(otherChrome, userAgent), | ||
device: match(otherBlackBerry, userAgent) || | ||
match(otherBlackBerry10, userAgent) || | ||
match(otherOpera, userAgent) || | ||
match(otherFirefox, userAgent) || | ||
match(otherChrome, userAgent), | ||
blackberry: match(otherBlackBerry), | ||
blackberry10: match(otherBlackBerry10), | ||
opera: match(otherOpera), | ||
firefox: match(otherFirefox), | ||
chrome: match(otherChrome), | ||
device: match(otherBlackBerry) || | ||
match(otherBlackBerry10) || | ||
match(otherOpera) || | ||
match(otherFirefox) || | ||
match(otherChrome) | ||
}, | ||
any: false, | ||
phone: false, | ||
tablet: false, | ||
tablet: false | ||
}; | ||
@@ -96,3 +98,3 @@ result.any = | ||
} | ||
exports.default = isMobile; | ||
exports["default"] = isMobile; | ||
//# sourceMappingURL=isMobile.js.map |
@@ -9,2 +9,3 @@ * Igor Ribeio Lima ([https://github.com/igorlima](https://github.com/igorlima)) | ||
* Ma Cheng ([https://github.com/mc-zone](https://github.com/mc-zone)) | ||
* Ruslan Ismagilov ([https://github.com/isRuslan](https://github.com/isRuslan)) | ||
* Ruslan Ismagilov ([https://github.com/isRuslan](https://github.com/isRuslan)) | ||
* Samuli Hiltunen ([https://github.com/samuli-hiltunen-somedia](https://github.com/samuli-hiltunen-somedia)) |
@@ -1,1 +0,1 @@ | ||
(function () {var a={};var g=/iPhone/i,p=/iPod/i,i=/iPad/i,f=/\bAndroid(?:.+)Mobile\b/i,h=/Android/i,d=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,e=/Silk/i,c=/Windows Phone/i,j=/\bWindows(?:.+)ARM\b/i,k=/BlackBerry/i,l=/BB10/i,m=/Opera Mini/i,n=/\b(CriOS|Chrome)(?:.+)Mobile/i,o=/Mobile(?:.+)Firefox\b/i;function b($,a){return $.test(a)}function q($){var a=($=$||("undefined"!=typeof navigator?navigator.userAgent:"")).split("[FBAN");void 0!==a[1]&&($=a[0]),void 0!==(a=$.split("Twitter"))[1]&&($=a[0]);var r={apple:{phone:b(g,$)&&!b(c,$),ipod:b(p,$),tablet:!b(g,$)&&b(i,$)&&!b(c,$),device:(b(g,$)||b(p,$)||b(i,$))&&!b(c,$)},amazon:{phone:b(d,$),tablet:!b(d,$)&&b(e,$),device:b(d,$)||b(e,$)},android:{phone:!b(c,$)&&b(d,$)||!b(c,$)&&b(f,$),tablet:!b(c,$)&&!b(d,$)&&!b(f,$)&&(b(e,$)||b(h,$)),device:!b(c,$)&&(b(d,$)||b(e,$)||b(f,$)||b(h,$))||b(/\bokhttp\b/i,$)},windows:{phone:b(c,$),tablet:b(j,$),device:b(c,$)||b(j,$)},other:{blackberry:b(k,$),blackberry10:b(l,$),opera:b(m,$),firefox:b(o,$),chrome:b(n,$),device:b(k,$)||b(l,$)||b(m,$)||b(o,$)||b(n,$)},any:!1,phone:!1,tablet:!1};return r.any=r.apple.device||r.android.device||r.windows.device||r.other.device,r.phone=r.apple.phone||r.android.phone||r.windows.phone,r.tablet=r.apple.tablet||r.android.tablet||r.windows.tablet,r}a=q();if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=a}else if(typeof define==="function"&&define.amd){define(function(){return a})}else{this["isMobile"]=a}})(); | ||
(function () {var f={};var g=/iPhone/i,i=/iPod/i,j=/iPad/i,k=/\biOS-universal(?:.+)Mac\b/i,h=/\bAndroid(?:.+)Mobile\b/i,m=/Android/i,c=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,d=/Silk/i,b=/Windows Phone/i,n=/\bWindows(?:.+)ARM\b/i,o=/BlackBerry/i,p=/BB10/i,q=/Opera Mini/i,r=/\b(CriOS|Chrome)(?:.+)Mobile/i,s=/Mobile(?:.+)Firefox\b/i;function t(l){return function($){return $.test(l)}}function u(l){var $=(l=l||("undefined"!=typeof navigator?navigator.userAgent:"")).split("[FBAN");void 0!==$[1]&&(l=$[0]),void 0!==($=l.split("Twitter"))[1]&&(l=$[0]);var a=t(l),e={apple:{phone:a(g)&&!a(b),ipod:a(i),tablet:!a(g)&&a(j)&&!a(b),universal:a(k),device:(a(g)||a(i)||a(j)||a(k))&&!a(b)},amazon:{phone:a(c),tablet:!a(c)&&a(d),device:a(c)||a(d)},android:{phone:!a(b)&&a(c)||!a(b)&&a(h),tablet:!a(b)&&!a(c)&&!a(h)&&(a(d)||a(m)),device:!a(b)&&(a(c)||a(d)||a(h)||a(m))||a(/\bokhttp\b/i)},windows:{phone:a(b),tablet:a(n),device:a(b)||a(n)},other:{blackberry:a(o),blackberry10:a(p),opera:a(q),firefox:a(s),chrome:a(r),device:a(o)||a(p)||a(q)||a(s)||a(r)},any:!1,phone:!1,tablet:!1};return e.any=e.apple.device||e.android.device||e.windows.device||e.other.device,e.phone=e.apple.phone||e.android.phone||e.windows.phone,e.tablet=e.apple.tablet||e.android.tablet||e.windows.tablet,e}f=u();if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f}else if(typeof define==="function"&&define.amd){define(function(){return f})}else{this["isMobile"]=f}})(); |
@@ -1,17 +0,18 @@ | ||
const appleIphone = /iPhone/i; | ||
const appleIpod = /iPod/i; | ||
const appleTablet = /iPad/i; | ||
const androidPhone = /\bAndroid(?:.+)Mobile\b/i; | ||
const androidTablet = /Android/i; | ||
const amazonPhone = /(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i; | ||
const amazonTablet = /Silk/i; | ||
const windowsPhone = /Windows Phone/i; | ||
const windowsTablet = /\bWindows(?:.+)ARM\b/i; | ||
const otherBlackBerry = /BlackBerry/i; | ||
const otherBlackBerry10 = /BB10/i; | ||
const otherOpera = /Opera Mini/i; | ||
const otherChrome = /\b(CriOS|Chrome)(?:.+)Mobile/i; | ||
const otherFirefox = /Mobile(?:.+)Firefox\b/i; | ||
function match(regex, userAgent) { | ||
return regex.test(userAgent); | ||
var appleIphone = /iPhone/i; | ||
var appleIpod = /iPod/i; | ||
var appleTablet = /iPad/i; | ||
var appleUniversal = /\biOS-universal(?:.+)Mac\b/i; | ||
var androidPhone = /\bAndroid(?:.+)Mobile\b/i; | ||
var androidTablet = /Android/i; | ||
var amazonPhone = /(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i; | ||
var amazonTablet = /Silk/i; | ||
var windowsPhone = /Windows Phone/i; | ||
var windowsTablet = /\bWindows(?:.+)ARM\b/i; | ||
var otherBlackBerry = /BlackBerry/i; | ||
var otherBlackBerry10 = /BB10/i; | ||
var otherOpera = /Opera Mini/i; | ||
var otherChrome = /\b(CriOS|Chrome)(?:.+)Mobile/i; | ||
var otherFirefox = /Mobile(?:.+)Firefox\b/i; | ||
function createMatch(userAgent) { | ||
return function (regex) { return regex.test(userAgent); }; | ||
} | ||
@@ -21,3 +22,3 @@ export default function isMobile(userAgent) { | ||
userAgent || (typeof navigator !== 'undefined' ? navigator.userAgent : ''); | ||
let tmp = userAgent.split('[FBAN'); | ||
var tmp = userAgent.split('[FBAN'); | ||
if (typeof tmp[1] !== 'undefined') { | ||
@@ -30,53 +31,54 @@ userAgent = tmp[0]; | ||
} | ||
const result = { | ||
var match = createMatch(userAgent); | ||
var result = { | ||
apple: { | ||
phone: match(appleIphone, userAgent) && !match(windowsPhone, userAgent), | ||
ipod: match(appleIpod, userAgent), | ||
tablet: !match(appleIphone, userAgent) && | ||
match(appleTablet, userAgent) && | ||
!match(windowsPhone, userAgent), | ||
device: (match(appleIphone, userAgent) || | ||
match(appleIpod, userAgent) || | ||
match(appleTablet, userAgent)) && | ||
!match(windowsPhone, userAgent), | ||
phone: match(appleIphone) && !match(windowsPhone), | ||
ipod: match(appleIpod), | ||
tablet: !match(appleIphone) && match(appleTablet) && !match(windowsPhone), | ||
universal: match(appleUniversal), | ||
device: (match(appleIphone) || | ||
match(appleIpod) || | ||
match(appleTablet) || | ||
match(appleUniversal)) && | ||
!match(windowsPhone) | ||
}, | ||
amazon: { | ||
phone: match(amazonPhone, userAgent), | ||
tablet: !match(amazonPhone, userAgent) && match(amazonTablet, userAgent), | ||
device: match(amazonPhone, userAgent) || match(amazonTablet, userAgent), | ||
phone: match(amazonPhone), | ||
tablet: !match(amazonPhone) && match(amazonTablet), | ||
device: match(amazonPhone) || match(amazonTablet) | ||
}, | ||
android: { | ||
phone: (!match(windowsPhone, userAgent) && match(amazonPhone, userAgent)) || | ||
(!match(windowsPhone, userAgent) && match(androidPhone, userAgent)), | ||
tablet: !match(windowsPhone, userAgent) && | ||
!match(amazonPhone, userAgent) && | ||
!match(androidPhone, userAgent) && | ||
(match(amazonTablet, userAgent) || match(androidTablet, userAgent)), | ||
device: (!match(windowsPhone, userAgent) && | ||
(match(amazonPhone, userAgent) || | ||
match(amazonTablet, userAgent) || | ||
match(androidPhone, userAgent) || | ||
match(androidTablet, userAgent))) || | ||
match(/\bokhttp\b/i, userAgent), | ||
phone: (!match(windowsPhone) && match(amazonPhone)) || | ||
(!match(windowsPhone) && match(androidPhone)), | ||
tablet: !match(windowsPhone) && | ||
!match(amazonPhone) && | ||
!match(androidPhone) && | ||
(match(amazonTablet) || match(androidTablet)), | ||
device: (!match(windowsPhone) && | ||
(match(amazonPhone) || | ||
match(amazonTablet) || | ||
match(androidPhone) || | ||
match(androidTablet))) || | ||
match(/\bokhttp\b/i) | ||
}, | ||
windows: { | ||
phone: match(windowsPhone, userAgent), | ||
tablet: match(windowsTablet, userAgent), | ||
device: match(windowsPhone, userAgent) || match(windowsTablet, userAgent), | ||
phone: match(windowsPhone), | ||
tablet: match(windowsTablet), | ||
device: match(windowsPhone) || match(windowsTablet) | ||
}, | ||
other: { | ||
blackberry: match(otherBlackBerry, userAgent), | ||
blackberry10: match(otherBlackBerry10, userAgent), | ||
opera: match(otherOpera, userAgent), | ||
firefox: match(otherFirefox, userAgent), | ||
chrome: match(otherChrome, userAgent), | ||
device: match(otherBlackBerry, userAgent) || | ||
match(otherBlackBerry10, userAgent) || | ||
match(otherOpera, userAgent) || | ||
match(otherFirefox, userAgent) || | ||
match(otherChrome, userAgent), | ||
blackberry: match(otherBlackBerry), | ||
blackberry10: match(otherBlackBerry10), | ||
opera: match(otherOpera), | ||
firefox: match(otherFirefox), | ||
chrome: match(otherChrome), | ||
device: match(otherBlackBerry) || | ||
match(otherBlackBerry10) || | ||
match(otherOpera) || | ||
match(otherFirefox) || | ||
match(otherChrome) | ||
}, | ||
any: false, | ||
phone: false, | ||
tablet: false, | ||
tablet: false | ||
}; | ||
@@ -83,0 +85,0 @@ result.any = |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A simple JS library that detects mobile devices.", | ||
@@ -35,5 +35,7 @@ "keywords": [ | ||
"test": "jest", | ||
"format": "web-scripts format", | ||
"lint": "web-scripts lint", | ||
"commit": "web-scripts commit", | ||
"release": "web-scripts release" | ||
"release": "web-scripts release", | ||
"prepare": "web-scripts audit" | ||
}, | ||
@@ -47,10 +49,10 @@ "husky": { | ||
"devDependencies": { | ||
"@spotify/web-scripts": "^1.2.0", | ||
"@types/puppeteer": "^1.19.1", | ||
"husky": "^3.0.3", | ||
"jest-puppeteer": "^4.3.0", | ||
"parcel-bundler": "^1.12.3", | ||
"puppeteer": "^1.19.0", | ||
"ts-jest": "^24.0.2" | ||
"@spotify/web-scripts": "^6.2.0", | ||
"@types/puppeteer": "^2.0.1", | ||
"husky": "^4.2.5", | ||
"jest-puppeteer": "^4.4.0", | ||
"parcel-bundler": "^1.12.4", | ||
"puppeteer": "^2.1.1", | ||
"ts-jest": "^25.3.1" | ||
} | ||
} |
@@ -38,2 +38,3 @@ [![Build Status](https://travis-ci.org/kaimallea/isMobile.png)](https://travis-ci.org/kaimallea/isMobile) | ||
- `isMobile.apple.tablet` | ||
- `isMobile.apple.universal` | ||
- `isMobile.apple.device` (any mobile Apple device) | ||
@@ -81,5 +82,11 @@ | ||
```bash | ||
yarn install ismobilejs | ||
yarn add ismobilejs | ||
``` | ||
or | ||
```bash | ||
npm install ismobilejs | ||
``` | ||
#### Use | ||
@@ -105,3 +112,3 @@ | ||
// Minified version of isMobile included in the HTML since it's small | ||
(function () {var f=/iPhone/i,j=/iPod/i,p=/iPad/i,g=/\bAndroid(?:.+)Mobile\b/i,i=/Android/i,d=/\bAndroid(?:.+)SD4930UR\b/i,e=/\bAndroid(?:.+)(?:KF[A-Z]{2,4})\b/i,c=/Windows Phone/i,h=/\bWindows(?:.+)ARM\b/i,k=/BlackBerry/i,l=/BB10/i,m=/Opera Mini/i,n=/\b(CriOS|Chrome)(?:.+)Mobile/i,o=/Mobile(?:.+)Firefox\b/i;function b($,a){return $.test(a)}function a($){var a=($=$||("undefined"!=typeof navigator?navigator.userAgent:"")).split("[FBAN");void 0!==a[1]&&($=a[0]),void 0!==(a=$.split("Twitter"))[1]&&($=a[0]);var r={apple:{phone:b(f,$)&&!b(c,$),ipod:b(j,$),tablet:!b(f,$)&&b(p,$)&&!b(c,$),device:(b(f,$)||b(j,$)||b(p,$))&&!b(c,$)},amazon:{phone:b(d,$),tablet:!b(d,$)&&b(e,$),device:b(d,$)||b(e,$)},android:{phone:!b(c,$)&&b(d,$)||!b(c,$)&&b(g,$),tablet:!b(c,$)&&!b(d,$)&&!b(g,$)&&(b(e,$)||b(i,$)),device:!b(c,$)&&(b(d,$)||b(e,$)||b(g,$)||b(i,$))||b(/\bokhttp\b/i,$)},windows:{phone:b(c,$),tablet:b(h,$),device:b(c,$)||b(h,$)},other:{blackberry:b(k,$),blackberry10:b(l,$),opera:b(m,$),firefox:b(o,$),chrome:b(n,$),device:b(k,$)||b(l,$)||b(m,$)||b(o,$)||b(n,$)},any:!1,phone:!1,tablet:!1};return r.any=r.apple.device||r.android.device||r.windows.device||r.other.device,r.phone=r.apple.phone||r.android.phone||r.windows.phone,r.tablet=r.apple.tablet||r.android.tablet||r.windows.tablet,r}window.isMobile=a();})(); | ||
(function () {var a={};var f=/iPhone/i,h=/iPod/i,i=/iPad/i,r=/\biOS-universal(?:.+)Mac\b/i,g=/\bAndroid(?:.+)Mobile\b/i,j=/Android/i,c=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,d=/Silk/i,b=/Windows Phone/i,k=/\bWindows(?:.+)ARM\b/i,m=/BlackBerry/i,n=/BB10/i,o=/Opera Mini/i,p=/\b(CriOS|Chrome)(?:.+)Mobile/i,q=/Mobile(?:.+)Firefox\b/i;function s(l){return function($){return $.test(l)}}function e(l){var $=(l=l||("undefined"!=typeof navigator?navigator.userAgent:"")).split("[FBAN");void 0!==$[1]&&(l=$[0]),void 0!==($=l.split("Twitter"))[1]&&(l=$[0]);var a=s(l),e={apple:{phone:a(f)&&!a(b),ipod:a(h),tablet:!a(f)&&a(i)&&!a(b),universal:a(r),device:(a(f)||a(h)||a(i))&&!a(b)},amazon:{phone:a(c),tablet:!a(c)&&a(d),device:a(c)||a(d)},android:{phone:!a(b)&&a(c)||!a(b)&&a(g),tablet:!a(b)&&!a(c)&&!a(g)&&(a(d)||a(j)),device:!a(b)&&(a(c)||a(d)||a(g)||a(j))||a(/\bokhttp\b/i)},windows:{phone:a(b),tablet:a(k),device:a(b)||a(k)},other:{blackberry:a(m),blackberry10:a(n),opera:a(o),firefox:a(q),chrome:a(p),device:a(m)||a(n)||a(o)||a(q)||a(p)},any:!1,phone:!1,tablet:!1};return e.any=e.apple.universal||e.apple.device||e.android.device||e.windows.device||e.other.device,e.phone=e.apple.phone||e.android.phone||e.windows.phone,e.tablet=e.apple.tablet||e.android.tablet||e.windows.tablet,e}a=e();if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=a}else if(typeof define==="function"&&define.amd){define(function(){return a})}else{this["isMobile"]=a}})(); | ||
@@ -108,0 +115,0 @@ // My own arbitrary use of isMobile, as an example |
@@ -31,2 +31,3 @@ import puppeteer from 'puppeteer'; | ||
"tablet": false, | ||
"universal": false, | ||
}, | ||
@@ -33,0 +34,0 @@ "other": Object { |
const appleIphone = /iPhone/i; | ||
const appleIpod = /iPod/i; | ||
const appleTablet = /iPad/i; | ||
const appleUniversal = /\biOS-universal(?:.+)Mac\b/i; | ||
const androidPhone = /\bAndroid(?:.+)Mobile\b/i; // Match 'Android' AND 'Mobile' | ||
@@ -16,4 +17,4 @@ const androidTablet = /Android/i; | ||
function match(regex: RegExp, userAgent: string): boolean { | ||
return regex.test(userAgent); | ||
function createMatch(userAgent: string): (regex: RegExp) => boolean { | ||
return (regex: RegExp): boolean => regex.test(userAgent); | ||
} | ||
@@ -26,2 +27,3 @@ | ||
tablet: boolean; | ||
universal: boolean; | ||
device: boolean; | ||
@@ -77,55 +79,56 @@ }; | ||
const match = createMatch(userAgent); | ||
const result: isMobileResult = { | ||
apple: { | ||
phone: match(appleIphone, userAgent) && !match(windowsPhone, userAgent), | ||
ipod: match(appleIpod, userAgent), | ||
tablet: | ||
!match(appleIphone, userAgent) && | ||
match(appleTablet, userAgent) && | ||
!match(windowsPhone, userAgent), | ||
phone: match(appleIphone) && !match(windowsPhone), | ||
ipod: match(appleIpod), | ||
tablet: !match(appleIphone) && match(appleTablet) && !match(windowsPhone), | ||
universal: match(appleUniversal), | ||
device: | ||
(match(appleIphone, userAgent) || | ||
match(appleIpod, userAgent) || | ||
match(appleTablet, userAgent)) && | ||
!match(windowsPhone, userAgent), | ||
(match(appleIphone) || | ||
match(appleIpod) || | ||
match(appleTablet) || | ||
match(appleUniversal)) && | ||
!match(windowsPhone), | ||
}, | ||
amazon: { | ||
phone: match(amazonPhone, userAgent), | ||
tablet: !match(amazonPhone, userAgent) && match(amazonTablet, userAgent), | ||
device: match(amazonPhone, userAgent) || match(amazonTablet, userAgent), | ||
phone: match(amazonPhone), | ||
tablet: !match(amazonPhone) && match(amazonTablet), | ||
device: match(amazonPhone) || match(amazonTablet), | ||
}, | ||
android: { | ||
phone: | ||
(!match(windowsPhone, userAgent) && match(amazonPhone, userAgent)) || | ||
(!match(windowsPhone, userAgent) && match(androidPhone, userAgent)), | ||
(!match(windowsPhone) && match(amazonPhone)) || | ||
(!match(windowsPhone) && match(androidPhone)), | ||
tablet: | ||
!match(windowsPhone, userAgent) && | ||
!match(amazonPhone, userAgent) && | ||
!match(androidPhone, userAgent) && | ||
(match(amazonTablet, userAgent) || match(androidTablet, userAgent)), | ||
!match(windowsPhone) && | ||
!match(amazonPhone) && | ||
!match(androidPhone) && | ||
(match(amazonTablet) || match(androidTablet)), | ||
device: | ||
(!match(windowsPhone, userAgent) && | ||
(match(amazonPhone, userAgent) || | ||
match(amazonTablet, userAgent) || | ||
match(androidPhone, userAgent) || | ||
match(androidTablet, userAgent))) || | ||
match(/\bokhttp\b/i, userAgent), | ||
(!match(windowsPhone) && | ||
(match(amazonPhone) || | ||
match(amazonTablet) || | ||
match(androidPhone) || | ||
match(androidTablet))) || | ||
match(/\bokhttp\b/i), | ||
}, | ||
windows: { | ||
phone: match(windowsPhone, userAgent), | ||
tablet: match(windowsTablet, userAgent), | ||
device: match(windowsPhone, userAgent) || match(windowsTablet, userAgent), | ||
phone: match(windowsPhone), | ||
tablet: match(windowsTablet), | ||
device: match(windowsPhone) || match(windowsTablet), | ||
}, | ||
other: { | ||
blackberry: match(otherBlackBerry, userAgent), | ||
blackberry10: match(otherBlackBerry10, userAgent), | ||
opera: match(otherOpera, userAgent), | ||
firefox: match(otherFirefox, userAgent), | ||
chrome: match(otherChrome, userAgent), | ||
blackberry: match(otherBlackBerry), | ||
blackberry10: match(otherBlackBerry10), | ||
opera: match(otherOpera), | ||
firefox: match(otherFirefox), | ||
chrome: match(otherChrome), | ||
device: | ||
match(otherBlackBerry, userAgent) || | ||
match(otherBlackBerry10, userAgent) || | ||
match(otherOpera, userAgent) || | ||
match(otherFirefox, userAgent) || | ||
match(otherChrome, userAgent), | ||
match(otherBlackBerry) || | ||
match(otherBlackBerry10) || | ||
match(otherOpera) || | ||
match(otherFirefox) || | ||
match(otherChrome), | ||
}, | ||
@@ -132,0 +135,0 @@ any: false, |
{ | ||
"extends": "@spotify/web-scripts/config/tsconfig.json", | ||
"include": ["src"], | ||
"exclude": ["src/__tests__", "src/index.browser.ts"] | ||
"exclude": ["src/__tests__", "src/index.browser.ts"], | ||
"compilerOptions": { | ||
"target": "es3" | ||
} | ||
} |
export * from './isMobile'; | ||
export { default } from './isMobile'; | ||
// # sourceMappingURL=index.d.ts.map |
export declare type isMobileResult = { | ||
apple: { | ||
phone: boolean; | ||
ipod: boolean; | ||
tablet: boolean; | ||
device: boolean; | ||
}; | ||
amazon: { | ||
phone: boolean; | ||
tablet: boolean; | ||
device: boolean; | ||
}; | ||
android: { | ||
phone: boolean; | ||
tablet: boolean; | ||
device: boolean; | ||
}; | ||
windows: { | ||
phone: boolean; | ||
tablet: boolean; | ||
device: boolean; | ||
}; | ||
other: { | ||
blackberry: boolean; | ||
blackberry10: boolean; | ||
opera: boolean; | ||
firefox: boolean; | ||
chrome: boolean; | ||
device: boolean; | ||
}; | ||
apple: { | ||
phone: boolean; | ||
ipod: boolean; | ||
tablet: boolean; | ||
any: boolean; | ||
universal: boolean; | ||
device: boolean; | ||
}; | ||
amazon: { | ||
phone: boolean; | ||
tablet: boolean; | ||
device: boolean; | ||
}; | ||
android: { | ||
phone: boolean; | ||
tablet: boolean; | ||
device: boolean; | ||
}; | ||
windows: { | ||
phone: boolean; | ||
tablet: boolean; | ||
device: boolean; | ||
}; | ||
other: { | ||
blackberry: boolean; | ||
blackberry10: boolean; | ||
opera: boolean; | ||
firefox: boolean; | ||
chrome: boolean; | ||
device: boolean; | ||
}; | ||
phone: boolean; | ||
tablet: boolean; | ||
any: boolean; | ||
}; | ||
export default function isMobile(userAgent?: string): isMobileResult; | ||
// # sourceMappingURL=isMobile.d.ts.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
71956
38
1433
170