Created
January 25, 2019 19:00
-
-
Save fohlin/24e1684cd0cf746d28df056c4908f497 to your computer and use it in GitHub Desktop.
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
const caniuse = require('caniuse-api'); | |
const featureSupport = {}; | |
const features = [ | |
'classlist', | |
'element-closest', | |
'es6-module', | |
'es6-class', | |
'fetch', | |
'promises', | |
'requestanimationframe', | |
'srcset', | |
'urlsearchparams', | |
]; | |
const matches = {}; | |
for (const feature of features) { | |
let support = caniuse.getSupport(feature); | |
featureSupport[feature] = {}; | |
for (const browser of Object.keys(support)) { | |
if (support[browser].y) { | |
featureSupport[feature][browser] = support[browser].y; | |
matches[browser] = !!matches[browser] ? (matches[browser] + 1) : 1; | |
} | |
} | |
} | |
const matchesRequired = Object.keys(featureSupport).length; | |
const supportsAll = Object.keys(matches).map(browser => { | |
if (matches[browser] === matchesRequired) { | |
return browser; | |
} else { | |
return null; | |
} | |
}).filter(val => { | |
return !!val; | |
}); | |
console.info(supportsAll); | |
const browserslist = {}; | |
for (const featName of Object.keys(featureSupport)) { | |
let feat = featureSupport[featName]; | |
for (const browser of supportsAll) { | |
browserslist[browser] = feat[browser] > browserslist[browser] ? feat[browser] : browserslist[browser] || 0; | |
} | |
} | |
console.info(browserslist); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment