3 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5 var browserslist = require('browserslist');
7 var utils = require('./utils');
9 var Browsers = function () {
12 * Return all prefixes for default browser data
14 Browsers.prefixes = function prefixes() {
15 if (this.prefixesCache) {
16 return this.prefixesCache;
19 var data = require('caniuse-lite').agents;
21 this.prefixesCache = [];
22 for (var name in data) {
23 this.prefixesCache.push('-' + data[name].prefix + '-');
26 this.prefixesCache = utils.uniq(this.prefixesCache).sort(function (a, b) {
27 return b.length - a.length;
30 return this.prefixesCache;
34 * Check is value contain any possibe prefix
38 Browsers.withPrefix = function withPrefix(value) {
39 if (!this.prefixesRegexp) {
40 this.prefixesRegexp = new RegExp(this.prefixes().join('|'));
43 return this.prefixesRegexp.test(value);
46 function Browsers(data, requirements, options, stats) {
47 _classCallCheck(this, Browsers);
50 this.options = options || {};
52 this.selected = this.parse(requirements);
56 * Return browsers selected by requirements
60 Browsers.prototype.parse = function parse(requirements) {
61 return browserslist(requirements, {
63 path: this.options.from,
69 * Return prefix for selected browser
73 Browsers.prototype.prefix = function prefix(browser) {
74 var _browser$split = browser.split(' '),
75 name = _browser$split[0],
76 version = _browser$split[1];
78 var data = this.data[name];
80 var prefix = data.prefix_exceptions && data.prefix_exceptions[version];
84 return '-' + prefix + '-';
88 * Is browser is selected by requirements
92 Browsers.prototype.isSelected = function isSelected(browser) {
93 return this.selected.indexOf(browser) !== -1;
99 module.exports = Browsers;