pax_global_header00006660000000000000000000000064133721730370014520gustar00rootroot0000000000000052 comment=1aaae360a730e0232f0d9b2b82ad05f30158cb13 isMobile-0.5.0/000077500000000000000000000000001337217303700132655ustar00rootroot00000000000000isMobile-0.5.0/.gitignore000066400000000000000000000000221337217303700152470ustar00rootroot00000000000000node_modules dist isMobile-0.5.0/.prettierrc000066400000000000000000000001261337217303700154500ustar00rootroot00000000000000{ "trailingComma": "none", "tabWidth": 2, "semi": true, "singleQuote": true } isMobile-0.5.0/.travis.yml000066400000000000000000000001271337217303700153760ustar00rootroot00000000000000language: node_js node_js: - "10.13" before_script: - npm install script: npm test isMobile-0.5.0/CONTRIBUTORS.md000066400000000000000000000013221337217303700155420ustar00rootroot00000000000000* 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.md000066400000000000000000000151551337217303700145530ustar00rootroot00000000000000[![Build Status](https://travis-ci.org/kaimallea/isMobile.png)](https://travis-ci.org/kaimallea/isMobile) [![Node dependencies status](https://david-dm.org/kaimallea/isMobile.png)](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 `