ua-supports
v0.0.1
Published
check if a range of user agents supports a feature
Downloads
3
Readme
ua-supports
check if a range of user agents supports a feature
Installation
$ npm install ua-supports
Usage
ua(useragents?: String) => (Feature) => Boolean
Given a user agent string, returns a function that can check against features if that user agent supports that feature or not.
The feature is just a hash of key => value pairs, where the key is the browser and the value is the lowest version of the browser that supports the feature to be tested.
See the following list of browser identifiers:
// The lowest version of the browser supporting this feature
MinimumVersion: String | Number
Feature: {
ie?: MinimumVersion,
firefox?: MinimumVersion,
chrome?: MinimumVersion,
safari?: MinimumVersion,
opera?: MinimumVersion,
ios_saf?: MinimumVersion,
op_mini?: MinimumVersion,
android?: MinimumVersion,
op_mob?: MinimumVersion,
bb?: MinimumVersion,
and_chr?: MinimumVersion,
and_ff?: MinimumVersion,
ie_mob?: MinimumVersion
}
useragents
The useragents string can be either a standard useragent identifier as found in
the User-Agent header, or a comma separated list of browser identifiers, with
or without versions, or special expressions like last X versions
. The syntax
is very much like the one used by
autoprefixer.
If no version is given, it will default to last 2 versions
of major browsers.
Example
var supports = ua('Mozilla/5.0 (X11; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0');
supports({
firefox: 34 // feature requires ff 34
}); // => true
// with 2 browsers
supports = ua('chrome, firefox');
supports({
firefox: 24 // the feature is only available in firefox, not in chrome
}); // => false
License
LGPLv3