How to use the browserslist.data 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 swissquote / crafty / packages / crafty / src / defaultConfiguration.js View on Github external
function getDefaultBrowsers() {
  // There seems to be a bug with browserslist's data
  for (var name in browserslist.data) {
    if (browserslist.data.hasOwnProperty(name)) {
      browserslist.data[name].released.sort((a, b) => Number(a) - Number(b));
    }
  }

  const config = browserslist.loadConfig({ path: path.resolve(".") });
  return config ? config : defaultBrowsers;
}
github open-wc / open-wc / packages / es-dev-server / src / utils / user-agent-compat.js View on Github external
function normalizeSamsungVersion(browser, version) {
  try {
    browserslist(`${browser} ${version}`);
    // browserslist didn't throw, return the valid version
    return version;
  } catch (error) {
    // we gave an invalid version to browserslist, so we try to
    // find the nearest matching major version for samsung browser
    const validVersions = [
      ...Object.keys(browserslist.versionAliases.samsung),
      ...browserslist.data.samsung.versions,
    ];

    return validVersions.find(validVersion => validVersion[0] === version[0]);
  }
}
github babel / babel / packages / babel-preset-env / src / targets-parser.js View on Github external
// @flow

import browserslist from "browserslist";
import invariant from "invariant";
import semver from "semver";
import findSuggestion from "levenary";
import { semverify, isUnreleasedVersion, getLowestUnreleased } from "./utils";
import browserModulesData from "../data/built-in-modules.json";
import { TargetNames } from "./options";
import type { Targets } from "./types";

const browserslistDefaults = browserslist.defaults;

const validBrowserslistTargets = [
  ...Object.keys(browserslist.data),
  ...Object.keys(browserslist.aliases),
];

const objectToBrowserslist = (object: Targets): Array => {
  return Object.keys(object).reduce((list, targetName) => {
    if (validBrowserslistTargets.indexOf(targetName) >= 0) {
      const targetVersion = object[targetName];
      return list.concat(`${targetName} ${targetVersion}`);
    }
    return list;
  }, []);
};

const validateTargetNames = (targets: Targets): void => {
  const validTargets = Object.keys(TargetNames);
  for (const target in targets) {
github Nyalab / caniuse-api / test / index.js View on Github external
test("isSupported test with browsers caniuse doesn't know", (t) => {
  browserslist.data.notabrowser = {
    name: 'notabrowser',
    versions: ['1'],
    released: ['1']
  };
  browserslist.versionAliases.notabrowser = {}

  t.notOk(caniuse.isSupported("border-radius", "notabrowser 1"), "do not throw on non existing data")

  delete browserslist.data.notabrowser
  delete browserslist.versionAliases.notabrowser
  t.end()
})
github Nyalab / caniuse-api / test / index.js View on Github external
test("isSupported test with browsers caniuse doesn't know", (t) => {
  browserslist.data.notabrowser = {
    name: 'notabrowser',
    versions: ['1'],
    released: ['1']
  };
  browserslist.versionAliases.notabrowser = {}

  t.notOk(caniuse.isSupported("border-radius", "notabrowser 1"), "do not throw on non existing data")

  delete browserslist.data.notabrowser
  delete browserslist.versionAliases.notabrowser
  t.end()
})
github webextension-toolbox / webextension-toolbox / src / preset.js View on Github external
function latest (vendor) {
  const { versions } = browserslist.data[vendor]
  return versions[versions.length - 1]
}
github babel / babel-preset-env / src / normalize-options.js View on Github external
const unknownOpts = opts.filter(opt => !validIncludesAndExcludes.has(opt));

  invariant(
    unknownOpts.length === 0,
    `Invalid Option: The plugins/built-ins '${unknownOpts.join(
      ", ",
    )}' passed to the '${type}' option are not
    valid. Please check data/[plugin-features|built-in-features].js in babel-preset-env`,
  );

  return opts;
};

const validBrowserslistTargets = [
  ...Object.keys(browserslist.data),
  ...Object.keys(browserslist.aliases),
];

export const normalizePluginName = (plugin: string): string =>
  plugin.replace(/^babel-plugin-/, "");

export const normalizePluginNames = (plugins: Array): Array =>
  plugins.map(normalizePluginName);

export const checkDuplicateIncludeExcludes = (
  include: Array = [],
  exclude: Array = [],
): void => {
  const duplicates: Array = include.filter(
    opt => exclude.indexOf(opt) >= 0,
  );
github iamvdo / pleeease / lib / browsers.js View on Github external
function Browsers (options) {

  var browserslist = require('browserslist');
  var cdbRem       = require('caniuse-db/features-json/rem');
  var cdbOpacity   = require('caniuse-db/features-json/css-opacity');
  var cdbPseudo    = require('caniuse-db/features-json/css-gencontent');

  options = options || {};
  options.browsers = options.browsers || browserslist.defaults;

  this.selected = browserslist(options.browsers);
  this.browsers = browserslist.data;

  var features = {};

  this.getBrowsersByFeature(cdbRem, function(browsers) {
    features.rem = browsers;
  });
  this.getBrowsersByFeature(cdbOpacity, /^(a|n)/, function(browsers) {
    features.opacity = browsers;
  });
  this.getBrowsersByFeature(cdbPseudo, function(browsers) {
    features.pseudoElements = browsers;
  });
  this.features = features;

}