utils.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.contains = contains;
  6. exports.parseCaniuseData = parseCaniuseData;
  7. exports.cleanBrowsersList = cleanBrowsersList;
  8. var _lodash = require("lodash.uniq");
  9. var _lodash2 = _interopRequireDefault(_lodash);
  10. var _browserslist = require("browserslist");
  11. var _browserslist2 = _interopRequireDefault(_browserslist);
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. function contains(str, substr) {
  14. return !!~str.indexOf(substr);
  15. }
  16. function parseCaniuseData(feature, browsers) {
  17. var support = {};
  18. var letters;
  19. var letter;
  20. browsers.forEach(function (browser) {
  21. support[browser] = {};
  22. for (var info in feature.stats[browser]) {
  23. letters = feature.stats[browser][info].replace(/#\d+/, "").trim().split(" ");
  24. info = parseFloat(info.split("-")[0]); //if info is a range, take the left
  25. if (isNaN(info)) continue;
  26. for (var i = 0; i < letters.length; i++) {
  27. letter = letters[i];
  28. if (letter === "d") {
  29. // skip this letter, we don't support it yet
  30. continue;
  31. } else if (letter === "y") {
  32. // min support asked, need to find the min value
  33. if (typeof support[browser][letter] === "undefined" || info < support[browser][letter]) {
  34. support[browser][letter] = info;
  35. }
  36. } else {
  37. // any other support, need to find the max value
  38. if (typeof support[browser][letter] === "undefined" || info > support[browser][letter]) {
  39. support[browser][letter] = info;
  40. }
  41. }
  42. }
  43. }
  44. });
  45. return support;
  46. }
  47. function cleanBrowsersList(browserList) {
  48. return (0, _lodash2.default)((0, _browserslist2.default)(browserList).map(function (browser) {
  49. return browser.split(" ")[0];
  50. }));
  51. }