How to use the browserslist function in browserslist

To help you get started, we’ve selected a few browserslist examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DestinyItemManager / DIM / src / browsercheck.js View on Github external
function getBrowserVersionFromUserAgent(agent) {
  var browserName = getBrowserName(agent);
  var version = (browserName === 'ios_saf'
    ? agent.os.version
    : agent.browser.version || agent.os.version || ''
  ).split('.');
  while (version.length > 0) {
    try {
      return browserslist(browserName + ' ' + version.join('.'))[0];
    } catch (e) {
      // Ignore unknown browser query error
    }
    version.pop();
  }
  return 'unknown';
}
github stsiarzhanau / webpack-react-redux-starter / tools / printBrowsersList.js View on Github external
// eslint-disable-next-line import/no-extraneous-dependencies
import browserslist from 'browserslist'

// prints to terminal list of browsers that matches browserlist config file
// eslint-disable-next-line no-console
console.log(browserslist())

// prints to terminal total users coverage for selected browsers
// eslint-disable-next-line no-console
console.log(`coverage: ${browserslist.coverage(browserslist())}%`)
github robjtede / alfred-caniuse / src / index.js View on Github external
.then(res => {
    // console.log(JSON.stringify(res))
    const match = exactMatch(alfy.input, res.data)

    if (match) {
      const supportTable = new SupportTable({
        featureId: match,
        db: res,
        browsersList: browserslist(browsersListConfig)
      })

      return alfy.output(supportTable.alfredItems)
    } else {
      const featureSelectionList = filterFeatures(alfy.input, res)
      return alfy.output(featureSelectionList)
    }
  })
  .catch(alfy.error)
github parcel-bundler / parcel / packages / transformers / babel / src / getBabelTargets.js View on Github external
browsers = browserslist;
      }
    }

    // Parse browser targets
    if (
      typeof browsers === 'object' &&
      browsers != null &&
      !Array.isArray(browsers)
    ) {
      let env = process.env.NODE_ENV || 'development';
      browsers = browsers[env] || browsers.defaults;
    }

    if (browsers) {
      targets.browsers = browserslist(browsers).sort();
    }
  }

  // Dont compile if we couldn't find any targets
  if (Object.keys(targets).length === 0) {
    return null;
  }

  return targets;
}
github Nyalab / caniuse-api / test / index.js View on Github external
test("browserscope tests", (t) => {
  const defaultBrowserslist = cleanBrowsersList()

  t.deepEqual(caniuse.getBrowserScope().sort(), defaultBrowserslist.sort(), "default browser scope is browserslists one")
  caniuse.setBrowserScope(browserslist("Firefox 4, Opera 12.1"))
  t.deepEqual(caniuse.getBrowserScope().sort(), ["firefox", "opera"].sort(), "browser scope update does really update")

  t.end()
})
github mozilla-frontend-infra / firefox-health-dashboard / src / status / chrome.js View on Github external
export async function getChromePopular() {
  const firefoxStatus = await fetchJson(firefoxBase);
  const chromeStatus = await fetchJson(base);
  const latest = browserslist('last 1 version').reduce((result, str) => {
    const [platform, version] = str.split(/\s+/);
    result[platform] = +version;
    return result;
  }, {});
  const queuedIds = [];
  const features = flow(
    filter(({ browsers }) => {
      return browsers.webdev && browsers.webdev.view.val <= 2;
    }),
    filter(({ browsers }) => {
      return (
        !/opposed/i.test(browsers.ff.view.text) &&
        !/pursuing|deprecat|removed/i.test(browsers.chrome.status.text)
      );
    }),
    map((chromestatus) => {
github Nyalab / caniuse-api / src / utils.js View on Github external
export function cleanBrowsersList(browserList) {
  return uniq(browserslist(browserList).map((browser) => browser.split(" ")[0]))
}
github xeroxinteractive / browserslist-browserstack / source / index.ts View on Github external
export default async function getCapabilities(
  userOptions?: Options
): Promise {
  const options: Options = {
    ...defaultOptions,
    ...userOptions,
  };
  if (options.username && options.accessKey) {
    const allCapabilities = await getAllCapabilities(
      options.username,
      options.accessKey
    );
    const allSupportedBrowsers = browserslist(
      options.browserslist?.queries,
      options.browserslist?.opts
    ).map(
      (browserString: string): Browser => {
        const [browser, browser_version] = browserString.split(' ');
        return {
          browser,
          browser_version:
            !browser_version.includes('.') &&
            !isNaN(parseFloat(browser_version))
              ? `${browser_version}.0`
              : browser_version,
        };
      }
    );
    const capabilites = filterCapabilities(
github Nyalab / caniuse-api / src / index.js View on Github external
function getLatestStableBrowsers() {
  return browserslist("last 1 version")
}
github amilajack / eslint-plugin-compat / src / Versioning.js View on Github external
export default function DetermineTargetsFromConfig(
  configPath: string,
  config?: BrowserListConfig
): Array {
  const browserslistOpts = { path: configPath };

  if (Array.isArray(config) || typeof config === 'string') {
    return browserslist(config, browserslistOpts);
  }

  if (config && typeof config === 'object') {
    return browserslist(
      [...(config.production || []), ...(config.development || [])],
      browserslistOpts
    );
  }

  return browserslist(undefined, browserslistOpts);
}