caniuse-on-user-agent
A small module that takes a User-Agent string and a caniuse.com feature ID, and returns support for that feature by the given user agent.
Keep in mind that user agent detection is inherently messy, so this module will sometimes fail or even return incorrect data. Do not rely on this module in order to detect what features to enable or polyfill. Also note that this package depends on caniuse-lite, and hence can result in code size that may not be desirable for your use case.
This project also includes TypeScript type definitions.
Installation
npm install caniuse-on-user-agent
Usage
import { canIUseOnUserAgent } from 'caniuse-on-user-agent';
canIUseOnUserAgent(
'fetch',
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0',
);
API
canIUseOnUserAgent(featureId: string, userAgent: string): string | null
Parameter: featureId
The ID of a specific feature as used on caniuse.com.
Parameter: userAgent
The User-Agent string of the browser for which you want to check if the given feature is supported.
Returns
If no data on the given browser was found, this function returns null
.
Otherwise, it returns the browser support as reported by caniuse-lite, e.g. y
if the feature is fully supported, a x
if it is partially supported with a vendor prefix, or n
when it is not supported. Note that it also may include footnotes, e.g. a x #1 #3
.
browserToCaniuseId(browserInfo: BrowserInfo): string | null
Parameter: browserInfo
A browser name, OS and version as reported by detect-browser.
Returns
If no ID for the given browser is known, this function returns null
.
Otherwise, it returns the user agent ID in the format used by caniuse.com.
Changelog
See CHANGELOG.md
.
License
MIT © Vincent Tunru