[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.getBrowserScope = exports.setBrowserScope = exports.getLatestStableBrowsers = exports.find = exports.isSupported = exports.getSupport = exports.features = undefined;
|
---|
| 7 |
|
---|
| 8 | var _lodash = require("lodash.memoize");
|
---|
| 9 |
|
---|
| 10 | var _lodash2 = _interopRequireDefault(_lodash);
|
---|
| 11 |
|
---|
| 12 | var _browserslist = require("browserslist");
|
---|
| 13 |
|
---|
| 14 | var _browserslist2 = _interopRequireDefault(_browserslist);
|
---|
| 15 |
|
---|
| 16 | var _caniuseLite = require("caniuse-lite");
|
---|
| 17 |
|
---|
| 18 | var _utils = require("./utils");
|
---|
| 19 |
|
---|
| 20 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 21 |
|
---|
| 22 | var featuresList = Object.keys(_caniuseLite.features);
|
---|
| 23 |
|
---|
| 24 | var browsers = void 0;
|
---|
| 25 | function setBrowserScope(browserList) {
|
---|
| 26 | browsers = (0, _utils.cleanBrowsersList)(browserList);
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | function getBrowserScope() {
|
---|
| 30 | return browsers;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | var parse = (0, _lodash2.default)(_utils.parseCaniuseData, function (feat, browsers) {
|
---|
| 34 | return feat.title + browsers;
|
---|
| 35 | });
|
---|
| 36 |
|
---|
| 37 | function getSupport(query) {
|
---|
| 38 | var feature = void 0;
|
---|
| 39 | try {
|
---|
| 40 | feature = (0, _caniuseLite.feature)(_caniuseLite.features[query]);
|
---|
| 41 | } catch (e) {
|
---|
| 42 | var res = find(query);
|
---|
| 43 | if (res.length === 1) return getSupport(res[0]);
|
---|
| 44 | throw new ReferenceError("Please provide a proper feature name. Cannot find " + query);
|
---|
| 45 | }
|
---|
| 46 | return parse(feature, browsers);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | function isSupported(feature, browsers) {
|
---|
| 50 | var data = void 0;
|
---|
| 51 | try {
|
---|
| 52 | data = (0, _caniuseLite.feature)(_caniuseLite.features[feature]);
|
---|
| 53 | } catch (e) {
|
---|
| 54 | var res = find(feature);
|
---|
| 55 | if (res.length === 1) {
|
---|
| 56 | data = _caniuseLite.features[res[0]];
|
---|
| 57 | } else {
|
---|
| 58 | throw new ReferenceError("Please provide a proper feature name. Cannot find " + feature);
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | return (0, _browserslist2.default)(browsers, { ignoreUnknownVersions: true }).map(function (browser) {
|
---|
| 63 | return browser.split(" ");
|
---|
| 64 | }).every(function (browser) {
|
---|
| 65 | return data.stats[browser[0]] && data.stats[browser[0]][browser[1]] === "y";
|
---|
| 66 | });
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | function find(query) {
|
---|
| 70 | if (typeof query !== "string") {
|
---|
| 71 | throw new TypeError("The `query` parameter should be a string.");
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | if (~featuresList.indexOf(query)) {
|
---|
| 75 | // exact match
|
---|
| 76 | return query;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | return featuresList.filter(function (file) {
|
---|
| 80 | return (0, _utils.contains)(file, query);
|
---|
| 81 | });
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | function getLatestStableBrowsers() {
|
---|
| 85 | return (0, _browserslist2.default)("last 1 version");
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | setBrowserScope();
|
---|
| 89 |
|
---|
| 90 | exports.features = featuresList;
|
---|
| 91 | exports.getSupport = getSupport;
|
---|
| 92 | exports.isSupported = isSupported;
|
---|
| 93 | exports.find = find;
|
---|
| 94 | exports.getLatestStableBrowsers = getLatestStableBrowsers;
|
---|
| 95 | exports.setBrowserScope = setBrowserScope;
|
---|
| 96 | exports.getBrowserScope = getBrowserScope; |
---|