source: trip-planner-front/node_modules/caniuse-api/dist/index.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[6a3a178]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.getBrowserScope = exports.setBrowserScope = exports.getLatestStableBrowsers = exports.find = exports.isSupported = exports.getSupport = exports.features = undefined;
7
8var _lodash = require("lodash.memoize");
9
10var _lodash2 = _interopRequireDefault(_lodash);
11
12var _browserslist = require("browserslist");
13
14var _browserslist2 = _interopRequireDefault(_browserslist);
15
16var _caniuseLite = require("caniuse-lite");
17
18var _utils = require("./utils");
19
20function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22var featuresList = Object.keys(_caniuseLite.features);
23
24var browsers = void 0;
25function setBrowserScope(browserList) {
26 browsers = (0, _utils.cleanBrowsersList)(browserList);
27}
28
29function getBrowserScope() {
30 return browsers;
31}
32
33var parse = (0, _lodash2.default)(_utils.parseCaniuseData, function (feat, browsers) {
34 return feat.title + browsers;
35});
36
37function 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
49function 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
69function 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
84function getLatestStableBrowsers() {
85 return (0, _browserslist2.default)("last 1 version");
86}
87
88setBrowserScope();
89
90exports.features = featuresList;
91exports.getSupport = getSupport;
92exports.isSupported = isSupported;
93exports.find = find;
94exports.getLatestStableBrowsers = getLatestStableBrowsers;
95exports.setBrowserScope = setBrowserScope;
96exports.getBrowserScope = getBrowserScope;
Note: See TracBrowser for help on using the repository browser.