Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
browserslist-generator
Advanced tools
A library that makes generating and validating Browserslists a breeze!
A library that makes generating and validating Browserslists a breeze!
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.
Become a sponsor/backer and get your logo listed here.
Bubbles Twitter: @usebubbles | Christopher Blanchard | Ideal Postcodes | Xerox | Trent Raymond |
$ npm install browserslist-generator
$ yarn add browserslist-generator
$ pnpm add browserslist-generator
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");
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();
}
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();
}
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");
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();
}
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)
};
All of the possible ECMAScript versions are:
es3
es5
es2015
es2016
es2017
es2018
es2019
es2020
Do you want to contribute? Awesome! Please follow these recommendations.
Frederik Wessberg Twitter: @FredWessberg Github: @wessberg Lead Developer |
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.
MIT © Frederik Wessberg (@FredWessberg) (Website)
FAQs
A library that makes generating and validating Browserslists a breeze!
The npm package browserslist-generator receives a total of 11,898 weekly downloads. As such, browserslist-generator popularity was classified as popular.
We found that browserslist-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.