Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

browserslist-generator

wessberg176.8kMIT3.0.0TypeScript support: included

A library that makes generating and validating Browserslists a breeze!

browserslist, caniuse, generate, support, babel-preset-env, util

readme

Logo

A library that makes generating and validating Browserslists a breeze!

Downloads per month NPM version Dependencies Contributors code style: prettier License: MIT Support on Patreon

Description

This is a library that makes it easier to work with browserslists. It can do things like generating a Browserslist that targets only browsers that support - or don't support - specific required features, or even generate a Browserslist from a User Agent string! It can also do the same in reverse - match a Browserslist on a user agent. A Feature is anything that can be found on caniuse or MDN.

Features

  • Generating a Browserslist based on features
  • Generating a Browserslist based on an ECMA version
  • Generating a browserslist based on a User Agent string
  • Checking if a User Agent string supports specific features
  • Checking if a browserslist supports specific features
  • Checking if a browserslist supports a specific ECMA version
  • Getting the most appropriate ECMA version for a browserslist

Backers

Patreon

Patrons on Patreon

Table of Contents

Install

npm

$ npm install browserslist-generator

Yarn

$ yarn add browserslist-generator

pnpm

$ pnpm add browserslist-generator

Usage

Generating a Browserslist based on features

When deciding which Browsers and environments to support, it is quite common to make the decision based on feature support. With this library, you no longer have to neither look up Browser support and manually write a Browserslist, nor make sure to keep it up-to-date. Instead, simply declare the features that should be available:

import {browsersWithSupportForFeatures} from "browserslist-generator";
// Generate a browserslist for browsers that support all of the given features
const browserslist = browsersWithSupportForFeatures("es6-module", "shadowdomv1", "custom-elementsv1");

Checking if a User Agent supports a specific feature

This library offers simple ways that you can check if a given User Agent supports any amount of features. This could be useful, among other things, for conditional bundle serving:

import {userAgentSupportsFeatures} from "browserslist-generator";
if (userAgentSupportsFeatures(userAgentString, "javascript.builtins.Promise.finally")) {
    doA();
} else {
    doB();
}

Checking if a Browserslist supports a specific feature

Given an existing Browserslist, this library can check if it supports one or more features. This could be useful, among other things, for conditional bundle serving:

import {browserslistSupportsFeatures} from "browserslist-generator";
if (browserslistSupportsFeatures(browserslist, "es6-module")) {
    useModernBundle();
} else {
    useLegacyBundle();
}

Generating a Browserslist based on a ECMAScript version

When deciding which Browsers and environments to support, it is quite common to make the decision based on a specific version of ECMAScript to target. For example, with the Typescript Compiler, the target option takes an ECMAScript version and the Typescript Compiler then knows which transformations to apply accordingly.

import {browsersWithSupportForEcmaVersion} from "browserslist-generator";
// Generate a browserslist for browsers that support the given version of ECMAScript
const browserslist = browsersWithSupportForEcmaVersion("es2015");

Checking if a Browserslist supports a specific ECMAScript version

Given an existing Browserslist, this library can also check if it supports a specific version of ECMAScript. This could be useful, among other things, for conditional bundle serving:

import {browserslistSupportsEcmaVersion} from "browserslist-generator";
if (browserslistSupportsEcmaVersion(browserslist, "es2015")) {
    useModernBundle();
} else {
    useLegacyBundle();
}

Getting the most appropriate ECMAScript version for a Browserslist

Given an existing Browserslist, this library can detect the most appropriate ECMAScript version to target. This could be useful, for example, when using the Typescript compiler based on a Browserslist.

import {getAppropriateEcmaVersionForBrowserslist} from "browserslist-generator";

const typescriptOptions = {
    // ...
    target: getAppropriateEcmaVersionForBrowserslist(browserslist)
};

Possible ECMAScript versions

All of the possible ECMAScript versions are:

  • es3
  • es5
  • es2015
  • es2016
  • es2017
  • es2018
  • es2019
  • es2020,
  • es2021,
  • es2022,
  • es2023
  • es2024

Contributing

Do you want to contribute? Awesome! Please follow these recommendations.

Maintainers

Frederik Wessberg
Frederik Wessberg
Twitter: @FredWessberg
Github: @wessberg
Lead Developer

FAQ

What is some cool example of a use case for this library?

Well, here's one I think is pretty neat: You're building an app, and you care about serving the smallest amount of code to your users. You've decided to build two bundles: One for browsers with, and one for browsers without ES-module support. You can now generate two Browserslists via browserslist-generator:

browsersWithSupportForFeatures("es6-module");
browsersWithoutSupportForFeatures("es6-module");

Now, you can then pass each one into tools like @babel/preset-env and postcss. On the server, you can use the function userAgentSupportsFeatures to check if the same features are supported and respond with resources that points to the right bundle.

License

MIT © Frederik Wessberg (@FredWessberg) (Website)

changelog

3.0.0 (2024-09-24)

Features

  • bump dependencies and support Node 22 (9bd472e)

2.3.0 (2024-08-30)

Features

  • allow more precise filtering (553c111)
  • remove and_qq, and_uc, baidu, and kaios from generated browserslists, as the data for these browsers are lacking and harms feature detection otherwise (ac24451)

2.2.0 (2024-08-30)

Features

2.1.0 (2023-08-02)

Features

2.0.3 (2023-02-02)

Bug Fixes

  • point to new feature name for nullish coalescing assignments in mdn compat data (af2b4ca)

2.0.2 (2023-01-23)

Bug Fixes

  • add type modifiers to relevant exports (909050a)
  • run tests on Node v16.14.0 and up (75ebb7e)
  • run tests on Node v16.14.0 and up (f65d487)
  • run tests on v16.15.1 instead (ba406d5)

Features

  • handle Android browsers even better (f28918f)

2.0.1 (2023-01-20)

Bug Fixes

Features

  • improve Android feature detection (b687a2d)
  • migrate to ESM (3d5c8f0)

1.0.66 (2022-04-12)

1.0.65 (2021-11-17)

Bug Fixes

  • use TypeScript 4.4.3 for now (73c529c)

Features

  • add support for ES2021 and ES2022 Ecma versions (81eecb8)

1.0.64 (2021-09-24)

1.0.63 (2021-09-23)

1.0.62 (2021-09-21)

1.0.61 (2021-09-15)

Bug Fixes

  • removed a console.log that had slipped into the published package (6a73d26)

1.0.60 (2021-08-31)

1.0.59 (2021-06-02)

Bug Fixes

  • fix regression where iOS Safari can't always be parsed correctly (35da2f7)

1.0.58 (2021-05-21)

Features

  • ua: add support for Samsung Internet through its CrossApp feature (3018c9b)
  • ua: catch iPad on iPhone OS 3 (cd628fe)
  • ua: catch more bots (7ec729c)
  • ua: detect Instagram browser on iOS as ios_saf (45c9918)
  • ua: treat Nokia WAP browsers as IE 8 as that there are no equivalent browsers in Caniuse (4aa42be)

1.0.57 (2021-05-20)

Features

  • ua: fall back to the unknown Caniuse browser less often to catch more bad UAs (1c1db15)

1.0.56 (2021-05-20)

Bug Fixes

  • ua: add handling for WebKit-based browsers that do not support a Safari version and attempt to map back into an equivalent Safari version (1700ca4)
  • ua: detect even more bots (1bb27f4)
  • ua: detect more bots (9cd9f80)

Features

  • ua: add handling with fallbacks for unparseable user agents (33ff06a)
  • ua: add handling with more bots (75e891a)
  • ua: detect the Facebook browser on iOS more often (a1dd77a)

1.0.55 (2021-05-19)

Features

  • ua: fall back to latest known iOS Safari version (7359201)

1.0.54 (2021-05-19)

Features

  • ua: add better Pale Moon handling (74b1d74)

1.0.53 (2021-05-19)

Features

  • ua: add better support for MIUIBrowser on Android and catch more instances of Googlebot (3836da3)
  • ua: add better support for MIUIBrowser on Android and catch more instances of Googlebot (1c3d1a8)
  • ua: add handling or Sogou Explorer, Chromium on Smart TVs, Dalvik VMs, and others (52f9af7)

1.0.52 (2021-05-19)

Features

  • ua: add support for detecing Iceweasel as Firefox (158eb70)
  • ua: add support for detecing Iceweasel as Firefox (cf57061)
  • ua: add support for detecting browsers based on Gecko/Firefox like Iceweasel and IceDragon (065c696)

1.0.51 (2021-05-19)

Bug Fixes

  • ua: add support for Google AdsBot (06fd644)

1.0.50 (2021-05-19)

Bug Fixes

  • ua: add detection for more bots (bbffdbb)
  • ua: handle special case with the old stock Android browser (2f2847e)

1.0.49 (2021-05-19)

Features

  • ua: fix detection of the Facebook browser on iOS and Edge Mobile on Android (0a4562d)

1.0.48 (2021-05-19)

1.0.47 (2021-04-10)

Bug Fixes

  • edge: work around UAParser change where EdgeHTML versions weren't being used anymore (bba685f)

1.0.46 (2021-03-25)

1.0.44 (2021-03-16)

1.0.42 (2020-11-06)

1.0.41 (2020-10-27)

Bug Fixes

  • fix classList detection on Edge 15 and IE 10 (a66875b)

1.0.40 (2020-10-21)

1.0.39 (2020-10-13)

1.0.38 (2020-09-30)

1.0.37 (2020-06-22)

Bug Fixes

  • mdn: update mdn data structure (b83d160)

1.0.36 (2020-05-04)

Bug Fixes

  • correctly detect QQ browser and MiuiBrowser. (04f5f73)

1.0.35 (2020-03-30)

Bug Fixes

  • Android on Firefox: stop treating and_ff as firefox (fb645f4)

1.0.34 (2020-03-04)

Bug Fixes

  • add support for FBAN (Facebook in-app browser) on iOS and Android (0be9eea)

1.0.33 (2020-02-13)

Bug Fixes

  • remove temporary workaround now that an external issue in the Browserslist repository has been fixed (7573be5)

1.0.32 (2020-01-29)

Bug Fixes

  • add a workaround for a Browserslist regression (c8531ab)

1.0.31 (2020-01-28)

1.0.30 (2019-11-09)

Bug Fixes

  • and_chr: fix issue with detecting ECMA version support for and_chr. Closes #3 (e04fe9b)

1.0.29 (2019-10-15)

1.0.28 (2019-10-15)

1.0.27 (2019-10-01)

Bug Fixes

  • bug: mark Safari as not supporting Web Animations by default (9c77715)

1.0.26 (2019-09-25)

Bug Fixes

  • safari: fix an issue where ResizeObserver is detected as supported by Safari (it is an experimental opt-in feature) (6492c07)

1.0.25 (2019-09-25)

Bug Fixes

  • safari: fix an issue where ResizeObserver is detected as supported by Safari (it is an experimental opt-in feature) (b6d571c)

1.0.24 (2019-09-09)

Bug Fixes

  • caniuse: fix caniuse data that were broken for some time (f8babd7)

1.0.23 (2019-06-20)

Bug Fixes

  • bug: rollback on Caniuse version to 4.6.2 which doesn't include a dependency on the bad version of caniuse-lite (3f61c38)

1.0.22 (2019-06-20)

Bug Fixes

  • bug: fixes bug where Android version 'all' could lead to crashes (009f868)
  • bug: fixes bug where Android version 'all' could lead to crashes (886569b)
  • bug: rollback of update to broken version of caniuse-lite (f64533a)

1.0.21 (2019-05-29)

1.0.20 (2019-05-29)

Features

  • es2020: adds support for EcmaScript 2020 features and generating a browserslist for it (b6e598e)

1.0.19 (2019-05-08)

Bug Fixes

  • safari 12.1: fixes issue that would make Safari 12.1 appear as Safari TP (ed9dbe3)

1.0.18 (2019-04-11)

Features

  • Facebook Crawler: adds support for detecting The Facebook Crawler (facebookexternalhit) (3df1142)

1.0.17 (2019-04-11)

Features

  • browser support: adds support for detecting user agents from Chrome WebView (f5fed56)

1.0.16 (2019-04-07)

Bug Fixes

  • api.Window: adds data corrections for the MDN feature api.Window (de30bec)

1.0.15 (2019-03-30)

Bug Fixes

  • bug: fixes an issue with detecting ES2019 features (2f55451)

1.0.14 (2019-03-30)

Features

  • EcmaVersion: adds support for generating browserslists for browsers with support for ES2019 (55e3354)

1.0.13 (2019-03-12)

1.0.12 (2019-02-28)

Bug Fixes

  • browsers: adds support for parsing SamsungBrowser 8.2 (a6b3217)

1.0.11 (2019-02-16)

Bug Fixes

  • tests: fixes a test that would crash (9584632)

1.0.10 (2019-02-07)

1.0.9 (2019-01-28)

Bug Fixes

  • edge: fixes an issue where some minor versions of Edge 16 would report as Edge 18 (a0623f6)

1.0.8 (2019-01-24)

Bug Fixes

  • build: updates build scripts (a047643)
  • package.json: updated prettier configuration (ea31ab8)
  • project: ran prettier (406b371)
  • safari: fixes an issue where patch versions of safari 12 would incorrectly translate to safari TP (8398d13)

1.0.7 (2019-01-24)

Bug Fixes

  • build: updates build scripts (06f8e32)

1.0.6 (2019-01-24)

Bug Fixes

  • bug: fixes some issues with detecting safari vs safari TP (25c1b17)
  • build: adds Rollup to the build pipeline to produce simple, flat output (4218de0)
  • build: updates build scripts (dd9f8ab)

1.0.5 (2019-01-21)

Bug Fixes

  • documentation: fix logo dimensions (362b71b)
  • documentation: fix logo dimensions (cf35fea)

1.0.4 (2019-01-21)

Bug Fixes

  • documentation: adds a logo (8fd5091)
  • format: adds Prettier to the project including commit hooks (4954096)
  • format: adds Prettier to the project including commit hooks (5433f98)
  • package.json: adds files array rather than .npmignore to package.json (1faeb6d)

1.0.3 (2019-01-11)

1.0.2 (2019-01-07)

1.0.1 (2019-01-07)

1.0.0 (2019-01-07)

0.0.57 (2019-01-04)

0.0.56 (2018-12-22)

0.0.55 (2018-12-22)

0.0.54 (2018-12-06)

0.0.53 (2018-12-06)

0.0.52 (2018-10-31)

0.0.51 (2018-10-30)

0.0.50 (2018-10-24)

0.0.49 (2018-10-24)

0.0.48 (2018-10-10)

Features

  • Added a few new functions: 'getAppropriateEcmaVersionForBrowserslist', 'browserslistSupportsEcmaVersion', and 'browsersWithSupportForEcmaVersion' (8173687)

0.0.47 (2018-09-24)

0.0.46 (2018-09-24)

0.0.45 (2018-09-24)

0.0.44 (2018-09-09)

0.0.43 (2018-08-30)

0.0.42 (2018-08-30)

0.0.41 (2018-08-30)

0.0.40 (2018-08-30)

0.0.39 (2018-08-29)

0.0.38 (2018-07-30)

0.0.37 (2018-06-15)

0.0.36 (2018-06-13)

0.0.35 (2018-06-13)

0.0.34 (2018-06-13)

0.0.33 (2018-06-13)

0.0.32 (2018-06-13)

0.0.31 (2018-06-12)

0.0.30 (2018-06-07)

0.0.29 (2018-06-07)

0.0.28 (2018-06-07)

0.0.27 (2018-05-23)

0.0.26 (2018-05-18)

0.0.25 (2018-05-08)

0.0.24 (2018-05-07)

0.0.23 (2018-05-07)

0.0.22 (2018-05-07)

0.0.21 (2018-05-07)

0.0.20 (2018-05-06)

0.0.19 (2018-05-06)

0.0.18 (2018-05-06)

0.0.17 (2018-05-05)

0.0.16 (2018-05-05)

0.0.15 (2018-05-05)

0.0.14 (2018-05-05)

0.0.13 (2018-05-05)

0.0.12 (2018-05-05)

0.0.11 (2018-05-05)

0.0.10 (2018-05-05)

0.0.9 (2018-05-05)

0.0.8 (2018-05-05)

0.0.7 (2018-05-01)

0.0.6 (2018-04-30)

0.0.5 (2018-04-30)

0.0.4 (2018-04-30)