info.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. (function() {
  2. var browserslist, capitalize, names, prefix;
  3. browserslist = require('browserslist');
  4. capitalize = function(str) {
  5. return str.slice(0, 1).toUpperCase() + str.slice(1);
  6. };
  7. names = {
  8. ie: 'IE',
  9. ie_mob: 'IE Mobile',
  10. ios_saf: 'iOS',
  11. op_mini: 'Opera Mini',
  12. op_mob: 'Opera Mobile',
  13. and_chr: 'Chrome for Android',
  14. and_ff: 'Firefox for Android',
  15. and_uc: 'UC for Android'
  16. };
  17. prefix = function(name, prefixes) {
  18. var out;
  19. out = ' ' + name + ': ';
  20. out += prefixes.map(function(i) {
  21. return i.replace(/^-(.*)-$/g, '$1');
  22. }).join(', ');
  23. out += "\n";
  24. return out;
  25. };
  26. module.exports = function(prefixes) {
  27. var atrules, browser, coverage, data, j, k, l, len, len1, len2, list, name, out, props, ref, ref1, ref2, ref3, ref4, ref5, round, selector, selectors, string, value, values, version, versions;
  28. if (prefixes.browsers.selected.length === 0) {
  29. return "No browsers selected";
  30. }
  31. versions = [];
  32. ref = prefixes.browsers.selected;
  33. for (j = 0, len = ref.length; j < len; j++) {
  34. browser = ref[j];
  35. ref1 = browser.split(' '), name = ref1[0], version = ref1[1];
  36. name = names[name] || capitalize(name);
  37. if (versions[name]) {
  38. versions[name].push(version);
  39. } else {
  40. versions[name] = [version];
  41. }
  42. }
  43. out = "Browsers:\n";
  44. for (browser in versions) {
  45. list = versions[browser];
  46. list = list.sort(function(a, b) {
  47. return parseFloat(b) - parseFloat(a);
  48. });
  49. out += ' ' + browser + ': ' + list.join(', ') + "\n";
  50. }
  51. coverage = browserslist.coverage(prefixes.browsers.selected);
  52. round = Math.round(coverage * 100) / 100.0;
  53. out += "\nThese browsers account for " + round + "% of all users globally\n";
  54. atrules = '';
  55. ref2 = prefixes.add;
  56. for (name in ref2) {
  57. data = ref2[name];
  58. if (name[0] === '@' && data.prefixes) {
  59. atrules += prefix(name, data.prefixes);
  60. }
  61. }
  62. if (atrules !== '') {
  63. out += "\nAt-Rules:\n" + atrules;
  64. }
  65. selectors = '';
  66. ref3 = prefixes.add.selectors;
  67. for (k = 0, len1 = ref3.length; k < len1; k++) {
  68. selector = ref3[k];
  69. if (selector.prefixes) {
  70. selectors += prefix(selector.name, selector.prefixes);
  71. }
  72. }
  73. if (selectors !== '') {
  74. out += "\nSelectors:\n" + selectors;
  75. }
  76. values = '';
  77. props = '';
  78. ref4 = prefixes.add;
  79. for (name in ref4) {
  80. data = ref4[name];
  81. if (name[0] !== '@' && data.prefixes) {
  82. props += prefix(name, data.prefixes);
  83. }
  84. if (!data.values) {
  85. continue;
  86. }
  87. ref5 = data.values;
  88. for (l = 0, len2 = ref5.length; l < len2; l++) {
  89. value = ref5[l];
  90. string = prefix(value.name, value.prefixes);
  91. if (values.indexOf(string) === -1) {
  92. values += string;
  93. }
  94. }
  95. }
  96. if (props !== '') {
  97. out += "\nProperties:\n" + props;
  98. }
  99. if (values !== '') {
  100. out += "\nValues:\n" + values;
  101. }
  102. if (atrules === '' && selectors === '' && props === '' && values === '') {
  103. out += '\nAwesome! Your browsers don\'t require any vendor prefixes.' + '\nNow you can remove Autoprefixer from build steps.';
  104. }
  105. return out;
  106. };
  107. }).call(this);