
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
browserslist-useragent-regexp
Advanced tools
A utility to compile browserslist query to a RegExp to test browser useragent.
A utility to compile browserslist query to a regex to test browser useragent. Simplest example: you can detect supported browsers on client-side.
.browserslistrc config, for example like this:last 2 versions
not dead
package.json:{
"scripts": {
"supportedBrowsers": "echo \"export default $(browserslist-useragent-regexp --allowHigherVersions);\" > supportedBrowsers.js"
}
}
{
"scripts": {
"supportedBrowsers": "(echo export default && browserslist-useragent-regexp --allowHigherVersions) > supportedBrowsers.js"
}
}
pnpm supportedBrowsers
# or
npm run supportedBrowsers
# or
yarn supportedBrowsers
supportedBrowsers.js:
export default /Edge?\/(10[5-9]|1[1-9]\d|[2-9]\d\d|\d{4,})(\.\d+|)(\.\d+|)|Firefox\/(10[4-9]|1[1-9]\d|[2-9]\d\d|\d{4,})\.\d+(\.\d+|)|Chrom(ium|e)\/(10[5-9]|1[1-9]\d|[2-9]\d\d|\d{4,})\.\d+(\.\d+|)|Maci.* Version\/(15\.([6-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})\.\d+)([,.]\d+|)( Mobile\/\w+|) Safari\/|Chrome.+OPR\/(9\d|\d{3,})\.\d+\.\d+|(CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS|CPU iPad OS)[ +]+(15[._]([6-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})[._]\d+)([._]\d+|)|Opera Mini|Android:?[ /\-](10[6-9]|1[1-9]\d|[2-9]\d{2}|\d{4,})(\.\d+|)(\.\d+|)|Mobile Safari.+OPR\/(6[4-9]|[7-9]\d|\d{3,})\.\d+\.\d+|Android.+Firefox\/(10[5-9]|1[1-9]\d|[2-9]\d\d|\d{4,})\.\d+(\.\d+|)|Android.+Chrom(ium|e)\/(10[6-9]|1[1-9]\d|[2-9]\d\d|\d{4,})\.\d+(\.\d+|)|Android.+(UC? ?Browser|UCWEB|U3)[ /]?(13\.([4-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+)\.\d+|SamsungBrowser\/(1[7-9]|[2-9]\d|\d{3,})\.\d+|Android.+MQQBrowser\/(13(\.([1-9]|\d{2,})|)|(1[4-9]|[2-9]\d|\d{3,})(\.\d+|))(\.\d+|)|K[Aa][Ii]OS\/(2\.([5-9]|\d{2,})|([3-9]|\d{2,})\.\d+)(\.\d+|)/;
import supportedBrowsers from './supportedBrowsers.js';
if (supportedBrowsers.test(navigator.userAgent)) {
alert('Your browser is supported.');
}
pnpm add -D browserslist-useragent-regexp
# or
npm i -D browserslist-useragent-regexp
# or
yarn add -D browserslist-useragent-regexp
As was written in article "Smart Bundling: Shipping legacy code to only legacy browsers": you can determinate, which bundle you should give to browser from server with browserslist-useragent. But in this case you must have your own server with special logic. Now, with browserslist-useragent-regexp, you can move that to client-side.
Development was inspired by this proposal from Mathias Bynens.
How to make differential resource loading and other optimizations with browserslist-useragent-regexp you can read in article "Speed up with Browserslist".
Demo (sources, build script).
Also, testing useragents using generated regex is faster than using the matchesUA method from browserslist-useragent.
pnpm browserslist-useragent-regexp [query] [...options]
# or
npx browserslist-useragent-regexp [query] [...options]
# or
yarn exec -- browserslist-useragent-regexp [query] [...options]
Also, short alias is available:
pnpm bluare [query] [...options]
| Option | Description | Default |
|---|---|---|
| query | Manually provide a browserslist query. Specifying this overrides the browserslist configuration specified in your project. | |
| ‑‑help, -h | Print this message. | |
| ‑‑verbose, -v | Print additional info about regexes. | |
| ‑‑ignorePatch | Ignore differences in patch browser numbers. | true |
| ‑‑ignoreMinor | Ignore differences in minor browser versions. | false |
| ‑‑allowHigherVersions | For all the browsers in the browserslist query, return a match if the useragent version is equal to or higher than the one specified in browserslist. | false |
| ‑‑allowZeroSubversions | Ignore match of patch or patch and minor, if they are 0. | false |
Module exposes two main methods:
Compile browserslist query to regexes for each browser.
Compile browserslist query to one regex.
| Option | Type | Default | Description |
|---|---|---|---|
| browsers | string | string[] | — | Manually provide a browserslist query (or an array of queries). Specifying this overrides the browserslist configuration specified in your project. |
| ignorePatch | boolean | true | Ignore differences in patch browser numbers. |
| ignoreMinor | boolean | false | Ignore differences in minor browser versions. |
| allowHigherVersions | boolean | false | For all the browsers in the browserslist query, return a match if the useragent version is equal to or higher than the one specified in browserslist. |
| allowZeroSubversions | boolean | false | Ignore match of patch or patch and minor, if they are 0. |
Any of the browserslist API options may also be provided.
| Property | Type | Description |
|---|---|---|
| family | string | Browser family. |
| requestVersions | [number, number, number][] | Versions provided by browserslist. |
| regex | RegExp | Regex to match useragent with family and versions. |
| sourceRegex | RegExp | Original useragent regex, without versions. |
| version | [number, number, number] | null | Useragent version of regex. |
| minVersion | [number, number, number] | null | Useragent min version of regex. |
| maxVersion | [number, number, number] | null | Useragent max version of regex. |
The `browserslist` package is used to share target browsers between different front-end tools, like Autoprefixer, ESLint, and Babel. While it does not generate regular expressions for user agents, it provides the core functionality for defining and querying browser support.
The `ua-parser-js` package is a JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model from userAgent string. Unlike `browserslist-useragent-regexp`, it focuses on parsing and identifying user agent details rather than matching them against Browserslist queries.
The `detect-browser` package is a lightweight library to detect the browser name and version. It provides a simple API to get the browser information but does not support Browserslist queries or regular expression generation for user agents.
FAQs
A utility to compile browserslist query to a RegExp to test browser useragent.
The npm package browserslist-useragent-regexp receives a total of 67,092 weekly downloads. As such, browserslist-useragent-regexp popularity was classified as popular.
We found that browserslist-useragent-regexp demonstrated a not healthy version release cadence and project activity because the last version was released 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.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.