polyfill-ua

1.0.1 • Public • Published

polyfill-ua

NPM version Build status Test coverage Dependency Status License Downloads Gittip

Check whether a user agent requires a polyfill. Designed to be used with user-agent based polyfills.

You compile objects of browsers and versions, which denote the minimum version a feature requires. The compiled function returns true if a polyfill is required for that browser.

var browsers = {
  chrome: true, // supported on all versions of chrome
  ie: false, // not supported on any version of chrome,
  safari: 7, // supported on safari 7+. numbers are prefixed with `>= `
  ff: '>= 1.5.3', // supported on ff `1.5.3`. strings __must be semver ranges__
};
 
var polyfill = require('polyfill-ua').compile(browsers);
 
polyfill({
  family: 'safari',
  version: '8.0.0'
}); // => false because no polyfill is needed
 
polyfill({
  family: 'safari',
  version: '6.0.0'
}); // => true because a polyfill is needed

You can also compile functions from caniuse-db!

var polyfill = require('polyfill-ua').caniuse('imports');
 
polyfill({
  family: 'chrome',
  version: '38.0.0'
}); // false because you don't need a polyfill!
 
polyfill({
  family: 'ie',
  version: '8.0.0'
}); // true because you need a polyfill!

API

var agent = parse(useragent)

var fn = compile(browsers)

var fn = caniuse(browsers)

Package Sidebar

Install

npm i polyfill-ua

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • jongleberry