All Projects → wessberg → browserslist-generator

wessberg / browserslist-generator

Licence: MIT license
A library that makes generating and validating Browserslists a breeze!

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to browserslist-generator

uainfer
Infer the user agent from its User Agent string
Stars: ✭ 21 (-72.73%)
Mutual labels:  user-agent, useragent
useragent-generator
Easily generate correct user-agent strings for popular browsers
Stars: ✭ 62 (-19.48%)
Mutual labels:  user-agent, useragent
Eslint Plugin Compat
Lint the browser compatibility of your code
Stars: ✭ 2,743 (+3462.34%)
Mutual labels:  caniuse, browserslist
bots-zoo
No description or website provided.
Stars: ✭ 59 (-23.38%)
Mutual labels:  user-agent, useragent
Browser.php
A PHP Class to detect a user's Browser. This encapsulation provides a breakdown of the browser and the version of the browser using the browser's user-agent string. This is not a guaranteed solution but provides an overall accurate way to detect what browser a user is using.
Stars: ✭ 546 (+609.09%)
Mutual labels:  user-agent, useragent
React Device Detect
Detect device, and render view according to detected device type.
Stars: ✭ 1,145 (+1387.01%)
Mutual labels:  user-agent, useragent
User agent
HTTP User Agent parser for the Go programming language.
Stars: ✭ 578 (+650.65%)
Mutual labels:  user-agent, useragent
Ng Device Detector
Angular module to detect OS / Browser / Device
Stars: ✭ 243 (+215.58%)
Mutual labels:  user-agent, useragent
ImNotSpider
浏览器User Agent生成器
Stars: ✭ 17 (-77.92%)
Mutual labels:  useragent
mdn-fiori
MDN Web Docs Front-End style guide
Stars: ✭ 16 (-79.22%)
Mutual labels:  mdn
idfx
Tool for flash/monitor ESP-IDF and ESP8266_SDK apps on the WSL2 ⚡
Stars: ✭ 71 (-7.79%)
Mutual labels:  support
okty
The simplest application to create and customize your docker projects
Stars: ✭ 48 (-37.66%)
Mutual labels:  generate
RDMSamples-ps
Remote Desktop Manager (RDM) samples of powershell code
Stars: ✭ 20 (-74.03%)
Mutual labels:  support
ModMail
A Discord ModMail Bot.
Stars: ✭ 54 (-29.87%)
Mutual labels:  support
big-frontend-knowlage
前端入门到进阶图文教程,超详细的Web前端学习笔记。从零开始学前端,做一名精致优雅的前端工程师。公众号「人生代码」作者。
Stars: ✭ 31 (-59.74%)
Mutual labels:  mdn
browserslist-config-google
Google / Google Workspace Browserslist Shared Config
Stars: ✭ 27 (-64.94%)
Mutual labels:  browserslist
vue-device-detector
A tiny device detector plugin of Vue for mobile🐔👁
Stars: ✭ 43 (-44.16%)
Mutual labels:  useragent
compat-db
A browser API compatibility database
Stars: ✭ 61 (-20.78%)
Mutual labels:  caniuse
crawlerdetect
Golang module to detect bots and crawlers via the user agent
Stars: ✭ 22 (-71.43%)
Mutual labels:  user-agent
auto-commit-msg
A VS Code extension to generate a smart commit message based on file changes
Stars: ✭ 61 (-20.78%)
Mutual labels:  generate
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 Trent Raymond
Bubbles
Twitter: @usebubbles
Christopher Blanchard Ideal Postcodes Xerox Trent Raymond

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

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)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].