UNPKG

ismobilejs-es5

Version:

A simple JS library that detects mobile devices.

89 lines 3.29 kB
var appleIphone = /iPhone/i; var appleIpod = /iPod/i; var appleTablet = /iPad/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); }; } export default function isMobile(userAgent) { userAgent = userAgent || (typeof navigator !== 'undefined' ? navigator.userAgent : ''); var tmp = userAgent.split('[FBAN'); if (typeof tmp[1] !== 'undefined') { userAgent = tmp[0]; } tmp = userAgent.split('Twitter'); if (typeof tmp[1] !== 'undefined') { userAgent = tmp[0]; } var match = createMatch(userAgent); var result = { apple: { phone: match(appleIphone) && !match(windowsPhone), ipod: match(appleIpod), tablet: !match(appleIphone) && match(appleTablet) && !match(windowsPhone), device: (match(appleIphone) || match(appleIpod) || match(appleTablet)) && !match(windowsPhone), }, amazon: { phone: match(amazonPhone), tablet: !match(amazonPhone) && match(amazonTablet), device: match(amazonPhone) || match(amazonTablet), }, android: { 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), tablet: match(windowsTablet), device: match(windowsPhone) || match(windowsTablet), }, other: { 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, }; result.any = result.apple.device || result.android.device || result.windows.device || result.other.device; result.phone = result.apple.phone || result.android.phone || result.windows.phone; result.tablet = result.apple.tablet || result.android.tablet || result.windows.tablet; return result; } //# sourceMappingURL=isMobile.js.map