1 | "use strict";
|
2 |
|
3 | var browserslist = require('browserslist');
|
4 |
|
5 | var agents = require('caniuse-lite').agents;
|
6 |
|
7 | var utils = require('./utils');
|
8 |
|
9 | var Browsers = function () {
|
10 | |
11 |
|
12 |
|
13 | Browsers.prefixes = function prefixes() {
|
14 | if (this.prefixesCache) {
|
15 | return this.prefixesCache;
|
16 | }
|
17 |
|
18 | this.prefixesCache = [];
|
19 |
|
20 | for (var name in agents) {
|
21 | this.prefixesCache.push("-" + agents[name].prefix + "-");
|
22 | }
|
23 |
|
24 | this.prefixesCache = utils.uniq(this.prefixesCache).sort(function (a, b) {
|
25 | return b.length - a.length;
|
26 | });
|
27 | return this.prefixesCache;
|
28 | }
|
29 | |
30 |
|
31 |
|
32 | ;
|
33 |
|
34 | Browsers.withPrefix = function withPrefix(value) {
|
35 | if (!this.prefixesRegexp) {
|
36 | this.prefixesRegexp = new RegExp(this.prefixes().join('|'));
|
37 | }
|
38 |
|
39 | return this.prefixesRegexp.test(value);
|
40 | };
|
41 |
|
42 | function Browsers(data, requirements, options, browserslistOpts) {
|
43 | this.data = data;
|
44 | this.options = options || {};
|
45 | this.browserslistOpts = browserslistOpts || {};
|
46 | this.selected = this.parse(requirements);
|
47 | }
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | var _proto = Browsers.prototype;
|
54 |
|
55 | _proto.parse = function parse(requirements) {
|
56 | var opts = {};
|
57 |
|
58 | for (var i in this.browserslistOpts) {
|
59 | opts[i] = this.browserslistOpts[i];
|
60 | }
|
61 |
|
62 | opts.path = this.options.from;
|
63 | opts.env = this.options.env;
|
64 | return browserslist(requirements, opts);
|
65 | }
|
66 | |
67 |
|
68 |
|
69 | ;
|
70 |
|
71 | _proto.prefix = function prefix(browser) {
|
72 | var _browser$split = browser.split(' '),
|
73 | name = _browser$split[0],
|
74 | version = _browser$split[1];
|
75 |
|
76 | var data = this.data[name];
|
77 | var prefix = data.prefix_exceptions && data.prefix_exceptions[version];
|
78 |
|
79 | if (!prefix) {
|
80 | prefix = data.prefix;
|
81 | }
|
82 |
|
83 | return "-" + prefix + "-";
|
84 | }
|
85 | |
86 |
|
87 |
|
88 | ;
|
89 |
|
90 | _proto.isSelected = function isSelected(browser) {
|
91 | return this.selected.includes(browser);
|
92 | };
|
93 |
|
94 | return Browsers;
|
95 | }();
|
96 |
|
97 | module.exports = Browsers; |
\ | No newline at end of file |