express-caniuse

1.0.2 • Public • Published

express-caniuse

Express/Connect middleware for automatically determining browser capabilities

Description

This express middleware parses the user-agent of the incoming request, compares it to the Can I use database and adds an additional capabilities object to the req, showing which predetermined browser features are supported. Use it for analytics or for conditional rendering, for example!

Usage

npm install --save --production express-caniuse
 
var express           = require('express');
var canIUseMiddleware = require('express-caniuse');
 
var app = express();
 
app.use(canIUseMiddleware({
  features: [
    'addeventlistener',
    'setimmediate'
  ]
}));
 
app.get('hello', function (req, res, next) {
  // Tested on Chrome 59.0 on OSX
  console.log(req.capabilities)
  // {
  //  'addeventlistener': true,
  //  'setimmediate': false
  // }
});
 

If the browser could not be determined due to missing/unknown user-agent header, req.capabilities will be an empty object.

License

MIT © Matti Jokitulppo

npm version npm downloads Build Status

Package Sidebar

Install

npm i express-caniuse

Weekly Downloads

2

Version

1.0.2

License

MIT

Last publish

Collaborators

  • melonmanchan