Home

Awesome

Browserslist Useragent

build npm

<img align="right" width="120" height="120" src="https://cdn.rawgit.com/pastelsky/browserslist-useragent/master/logo.svg" alt="Browserslist Useragent logo (original by Anton Lovchikov)" />

Find if a given user agent string satisfies a browserslist query.

It automatically reads the browserslist configuration specified in your project, but you can also specify the same using the options parameter.

If you wish to target modern browsers, read this.

Installation

Note, browserslist is a peer dependency, so make sure you have that installed in your project.

npm install browserslist-useragent
# or 
yarn add browserslist-useragent

Usage

const { matchesUA } = require('browserslist-useragent')

matchesUA(userAgentString, options)

// with browserslist config inferred
matchesUA('Mozilla/5.0 (Windows NT 10.0; rv:54.0) Gecko/20100101 Firefox/54.0')
//returns boolean

// with explicit browserslist
matchesUA(
  'Mozilla/5.0 (Windows NT 10.0; rv:54.0) Gecko/20100101 Firefox/54.0',
  { browsers: ['Firefox > 53'] }
)
// returns true
OptionDefault ValueDescription
browsersManually provide a browserslist query (or an array of queries). Specifying this overrides the browserslist configuration specified in your project.
envWhen multiple browserslist environments are specified, pick the config belonging to this environment.
pathprocess.cwd()Specify a folder to search for the browserslist config (if it differs from the current working directory)
ignorePatchtrueIgnore differences in patch browser numbers
ignoreMinorfalseIgnore differences in minor browser versions
allowHigherVersionsfalseFor all the browsers in the browserslist query, return a match if the user agent version is equal to or higher than the one specified in browserslist. See why this might be useful.

Supported browsers

PRs to add more browserslist supported browsers are welcome 👋

Notes

When querying for modern browsers

Further reads