Compoundjs Device Detective
What it does
Device Detective is a featherweight CompoundJs module which determines whether a user agent is a phone, tablet, desktop, text browser (e.g., Lynx), or a search engine crawler (e.g., GoogleBot, BingBot, Baiduspider, etc.). And it makes this info easy to get at.
Like all UA sniffers, Device Detective relies on a handful of regular expressions to determine what sort of device has issued the HTTP request. Device Detective implements MDN recommendations for detecting mobiles, and allows the developer to choose whether to use the distinction between tablets and smaller mobile devices, which is available via the UA header (it's not recommended for the general use case).
Installation
Simply cd
to your project's root directory and issue the following command.
npm install compoundjs-device-detective
//environment.js
...
var device = require('compoundjs-device-detective');
app.locals.device = compound.controllerExtensions.device = device;
...
//your_controller.js
load('application');
action('main', function (req, res){
...
device.isDesktop(req ) // true|false
...
});
detect( req )
=> {
"phone" : [boolean],
"tablet" : [boolean],
"mobile" : [boolean],
"desktop" : [boolean],
"lynx" : [boolean],
"crawler" : [boolean]
}
isPhone( req ) => [boolean]
isTablet( req ) => [boolean]
isMobile( req ) => [boolean]
isDesktop( req ) => [boolean]
isLynx( req ) => [boolean]
isCrawler( req ) => [boolean]