Last active
February 22, 2024 09:13
-
-
Save nemchik/08297ef04366ca9a6064d5f0c27e582a to your computer and use it in GitHub Desktop.
browser-update with browserslist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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