{"name":"ismobilejs","version":"0.3.7","description":"A simple JS library that detects mobile devices.","keywords":["ismobile","device detection","mobile devices","useragent"],"homepage":"https://github.com/kaimallea/isMobile","license":"CC0-1.0","author":{"name":"Kai Mallea","email":"kmallea@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/kaimallea/isMobile.git"},"main":"./isMobile","devDependencies":{"grunt":"0.4.x","grunt-contrib-jshint":"0.11.x","grunt-contrib-uglify":"0.9.x","grunt-contrib-jasmine":"0.8.x"},"gitHead":"eea98e21b2fadbde9fe2c65b07f9eec912e27c55","bugs":{"url":"https://github.com/kaimallea/isMobile/issues"},"_id":"ismobilejs@0.3.7","scripts":{},"_shasum":"10e1cb83edcc37a872aafe168c29457f14085757","_from":".","_npmVersion":"2.11.2","_nodeVersion":"0.12.5","_npmUser":{"name":"kai","email":"kmallea@gmail.com"},"maintainers":[{"name":"kai","email":"kmallea@gmail.com"}],"dist":{"shasum":"10e1cb83edcc37a872aafe168c29457f14085757","tarball":"http://registry-npm.ywwl.com/ismobilejs/download/ismobilejs-0.3.7.tgz","integrity":"sha512-Q6/OllXPLPxMLGwAbxfi9F95hhWpiXuNPzy/aIWRUIwL7ZhMew6xQKXlbYrl40gYJVWAKEM4bJxGjzXuDE5dWg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDIrmqYNiAhvk4S1KXRfVFl3DecKfQ+aNs6kd3ytG2QmQIhANtP4NAWUcf/RUK3KymcSjfq5HkjRQraW43Os2yzAJg8"}],"size":6196,"noattachment":false,"key":"/ismobilejs/-/ismobilejs-0.3.7.tgz"},"directories":{},"readme":"[![Build Status](https://travis-ci.org/kaimallea/isMobile.png)](https://travis-ci.org/kaimallea/isMobile)\n[![Node dependencies status](https://david-dm.org/kaimallea/isMobile.png)](https://david-dm.org/kaimallea/isMobile)\n[![](https://data.jsdelivr.com/v1/package/npm/ismobilejs/badge)](https://www.jsdelivr.com/package/npm/ismobilejs)\n\n# isMobile\n\nA simple JS library that detects mobile devices in both the browser and NodeJS.\n\n## Why use isMobile?\n\n### In the Browser\n\nYou might not need this library. In most cases, [responsive design](https://en.wikipedia.org/wiki/Responsive_web_design) solves the problem of controlling how to render things across different screen sizes. I recommend a [mobile first](https://medium.com/@Vincentxia77/what-is-mobile-first-design-why-its-important-how-to-make-it-7d3cf2e29d00) approach. But there are always edge cases. If you have an edge case, then this library might be for you.\n\nMy edge case at the time was redirecting users to a completely separate mobile site. I tried to keep this script small (**currently ~1.3k bytes, minified**) and simple, because it would need to execute in the `<head>`, which is generally a bad idea, since JS blocks the downloading and rendering of all assets while it parses and executes. In the case of mobile redirection, I don't mind so much, because I want to start the redirect as soon as possible, before the device has a chance to start downloading and rendering other stuff. For non-mobile platforms, the script should execute fast, so the browser can quickly get back to downloading and rendering.\n\n#### How it works in the browser\n\nisMobile runs quickly during initial page load to detect mobile devices; it then creates a JavaScript object with the results.\n\n### In NodeJS\n\nYou might want to use this library to do server-side device detection to minimize the amount of bytes you send back to visitors. Or you have your own arbitrary use case.\n\n#### How is works in NodeJS\n\nYou import and call the `isMobile` function, passing it a user agent string; it then returns a JavaScript object with the results.\n\n## Devices detected by isMobile\n\nIn a browser, the following properties of the global `isMobile` object will either be `true` or `false`. In Node, `isMobile` will be whatever you named the variable.\n\n### Apple devices\n\n- `isMobile.apple.phone`\n- `isMobile.apple.ipod`\n- `isMobile.apple.tablet`\n- `isMobile.apple.universal`\n- `isMobile.apple.device` (any mobile Apple device)\n\n### Android devices\n\n- `isMobile.android.phone`\n- `isMobile.android.tablet`\n- `isMobile.android.device` (any mobile Android device; OkHttp user agents will match this)\n\n### Amazon Silk devices (also passes Android checks)\n\n- `isMobile.amazon.phone`\n- `isMobile.amazon.tablet`\n- `isMobile.amazon.device` (any mobile Amazon Silk device)\n\n### Windows devices\n\n- `isMobile.windows.phone`\n- `isMobile.windows.tablet`\n- `isMobile.windows.device` (any mobile Windows device)\n\n### \"Other\" devices\n\n- `isMobile.other.blackberry_10`\n- `isMobile.other.blackberry`\n- `isMobile.other.opera` (Opera Mini)\n- `isMobile.other.firefox`\n- `isMobile.other.chrome`\n- `isMobile.other.device` (any \"Other\" device)\n\n### Aggregate Groupings\n\n- `isMobile.any` - any device matched\n- `isMobile.phone` - any device in the 'phone' groups above\n- `isMobile.tablet` - any device in the 'tablet' groups above\n\n## Usage\n\n### Node.js\n\n#### Install\n\n```bash\nyarn add ismobilejs\n```\n\nor\n\n```bash\nnpm install ismobilejs\n```\n\n#### Use\n\n```ts\nimport isMobile from 'ismobilejs';\nconst userAgent = req.headers['user-agent'];\nconsole.log(isMobile(userAgent).any);\n```\n\nOr pass in a `window.navigator`-shaped object that includes at least a `userAgent` property. To properly detect iPad on iOS 13, the object should also include the `platform` and `maxTouchPoints` properties.\n\n```js\n// this is just an example. window.navigator is readonly in the browser\nwindow.navigator = {\n  ...\n  userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko)',\n  platform: 'MacIntel',\n  maxTouchPoints: 2,\n  ..\n}\n```\n\n```ts\nimport isMobile from 'ismobilejs';\nconsole.log(isMobile(window.navigator).apple.tablet);\n```\n\n### Browser\n\nA real-word example: I include the minified version of the script, inline, and at the top of the `<head>`. Cellular connections tend to suck, so it would be wasteful overhead to open another connection, just to download ~1.3kb of JS:\n\n<!-- prettier-ignore -->\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\" />\n    <script>\n      // Minified version of isMobile included in the HTML since it's small\n      (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}})();\n\n      // My own arbitrary use of isMobile, as an example\n      (function() {\n        var MOBILE_SITE = '/mobile/index.html', // site to redirect to\n          NO_REDIRECT = 'noredirect'; // cookie to prevent redirect\n\n        // I only want to redirect iPhones, Android phones\n        if (isMobile.apple.phone || isMobile.android.phone) {\n          // Only redirect if the user didn't previously choose\n          // to explicitly view the full site. This is validated\n          // by checking if a \"noredirect\" cookie exists\n          if (document.cookie.indexOf(NO_REDIRECT) === -1) {\n            document.location = MOBILE_SITE;\n          }\n        }\n      })();\n    </script>\n  </head>\n  <body>\n    <!-- imagine lots of html and content -->\n  </body>\n</html>\n```\n\n### jsDelivr CDN [![](https://data.jsdelivr.com/v1/package/npm/ismobilejs/badge)](https://www.jsdelivr.com/package/npm/ismobilejs)\n\nAlternatively, you can include this library via [jsDelivr CDN](https://www.jsdelivr.com/package/npm/ismobilejs) in a `script` tag:\n\n`<script src=\"https://cdn.jsdelivr.net/npm/ismobilejs@1/dist/isMobile.min.js\"></script>`\n\n**Visit the isMobile [jsDelivr page](https://www.jsdelivr.com/package/npm/ismobilejs) to get the most up-to-date URL pointing to the lastest version.**\n\n## Building manually\n\nAfter checking out the repo, install dependencies:\n\n```bash\nyarn install\n```\n\nThen build the library:\n\n```bash\nyarn build\n```\n\nThree versions of the library will be generated:\n\n1. `./cjs/index.js` - the CommonJS version of the library\n2. `./esm/index.js` - the ESModule version of the library\n3. `./dist/isMobile.min.js` - the browser version of the library\n\nAdditionally, types will be output to `types`.\n\n## Contributing\n\nThis library uses Spotify's [web-scripts](https://github.com/spotify/web-scripts) project to build, lint, test, format and release the this library.\n\nYou must use `yarn commit` rather than `git commit` to commit files. This enforced commit messages to following a specific format and enables automation of release notes and version bump.\n","publish_time":1436049309924,"_cnpm_publish_time":1436049309924,"dist-tags":{"latest":"1.1.1"}}