Skip to content

Instantly share code, notes, and snippets.

@nemchik
Last active February 22, 2024 09:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemchik/08297ef04366ca9a6064d5f0c27e582a to your computer and use it in GitHub Desktop.
Save nemchik/08297ef04366ca9a6064d5f0c27e582a to your computer and use it in GitHub Desktop.
browser-update with browserslist
{
uc: '12.12',
a: '100',
c: '100',
e: '100',
f: '91',
i: '11',
ios: '12.2',
o_a: '64',
o: '82',
s: '14.1',
samsung: '15.0'
}
{
uc: '12.12',
c: '97',
e: '98',
f: '97',
ios: '12.2',
s: '14.1',
samsung: '16.0'
}
{
a: '100',
c: '100',
e: '100',
f: '100',
ios: '10.3',
o_a: '64',
o: '48',
s: '10.1',
samsung: '10.1'
}
var browserslist = require("browserslist");
function getRequiredFromList(queries, opts) {
var required = {},
browserMap = [
{ bl: "edge", bu: "e" },
{ bl: "ie", bu: "i" },
{ bl: "chrome", bu: "c" },
{ bl: "firefox", bu: "f" },
{ bl: "opera", bu: "o" },
{ bl: "op_mob", bu: "o_a" },
{ bl: "safari", bu: "s" },
//{ bl: "yandex", bu: "y" }, // not supported by browserslist
//{ bl: "vivaldi", bu: "v" }, // not supported by browserslist
{ bl: "and_uc", bu: "uc" },
{ bl: "ios_saf", bu: "ios" },
{ bl: "android", bu: "a" },
{ bl: "samsung", bu: "samsung" },
];
return (
browserslist(queries, opts).forEach(function (listEntry) {
var entrySplit = listEntry.split(" "),
name = entrySplit[0],
version = parseFloat(entrySplit[1].split('-')[0]),
mapMatch = browserMap.find(function (mapEntry) {
return mapEntry.bl === name;
});
mapMatch &&
(!required[mapMatch.bu] || required[mapMatch.bu] > version) &&
(required[mapMatch.bu] = version);
}),
required
);
}
console.log(getRequiredFromList("defaults"));
console.log(getRequiredFromList("> 0.5%, not IE 11"));
console.log(getRequiredFromList("supports es6-module"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment