GithubHelp home page GithubHelp logo

jalbertbowden / browserslist-useragent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from browserslist/browserslist-useragent

0.0 1.0 0.0 154 KB

๐Ÿฆ”A utility to match a browserslist query with user agent strings

License: MIT License

JavaScript 100.00%

browserslist-useragent's Introduction

Browserslist Useragent

Travis npm

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

npm install 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
Option Default Value Description
browsers โ€” Manually provide a browserslist query (or an array of queries). Specifying this overrides the browserslist configuration specified in your project.
env โ€” When multiple browserslist environments are specified, pick the config belonging to this environment.
ignorePatch true Ignore differences in patch browser numbers
ignoreMinor false Ignore differences in minor browser versions
allowHigherVersions false For 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

| Browser Family | Browserslist

  • Chrome (Chrome / Chromium / Yandex) as and_chr | ChromeAndroid | Chrome
  • Samsung Internet as Samsung
  • Firefox as ff | and_ff | FirefoxAndroid | Firefox
  • Safari iOS as ios_saf | iOS
  • Safari Desktop as Safari
  • IE as ie | ie_mob
  • Edge as Edge

PRs to add more browserslist supported browsers are welcome ๐Ÿ‘‹

Notes

  • All browsers on iOS (Chrome, Firefox etc) use Safari's WebKit as the underlying engine, and hence will be resolved to Safari. Since browserslist is usually used for transpiling / autoprefixing for browsers, this behaviour is what's intended in most cases, but might surprise you otherwise.

  • Right now, Chrome for Android and Firefox for Android are resolved to their desktop equivalents. The caniuse database does not currently store historical data for these browsers separately (except the last version) See #156. However, safari for iOS and desktop can be matched separately, since this data is available for both.

When querying for modern browsers

  • It is a good idea to update this package often so that browser definitions are upto date.
  • It is also a good idea to add unreleased versions to your browserslist query, and set ignoreMinor and ignorePatch to true so that alpha / beta / canary versions of browsers are matched.
  • In case you're unable to keep this package up-to-date, you can set the allowHigherVersions to true. For all the browsers specified in your browserslist query, this will return a match if the user agent version is equal to or higher than those specified in your browserslist query. Use this with care though, since it's a wildcard, and only lightly tested.

Further reads

browserslist-useragent's People

Contributors

gabrieldelepine avatar jazzzz avatar joeldenning avatar pastelsky avatar sheerun avatar simonihmig avatar wladyslawczyzewski avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.