0.2.0 • Published 8 years ago
sails-hook-device v0.2.0
sails-hook-device
Sails extension for determining device via user-agent header.
Installation
$ npm install sails-hook-device
Usage
Upon installation, a device object will be added to req.
//-- api/controllers/HomeController.js
module.exports = {
index: function(req, res) {
res.view({ device: req.device });
}
};
//-- views/home/index.ejs
<div>
<div><%- device.ios %></div>
<div><%- device.android %></div>
<div><%- device.phone %></div>
<div><%- device.tablet %></div>
<div><%- device.mobile %></div>
<div><%- device.webview %></div>
</div>
Properties
The ff. properties return true or false depending on the device used:
- ios
- android
- phone
- tablet
- mobile
- webview
Methods
is(property)
Returns true if property (case-insensitive) exists and matches the device used.
req.device.is("iOS");
req.device.is("Android");
req.device.is("anything");