Skip to content

polyfills/polyfill-ua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Check whether a user agent requires a polyfill

Resources

License

Stars

Watchers

Forks

Packages

No packages published