pax_global_header 0000666 0000000 0000000 00000000064 13372173037 0014520 g ustar 00root root 0000000 0000000 52 comment=1aaae360a730e0232f0d9b2b82ad05f30158cb13 isMobile-0.5.0/ 0000775 0000000 0000000 00000000000 13372173037 0013265 5 ustar 00root root 0000000 0000000 isMobile-0.5.0/.gitignore 0000664 0000000 0000000 00000000022 13372173037 0015247 0 ustar 00root root 0000000 0000000 node_modules dist isMobile-0.5.0/.prettierrc 0000664 0000000 0000000 00000000126 13372173037 0015450 0 ustar 00root root 0000000 0000000 { "trailingComma": "none", "tabWidth": 2, "semi": true, "singleQuote": true } isMobile-0.5.0/.travis.yml 0000664 0000000 0000000 00000000127 13372173037 0015376 0 ustar 00root root 0000000 0000000 language: node_js node_js: - "10.13" before_script: - npm install script: npm test isMobile-0.5.0/CONTRIBUTORS.md 0000664 0000000 0000000 00000001322 13372173037 0015542 0 ustar 00root root 0000000 0000000 * Igor Ribeio Lima ([https://github.com/igorlima](https://github.com/igorlima)) * Clay Hinson ([https://github.com/clayhinson](https://github.com/clayhinson)) * Vitaly Orlov ([https://github.com/orloffv](https://github.com/orloffv)) * Shinnosuke Watanabe ([https://github.com/shinnn](https://github.com/shinnn)) * Vladimir Matsola ([https://github.com/vomchik](https://github.com/vomchik)) * Bryce Neal ([https://github.com/prettymuchbryce](https://github.com/prettymuchbryce)) * Todd Smith-Salter ([https://github.com/ToddSmithSalter](https://github.com/ToddSmithSalter)) * Ma Cheng ([https://github.com/mc-zone](https://github.com/mc-zone)) * Ruslan Ismagilov ([https://github.com/isRuslan](https://github.com/isRuslan)) isMobile-0.5.0/README.md 0000664 0000000 0000000 00000015155 13372173037 0014553 0 ustar 00root root 0000000 0000000 [](https://travis-ci.org/kaimallea/isMobile) [](https://david-dm.org/kaimallea/isMobile) # isMobile A simple JS library that detects mobile devices. ## Why use isMobile? You probably shouldn't use this library unless you absolutely have to. In most cases, good [responsive design](https://en.wikipedia.org/wiki/Responsive_web_design) solves the problem of controlling how to render things across different screen sizes. But there are always edge cases. If you have an edge case, then this library might be for you. I had very specific requirements for a project when I created this: **`- Redirect all iPhones, iPods, Android phones, and seven inch devices to the mobile site.`** Yep, at the time, a completely separate site had already been created for mobile devices. So I couldn't depend on media queries, feature detection, graceful degradation, progressive enhancement, or any of the cool techniques for selectively displaying things. I had to find a way to redirect visitors on certain devices to the mobile site. I couldn't do detection on the back-end, because the entire site was generated as HTML, and then cached and served by a [CDN](https://en.wikipedia.org/wiki/Content_delivery_network), so I had to do the detection client-side. So I resorted to User-Agent (UA) sniffing. I tried to keep the script small (**currently ~1.5k bytes, minified**) and simple, because it would need to execute in the `
`, 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. ## How it works in the browser isMobile runs quickly during initial page load to detect mobile devices; it then creates a JavaScript object with the results. ## How it works in Node.js You import and call the `isMobile` function, passing it a user agent string; it then returns a JavaScript object with the results. ## Devices detected by isMobile In 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. ### Apple devices - `isMobile.apple.phone` - `isMobile.apple.ipod` - `isMobile.apple.tablet` - `isMobile.apple.device` (any mobile Apple device) ### Android devices - `isMobile.android.phone` - `isMobile.android.tablet` - `isMobile.android.device` (any mobile Android device) ### Amazon Silk devices (also passes Android checks) - `isMobile.amazon.phone` - `isMobile.amazon.tablet` - `isMobile.amazon.device` (any mobile Amazon Silk device) ### Windows devices - `isMobile.windows.phone` - `isMobile.windows.tablet` - `isMobile.windows.device` (any mobile Windows device) ### "Other" devices - `isMobile.other.blackberry_10` - `isMobile.other.blackberry` - `isMobile.other.opera` (Opera Mini) - `isMobile.other.firefox` - `isMobile.other.chrome` - `isMobile.other.device` (any "Other" device) ### Aggregate Groupings - `isMobile.any` - any device matched - `isMobile.phone` - any device in the 'phone' groups above - `isMobile.tablet` - any device in the 'tablet' groups above ## Example Usage I include the minified version of the script, inline, and at the top of the ``. Cellular connections tend to suck, so it would be wasteful overhead to open another connection, just to download ~1.5kb of JS: ```html ``` ## Building manually After checking out the repo, install dependencies: ```shell npm install ``` Then build a minified, distributable JS file: ```shell npm run build ``` It will be output to `./dist/isMobile.min.js`. You can then use it with a `