Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

caniuse-on-user-agent

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

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

  • 1.0.1-master-c440120a04c1c4af2f725edb555f291caeb5b6ad
  • next
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 21 Feb 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc