info.js
4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"use strict";
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
var browserslist = require('browserslist');
function capitalize(str) {
return str.slice(0, 1).toUpperCase() + str.slice(1);
}
var NAMES = {
ie: 'IE',
ie_mob: 'IE Mobile',
ios_saf: 'iOS',
op_mini: 'Opera Mini',
op_mob: 'Opera Mobile',
and_chr: 'Chrome for Android',
and_ff: 'Firefox for Android',
and_uc: 'UC for Android'
};
function prefix(name, prefixes, note) {
var out = " " + name;
if (note) out += ' *';
out += ': ';
out += prefixes.map(function (i) {
return i.replace(/^-(.*)-$/g, '$1');
}).join(', ');
out += '\n';
return out;
}
module.exports = function (prefixes) {
if (prefixes.browsers.selected.length === 0) {
return 'No browsers selected';
}
var versions = {};
for (var _iterator = _createForOfIteratorHelperLoose(prefixes.browsers.selected), _step; !(_step = _iterator()).done;) {
var _browser = _step.value;
var parts = _browser.split(' ');
var _name2 = parts[0];
var version = parts[1];
_name2 = NAMES[_name2] || capitalize(_name2);
if (versions[_name2]) {
versions[_name2].push(version);
} else {
versions[_name2] = [version];
}
}
var out = 'Browsers:\n';
for (var browser in versions) {
var list = versions[browser];
list = list.sort(function (a, b) {
return parseFloat(b) - parseFloat(a);
});
out += " " + browser + ": " + list.join(', ') + "\n";
}
var coverage = browserslist.coverage(prefixes.browsers.selected);
var round = Math.round(coverage * 100) / 100.0;
out += "\nThese browsers account for " + round + "% of all users globally\n";
var atrules = [];
for (var name in prefixes.add) {
var data = prefixes.add[name];
if (name[0] === '@' && data.prefixes) {
atrules.push(prefix(name, data.prefixes));
}
}
if (atrules.length > 0) {
out += "\nAt-Rules:\n" + atrules.sort().join('');
}
var selectors = [];
for (var _iterator2 = _createForOfIteratorHelperLoose(prefixes.add.selectors), _step2; !(_step2 = _iterator2()).done;) {
var selector = _step2.value;
if (selector.prefixes) {
selectors.push(prefix(selector.name, selector.prefixes));
}
}
if (selectors.length > 0) {
out += "\nSelectors:\n" + selectors.sort().join('');
}
var values = [];
var props = [];
var hadGrid = false;
for (var _name in prefixes.add) {
var _data = prefixes.add[_name];
if (_name[0] !== '@' && _data.prefixes) {
var grid = _name.indexOf('grid-') === 0;
if (grid) hadGrid = true;
props.push(prefix(_name, _data.prefixes, grid));
}
if (!Array.isArray(_data.values)) {
continue;
}
for (var _iterator3 = _createForOfIteratorHelperLoose(_data.values), _step3; !(_step3 = _iterator3()).done;) {
var value = _step3.value;
var _grid = value.name.includes('grid');
if (_grid) hadGrid = true;
var string = prefix(value.name, value.prefixes, _grid);
if (!values.includes(string)) {
values.push(string);
}
}
}
if (props.length > 0) {
out += "\nProperties:\n" + props.sort().join('');
}
if (values.length > 0) {
out += "\nValues:\n" + values.sort().join('');
}
if (hadGrid) {
out += '\n* - Prefixes will be added only on grid: true option.\n';
}
if (!atrules.length && !selectors.length && !props.length && !values.length) {
out += '\nAwesome! Your browsers don\'t require any vendor prefixes.' + '\nNow you can remove Autoprefixer from build steps.';
}
return out;
};