Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browserslist

Package Overview
Dependencies
Maintainers
1
Versions
194
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browserslist - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

5

CHANGELOG.md

@@ -0,3 +1,6 @@

## 1.1
* Added query against custom browser usage data (by Daniel Rey).
## 1.0.1
* Update Firefox ESR.
* Update Firefox ESR (by Rouven Weßling).

@@ -4,0 +7,0 @@ ## 1.0

82

index.js

@@ -28,2 +28,16 @@ var caniuse = require('caniuse-db/data').agents;

// Helpers
var normalize = function (versions) {
return versions.filter(function (version) {
return typeof version === 'string';
});
};
var fillUsage = function (result, name, data) {
for ( var i in data ) {
result[name + ' ' + i] = data[i];
}
};
// Return array of browsers by selection queries:

@@ -60,2 +74,21 @@ //

if ( opts.stats || process.env.BROWSERSLIST_STATS ) {
browserslist.usage.custom = { };
var stats = opts.stats || process.env.BROWSERSLIST_STATS;
if ( typeof stats === 'string' ) {
try {
stats = JSON.parse(fs.readFileSync(stats));
} catch (e) {
error('Can\'t read ' + stats);
}
}
if ( 'dataByBrowser' in stats ) {
// Allow to use the data as-is from the caniuse.com website
stats = stats.dataByBrowser;
}
for ( var browser in stats ) {
fillUsage(browserslist.usage.custom, browser, stats[browser]);
}
}
var result = [];

@@ -114,4 +147,2 @@

// Helpers
var normalizeVersion = function (data, version) {

@@ -126,20 +157,7 @@ if ( data.versions.indexOf(version) !== -1 ) {

var normalize = function (versions) {
return versions.filter(function (version) {
return typeof version === 'string';
});
};
var fillUsage = function (result, name, data) {
for ( var i in data ) {
result[name + ' ' + i] = data[i];
}
};
browserslist.Error = BrowserslistError;
// Will be filled by Can I Use data below
browserslist.data = { };
browserslist.usage = {
global: { }
global: { },
custom: null
};

@@ -269,2 +287,32 @@

customStatistics: {
regexp: /^> (\d+\.?\d*)% in my stats$/,
select: function (popularity) {
popularity = parseFloat(popularity);
var result = [];
var usage = browserslist.usage.custom;
if ( !usage ) {
error('Custom usage data was not provided. ' +
'To use selection "> ' + popularity + '% in my stats" ' +
'you need one of the following:\n' +
'* browserslist("selections", ' +
'{stats: "path/to/the/stats_file.json"})\n' +
'* browserslist("selections", {stats: <stats object>})\n' +
'* Set the ENV variable BROWSERSLIST_STATS to the path ' +
'of the stats JSON file.\nThe expected stats object is: ' +
'{"browser": {"version": <percentage>, "anotherVersion"' +
': <percentage>, ...}, "anotherBrowser": {...}, ...}');
}
for ( var version in usage ) {
if ( usage[version] > popularity ) {
result.push(version);
}
}
return result;
}
},
countryStatistics: {

@@ -271,0 +319,0 @@ regexp: /^> (\d+\.?\d*)% in (\w\w)$/,

{
"name": "browserslist",
"version": "1.0.1",
"version": "1.1.0",
"description": "Get browsers versions that matches given criterias like in Autoprefixer",

@@ -16,15 +16,12 @@ "keywords": [

"dependencies": {
"caniuse-db": "^1.0.30000335"
"caniuse-db": "^1.0.30000384"
},
"bin": "./cli.js",
"devDependencies": {
"gulp-eslint": "1.0.0",
"gulp-mocha": "2.1.3",
"mocha": "2.3.3",
"chai": "3.3.0",
"gulp": "3.9.0"
"eslint": "1.10.3",
"ava": "0.9.1"
},
"scripts": {
"test": "gulp"
"test": "ava && eslint *.js test/*.js"
}
}

@@ -6,22 +6,13 @@ # Browserslist [![Build Status][ci-img]][ci]

You can select browsers by passing a string. This library will use Can I Use
data to return the appropriate list of all matching versions.
You can select browsers by passing a string. This library will use
Can I Use data to return list of all matching versions.
For example, query to select all browser versions that are the last version
of each major browser, or have a usage of over 10% in global usage statistics:
For example, the last version of each major browser and versions,
with a usage of over 10% in global usage statistics:
```js
browserslist('last 1 version, > 10%');
//=> ['and_chr 45', 'chrome 45', 'edge 12', 'firefox 41', 'ie 11', 'ie_mob 11',
// 'ios_saf 9', 'opera 32', 'safari 9']
//=> ['and_chr 47', 'chrome 47', 'edge 13', 'firefox 43',
// 'ie 11', 'ie_mob 11', 'ios_saf 9.0-9.2', 'opera 34', 'safari 9']
```
Browserslist will use browsers criterias from:
1. First argument.
2. `BROWSERSLIST` environment variable.
3. `browserslist` config file in current or parent directories.
4. If all methods will not give a result, Browserslist will use defaults:<br>
`> 1%, last 2 versions, Firefox ESR`.
<a href="https://evilmartians.com/?utm_source=browserslist">

@@ -37,2 +28,13 @@ <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">

Browserslist will use browsers criterias from:
1. First argument.
2. `BROWSERSLIST` environment variable.
3. `browserslist` config file in current or parent directories.
4. If all methods will not give a result, Browserslist will use defaults:
`> 1%, last 2 versions, Firefox ESR`.
Multiple criteria are combined as a boolean `OR`. A browser version must match
at least one of the criteria to be selected.
You can specify the versions by queries (case insensitive):

@@ -44,2 +46,3 @@

* `> 5% in US`: uses USA usage statistics. It accepts [two-letter country code].
* `> 5% in my stats`: uses [custom usage data].
* `ie 6-8`: selects an inclusive range of versions.

@@ -58,7 +61,7 @@ * `Firefox > 20`: versions of Firefox newer than 20.

Browserslist works with separated versions of browsers. To use all versions
of some browsers you can use for example `Firefox > 0`,
but it is bad practice.
Browserslist works with separated versions of browsers.
You should avoid queries like `Firefox > 0`.
[two-letter country code]: http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements
[custom usage data]: #custom-usage-data

@@ -88,3 +91,3 @@ ## Browsers

Browserslist’s config should be named `browserslist` and have browsers queries
split by a new line. You can write a comment after `#`:
split by a new line. Comments starts with `#` symbol:

@@ -99,5 +102,5 @@ ```yaml

Browserslist will check config in every directory in `config.path` path.
So, if tool with Browserslist process `app/styles/main.css`, you can put
config to root, `app/` or `app/styles`.
Browserslist will check config in every directory in `path`.
So, if tool process `app/styles/main.css`, you can put config to root,
`app/` or `app/styles`.

@@ -124,4 +127,54 @@ You can specify direct path to config by `config` option

* `BROWSERSLIST_STATS` with path to the custom usage data.
```sh
BROWSERSLIST_STATS=./config/usage_data.json gulp css
```
[environment variables]: https://en.wikipedia.org/wiki/Environment_variable
## Custom Usage Data
If you have a website, you can query against the usage statistics of your site:
1. Import your Google Analytics data into [Can I Use].
Press `Import…` button in Settings page.
2. Open browser DevTools on [caniuse.com] add paste this snippet into Console:
```js
var e=document.createElement('a');e.setAttribute('href', 'data:text/plain;charset=utf-8,'+encodeURIComponent(JSON.stringify(JSON.parse(localStorage['usage-data-by-id'])[localStorage['config-primary_usage']])));e.setAttribute('download','stats.json');document.body.appendChild(e);e.click();document.body.removeChild(e);}
```
3. Save data to file in your project.
4. Give it to Browserslist by `stats` option
or `BROWSERSLIST_STATS` environment variable:
```js
browserslist('> 5% in my stats', { stats: 'path/to/the/stats.json' });
```
Of course, you can generate usage statistics file by any other method.
Option `stats` accepts path to file or data itself:
```js
var custom = {
ie: {
6: 0.01,
7: 0.4,
8: 1.5
},
chrome: {
},
};
browserslist('> 5% in my stats', { stats: custom });
```
Note that you can query against your custom usage data while also querying
against global or regional data. For example, the query
`> 5% in my stats, > 1%, > 10% in US` is permitted.
[Can I Use]: http://caniuse.com/
## Usage

@@ -139,9 +192,9 @@

If a list is missing, Browserslist will look for a config file.
You can provide a `path` option (that can be a file) to find the config file
relatively to it.
Queries can be a string `"> 5%, last 1 version"`
or an array `['> 5%', 'last 1 version']`.
If a query is missing, Browserslist will look for a config file.
You can provide a `path` option (that can be a file) to find the config file
relatively to it.
For non-JS environment and debug purpose you can use CLI tool:

@@ -148,0 +201,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc