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