Socket
Socket
Sign inDemoInstall

caniuse-on-user-agent

Package Overview
Dependencies
3
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    caniuse-on-user-agent

Given a User-Agent string, find out whether a browser feature is supported


Version published
Weekly downloads
15
decreased by-54.55%
Maintainers
1
Install size
2.03 MB
Created
Weekly downloads
 

Readme

Source

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',
);
//=> 'y'

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

Keywords

FAQs

Last updated on 21 Feb 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc