UNPKG

4.3 kBJavaScriptView Raw
1"use strict";
2
3var browserslist = require('browserslist');
4
5function capitalize(str) {
6 return str.slice(0, 1).toUpperCase() + str.slice(1);
7}
8
9var NAMES = {
10 ie: 'IE',
11 ie_mob: 'IE Mobile',
12 ios_saf: 'iOS',
13 op_mini: 'Opera Mini',
14 op_mob: 'Opera Mobile',
15 and_chr: 'Chrome for Android',
16 and_ff: 'Firefox for Android',
17 and_uc: 'UC for Android'
18};
19
20function prefix(name, prefixes, note) {
21 var out = " " + name;
22 if (note) out += ' *';
23 out += ': ';
24 out += prefixes.map(function (i) {
25 return i.replace(/^-(.*)-$/g, '$1');
26 }).join(', ');
27 out += '\n';
28 return out;
29}
30
31module.exports = function (prefixes) {
32 if (prefixes.browsers.selected.length === 0) {
33 return 'No browsers selected';
34 }
35
36 var versions = {};
37
38 for (var _iterator = prefixes.browsers.selected, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
39 var _ref;
40
41 if (_isArray) {
42 if (_i >= _iterator.length) break;
43 _ref = _iterator[_i++];
44 } else {
45 _i = _iterator.next();
46 if (_i.done) break;
47 _ref = _i.value;
48 }
49
50 var _browser = _ref;
51
52 var parts = _browser.split(' ');
53
54 var _name2 = parts[0];
55 var version = parts[1];
56 _name2 = NAMES[_name2] || capitalize(_name2);
57
58 if (versions[_name2]) {
59 versions[_name2].push(version);
60 } else {
61 versions[_name2] = [version];
62 }
63 }
64
65 var out = 'Browsers:\n';
66
67 for (var browser in versions) {
68 var list = versions[browser];
69 list = list.sort(function (a, b) {
70 return parseFloat(b) - parseFloat(a);
71 });
72 out += " " + browser + ": " + list.join(', ') + "\n";
73 }
74
75 var coverage = browserslist.coverage(prefixes.browsers.selected);
76 var round = Math.round(coverage * 100) / 100.0;
77 out += "\nThese browsers account for " + round + "% of all users globally\n";
78 var atrules = [];
79
80 for (var name in prefixes.add) {
81 var data = prefixes.add[name];
82
83 if (name[0] === '@' && data.prefixes) {
84 atrules.push(prefix(name, data.prefixes));
85 }
86 }
87
88 if (atrules.length > 0) {
89 out += "\nAt-Rules:\n" + atrules.sort().join('');
90 }
91
92 var selectors = [];
93
94 for (var _iterator2 = prefixes.add.selectors, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
95 var _ref2;
96
97 if (_isArray2) {
98 if (_i2 >= _iterator2.length) break;
99 _ref2 = _iterator2[_i2++];
100 } else {
101 _i2 = _iterator2.next();
102 if (_i2.done) break;
103 _ref2 = _i2.value;
104 }
105
106 var selector = _ref2;
107
108 if (selector.prefixes) {
109 selectors.push(prefix(selector.name, selector.prefixes));
110 }
111 }
112
113 if (selectors.length > 0) {
114 out += "\nSelectors:\n" + selectors.sort().join('');
115 }
116
117 var values = [];
118 var props = [];
119 var hadGrid = false;
120
121 for (var _name in prefixes.add) {
122 var _data = prefixes.add[_name];
123
124 if (_name[0] !== '@' && _data.prefixes) {
125 var grid = _name.indexOf('grid-') === 0;
126 if (grid) hadGrid = true;
127 props.push(prefix(_name, _data.prefixes, grid));
128 }
129
130 if (!Array.isArray(_data.values)) {
131 continue;
132 }
133
134 for (var _iterator3 = _data.values, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
135 var _ref3;
136
137 if (_isArray3) {
138 if (_i3 >= _iterator3.length) break;
139 _ref3 = _iterator3[_i3++];
140 } else {
141 _i3 = _iterator3.next();
142 if (_i3.done) break;
143 _ref3 = _i3.value;
144 }
145
146 var value = _ref3;
147
148 var _grid = value.name.includes('grid');
149
150 if (_grid) hadGrid = true;
151 var string = prefix(value.name, value.prefixes, _grid);
152
153 if (!values.includes(string)) {
154 values.push(string);
155 }
156 }
157 }
158
159 if (props.length > 0) {
160 out += "\nProperties:\n" + props.sort().join('');
161 }
162
163 if (values.length > 0) {
164 out += "\nValues:\n" + values.sort().join('');
165 }
166
167 if (hadGrid) {
168 out += '\n* - Prefixes will be added only on grid: true option.\n';
169 }
170
171 if (!atrules.length && !selectors.length && !props.length && !values.length) {
172 out += '\nAwesome! Your browsers don\'t require any vendor prefixes.' + '\nNow you can remove Autoprefixer from build steps.';
173 }
174
175 return out;
176};
\No newline at end of file