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!