@wessberg/browserslist-generator

A library that helps with generating a browserslist automatically. For example, a browserslist can be generated that targets only browsers that support specific required features.

wessberg/browserslist-generator has been renamed to browserslist-generator. Please use browserslist-generator instead
Last updated 7 years ago by wessberg .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install @wessberg/browserslist-generator 
SYNC missed versions from official npm registry.
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

Become a sponsor/backer and get your logo listed here.

Bubbles Christopher Blanchard Ideal Postcodes Xerox
Bubbles
Twitter: @usebubbles
Christopher Blanchard Ideal Postcodes Xerox

Patreon

Patrons on Patreon

Table of Contents

Install

npm

$ npm install @wessberg/browserslist-generator

Yarn

$ yarn add @wessberg/browserslist-generator

pnpm

$ pnpm add @wessberg/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 "@wessberg/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 "@wessberg/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 "@wessberg/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 "@wessberg/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 "@wessberg/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 "@wessberg/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

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 @wessberg/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)

Current Tags

  • 1.0.47                                ...           latest (4 years ago)

95 Versions

  • 1.0.47 [deprecated]           ...           4 years ago
  • 1.0.46 [deprecated]           ...           4 years ago
  • 1.0.44 [deprecated]           ...           4 years ago
  • 1.0.42 [deprecated]           ...           4 years ago
  • 1.0.41 [deprecated]           ...           4 years ago
  • 1.0.40 [deprecated]           ...           4 years ago
  • 1.0.39 [deprecated]           ...           4 years ago
  • 1.0.38 [deprecated]           ...           4 years ago
  • 1.0.37 [deprecated]           ...           4 years ago
  • 1.0.36 [deprecated]           ...           5 years ago
  • 1.0.35 [deprecated]           ...           5 years ago
  • 1.0.34 [deprecated]           ...           5 years ago
  • 1.0.33 [deprecated]           ...           5 years ago
  • 1.0.32 [deprecated]           ...           5 years ago
  • 1.0.31 [deprecated]           ...           5 years ago
  • 1.0.30 [deprecated]           ...           5 years ago
  • 1.0.29 [deprecated]           ...           5 years ago
  • 1.0.28 [deprecated]           ...           5 years ago
  • 1.0.27 [deprecated]           ...           5 years ago
  • 1.0.26 [deprecated]           ...           5 years ago
  • 1.0.25 [deprecated]           ...           5 years ago
  • 1.0.24 [deprecated]           ...           5 years ago
  • 1.0.23 [deprecated]           ...           5 years ago
  • 1.0.22 [deprecated]           ...           5 years ago
  • 1.0.21 [deprecated]           ...           6 years ago
  • 1.0.20 [deprecated]           ...           6 years ago
  • 1.0.19 [deprecated]           ...           6 years ago
  • 1.0.18 [deprecated]           ...           6 years ago
  • 1.0.17 [deprecated]           ...           6 years ago
  • 1.0.16 [deprecated]           ...           6 years ago
  • 1.0.15 [deprecated]           ...           6 years ago
  • 1.0.14 [deprecated]           ...           6 years ago
  • 1.0.13 [deprecated]           ...           6 years ago
  • 1.0.12 [deprecated]           ...           6 years ago
  • 1.0.11 [deprecated]           ...           6 years ago
  • 1.0.10 [deprecated]           ...           6 years ago
  • 1.0.9 [deprecated]           ...           6 years ago
  • 1.0.8 [deprecated]           ...           6 years ago
  • 1.0.7 [deprecated]           ...           6 years ago
  • 1.0.6 [deprecated]           ...           6 years ago
  • 1.0.5 [deprecated]           ...           6 years ago
  • 1.0.4 [deprecated]           ...           6 years ago
  • 1.0.3 [deprecated]           ...           6 years ago
  • 1.0.2 [deprecated]           ...           6 years ago
  • 1.0.0 [deprecated]           ...           6 years ago
  • 0.0.57 [deprecated]           ...           6 years ago
  • 0.0.56 [deprecated]           ...           6 years ago
  • 0.0.54 [deprecated]           ...           6 years ago
  • 0.0.53 [deprecated]           ...           6 years ago
  • 0.0.52 [deprecated]           ...           6 years ago
  • 0.0.51 [deprecated]           ...           6 years ago
  • 0.0.50 [deprecated]           ...           6 years ago
  • 0.0.49 [deprecated]           ...           6 years ago
  • 0.0.48 [deprecated]           ...           6 years ago
  • 0.0.47 [deprecated]           ...           6 years ago
  • 0.0.45 [deprecated]           ...           6 years ago
  • 0.0.44 [deprecated]           ...           6 years ago
  • 0.0.43 [deprecated]           ...           6 years ago
  • 0.0.42 [deprecated]           ...           6 years ago
  • 0.0.41 [deprecated]           ...           6 years ago
  • 0.0.40 [deprecated]           ...           6 years ago
  • 0.0.39 [deprecated]           ...           6 years ago
  • 0.0.38 [deprecated]           ...           6 years ago
  • 0.0.37 [deprecated]           ...           6 years ago
  • 0.0.36 [deprecated]           ...           6 years ago
  • 0.0.35 [deprecated]           ...           6 years ago
  • 0.0.34 [deprecated]           ...           6 years ago
  • 0.0.33 [deprecated]           ...           6 years ago
  • 0.0.32 [deprecated]           ...           6 years ago
  • 0.0.31 [deprecated]           ...           6 years ago
  • 0.0.30 [deprecated]           ...           6 years ago
  • 0.0.28 [deprecated]           ...           6 years ago
  • 0.0.27 [deprecated]           ...           7 years ago
  • 0.0.26 [deprecated]           ...           7 years ago
  • 0.0.25 [deprecated]           ...           7 years ago
  • 0.0.24 [deprecated]           ...           7 years ago
  • 0.0.23 [deprecated]           ...           7 years ago
  • 0.0.22 [deprecated]           ...           7 years ago
  • 0.0.21 [deprecated]           ...           7 years ago
  • 0.0.20 [deprecated]           ...           7 years ago
  • 0.0.19 [deprecated]           ...           7 years ago
  • 0.0.18 [deprecated]           ...           7 years ago
  • 0.0.17 [deprecated]           ...           7 years ago
  • 0.0.16 [deprecated]           ...           7 years ago
  • 0.0.15 [deprecated]           ...           7 years ago
  • 0.0.14 [deprecated]           ...           7 years ago
  • 0.0.13 [deprecated]           ...           7 years ago
  • 0.0.12 [deprecated]           ...           7 years ago
  • 0.0.11 [deprecated]           ...           7 years ago
  • 0.0.10 [deprecated]           ...           7 years ago
  • 0.0.9 [deprecated]           ...           7 years ago
  • 0.0.8 [deprecated]           ...           7 years ago
  • 0.0.7 [deprecated]           ...           7 years ago
  • 0.0.6 [deprecated]           ...           7 years ago
  • 0.0.5 [deprecated]           ...           7 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (8)
Dev Dependencies (6)

Copyright 2013 - present © cnpmjs.org | Home |