Last active
November 15, 2024 23:23
-
-
Save bosconian-dynamics/234900c85f25efe7bf3447391fc98a35 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 {getAppropriateEcmaVersionForBrowserslist} = require('browserslist-generator'); | |
const WORDPRESS_BROWSERLIST_URL = 'https://raw.githubusercontent.com/WordPress/gutenberg/refs/heads/trunk/packages/browserslist-config/index.js'; | |
const BROWSERSLIST_URL_BASE = 'https://browserl.ist/?q='; | |
async function getWordPressBrowserlistQueries() { | |
const res = await fetch(WORDPRESS_BROWSERLIST_URL); | |
const text = await res.text(); | |
const queries = [...text.matchAll(/^\s*'([^']+)',?\s*$/gm)].map(([, query]) => query); | |
return queries; | |
} | |
function getBrowserslistUrl(queries = []) { | |
return BROWSERSLIST_URL_BASE + queries | |
.map( | |
query => encodeURIComponent(query) | |
) | |
.join(',%0A') | |
.replaceAll('%20', '+'); | |
} | |
getWordPressBrowserlistQueries().then(queries => { | |
console.log('WordPress Browserlist Info'); | |
console.log('=========================='); | |
console.log('Browserlist:', WORDPRESS_BROWSERLIST_URL); | |
console.log('Date:', new Date().toISOString()); | |
console.log('Queries:'); | |
queries.forEach(query => console.log(' ', query)); | |
console.log('ECMAScript Compatibility:', getAppropriateEcmaVersionForBrowserslist(queries, {syntaxOnly: true})); | |
console.log('Audience Coverage: see', getBrowserslistUrl(queries)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment