.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / autoprefixer / lib / browsers.js
1 'use strict';
2
3 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
5 var browserslist = require('browserslist');
6
7 var utils = require('./utils');
8
9 var Browsers = function () {
10
11     /**
12      * Return all prefixes for default browser data
13      */
14     Browsers.prefixes = function prefixes() {
15         if (this.prefixesCache) {
16             return this.prefixesCache;
17         }
18
19         var data = require('caniuse-lite').agents;
20
21         this.prefixesCache = [];
22         for (var name in data) {
23             this.prefixesCache.push('-' + data[name].prefix + '-');
24         }
25
26         this.prefixesCache = utils.uniq(this.prefixesCache).sort(function (a, b) {
27             return b.length - a.length;
28         });
29
30         return this.prefixesCache;
31     };
32
33     /**
34      * Check is value contain any possibe prefix
35      */
36
37
38     Browsers.withPrefix = function withPrefix(value) {
39         if (!this.prefixesRegexp) {
40             this.prefixesRegexp = new RegExp(this.prefixes().join('|'));
41         }
42
43         return this.prefixesRegexp.test(value);
44     };
45
46     function Browsers(data, requirements, options, stats) {
47         _classCallCheck(this, Browsers);
48
49         this.data = data;
50         this.options = options || {};
51         this.stats = stats;
52         this.selected = this.parse(requirements);
53     }
54
55     /**
56      * Return browsers selected by requirements
57      */
58
59
60     Browsers.prototype.parse = function parse(requirements) {
61         return browserslist(requirements, {
62             stats: this.stats,
63             path: this.options.from,
64             env: this.options.env
65         });
66     };
67
68     /**
69      * Return prefix for selected browser
70      */
71
72
73     Browsers.prototype.prefix = function prefix(browser) {
74         var _browser$split = browser.split(' '),
75             name = _browser$split[0],
76             version = _browser$split[1];
77
78         var data = this.data[name];
79
80         var prefix = data.prefix_exceptions && data.prefix_exceptions[version];
81         if (!prefix) {
82             prefix = data.prefix;
83         }
84         return '-' + prefix + '-';
85     };
86
87     /**
88      * Is browser is selected by requirements
89      */
90
91
92     Browsers.prototype.isSelected = function isSelected(browser) {
93         return this.selected.indexOf(browser) !== -1;
94     };
95
96     return Browsers;
97 }();
98
99 module.exports = Browsers;