Skip to content

Commit 4e27448

Browse files
committed
transpiling and ie11 support
1 parent b1234ea commit 4e27448

10 files changed

+337
-446
lines changed

babel.config.js

-17
This file was deleted.

babel.config.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"ie": "11"
8+
}
9+
}
10+
]
11+
],
12+
"env": {
13+
"production": {
14+
"plugins": [
15+
[
16+
"remove-import-export",
17+
{
18+
"removeImport": true,
19+
"removeExport": true,
20+
"removeExportDefault": true,
21+
"preseveNamedDeclaration": false
22+
}
23+
]
24+
]
25+
}
26+
}
27+
}

dist/index.js

+87-97
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,97 @@
11
"use strict";
22

3-
Object.defineProperty(exports, "__esModule", {
4-
value: true
5-
});
6-
exports.default = exports.supportedBrowsers = void 0;
3+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
74

8-
require("core-js/modules/es6.regexp.match.js");
5+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
96

10-
require("core-js/modules/es6.regexp.constructor.js");
7+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
118

12-
require("core-js/modules/es6.object.keys.js");
9+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
1310

14-
var userAgent = function userAgent() {
15-
return (navigator && navigator.userAgent || "").toLowerCase();
16-
};
11+
var IsSupported = /*#__PURE__*/function () {
12+
function IsSupported() {
13+
var supportedBrowsers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1714

18-
var vendor = function vendor() {
19-
return (navigator && navigator.vendor || "").toLowerCase();
20-
};
15+
_classCallCheck(this, IsSupported);
16+
17+
_defineProperty(this, "userAgent", function () {
18+
return (navigator && navigator.userAgent || "").toLowerCase();
19+
});
20+
21+
_defineProperty(this, "vendor", function () {
22+
return (navigator && navigator.vendor || "").toLowerCase();
23+
});
24+
25+
this.supportedBrowsers = supportedBrowsers;
26+
this.browsersRegex = new RegExp(Object.keys(supportedBrowsers).join("|"));
27+
}
28+
29+
_createClass(IsSupported, [{
30+
key: "isSupported",
31+
value: function isSupported() {
32+
var browser = this.getBrowser();
33+
var version = this.supportedBrowsers[browser];
34+
if (!version || version == "none") return false;
35+
if (version == "any") return true;
36+
37+
switch (browser) {
38+
case "msie":
39+
case "trident":
40+
return this.isIe(version);
41+
42+
case "edge":
43+
return this.isEdge(version);
44+
45+
case "firefox":
46+
return this.isFirefox(version);
47+
48+
case "chrome":
49+
return this.isChrome(version);
50+
}
51+
}
52+
}, {
53+
key: "compareVersion",
54+
value: function compareVersion(version, range) {
55+
var string = range + "";
56+
var n = +(string.match(/\d+/) || NaN);
57+
var op = string.match(/^[<>]=?|/)[0];
58+
return comparator[op] ? comparator[op](version, n) : version == n || n !== n;
59+
}
60+
}, {
61+
key: "getBrowser",
62+
value: function getBrowser() {
63+
var match = this.userAgent().match(this.browsersRegex);
64+
if (!match) return null;
65+
return match[0];
66+
}
67+
}, {
68+
key: "isChrome",
69+
value: function isChrome(range) {
70+
var match = /google inc/.test(this.vendor()) ? this.userAgent().match(/(?:chrome|crios)\/(\d+)/) : null;
71+
return match !== null && this.compareVersion(match[1], range);
72+
}
73+
}, {
74+
key: "isIe",
75+
value: function isIe(range) {
76+
var match = this.userAgent().match(/(?:msie |trident.+?; rv:)(\d+)/);
77+
return match !== null && this.compareVersion(match[1], range);
78+
}
79+
}, {
80+
key: "isEdge",
81+
value: function isEdge(range) {
82+
var match = this.userAgent().match(/edge\/(\d+)/);
83+
return match !== null && this.compareVersion(match[1], range);
84+
}
85+
}, {
86+
key: "isFirefox",
87+
value: function isFirefox(range) {
88+
var match = this.userAgent().match(/(?:firefox|fxios)\/(\d+)/);
89+
return match !== null && this.compareVersion(match[1], range);
90+
}
91+
}]);
92+
93+
return IsSupported;
94+
}();
2195

2296
var comparator = {
2397
"<": function _(a, b) {
@@ -33,87 +107,3 @@ var comparator = {
33107
return a >= b;
34108
}
35109
};
36-
37-
function compareVersion(version, range) {
38-
var string = range + "";
39-
var n = +(string.match(/\d+/) || NaN);
40-
var op = string.match(/^[<>]=?|/)[0];
41-
return comparator[op] ? comparator[op](version, n) : version == n || n !== n;
42-
}
43-
44-
var supportedBrowsers = {
45-
msie: "none",
46-
//ie / internet explorer
47-
trident: "none",
48-
//ie / internet explorer
49-
edge: ">1",
50-
// example version range for now
51-
chrome: "any",
52-
firefox: "any",
53-
opera: "none"
54-
};
55-
exports.supportedBrowsers = supportedBrowsers;
56-
57-
function isSupported() {
58-
var browsers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : supportedBrowsers;
59-
var browser = getBrowser();
60-
var version = browsers[browser];
61-
if (!version || version == "none") return false;
62-
if (version == "any") return true;
63-
64-
switch (browser) {
65-
case "msie":
66-
case "trident":
67-
return isIe(version);
68-
69-
case "edge":
70-
return isEdge(version);
71-
72-
case "firefox":
73-
return isFirefox(version);
74-
75-
case "chrome":
76-
return isChrome(version);
77-
}
78-
}
79-
80-
var browsersRegex = new RegExp(Object.keys(supportedBrowsers).join("|"));
81-
82-
function getBrowser() {
83-
var match = userAgent().match(browsersRegex);
84-
if (!match) return null;
85-
return match[0];
86-
} // can take a number or a string. Can also take a string prefixed with a comparable like, > or >=
87-
// example, chrome('>=90')
88-
89-
90-
function isChrome(range) {
91-
var match = /google inc/.test(vendor()) ? userAgent().match(/(?:chrome|crios)\/(\d+)/) : null;
92-
return match !== null && compareVersion(match[1], range);
93-
}
94-
95-
function isIe(range) {
96-
var match = userAgent().match(/(?:msie |trident.+?; rv:)(\d+)/);
97-
return match !== null && compareVersion(match[1], range);
98-
}
99-
100-
function isEdge(range) {
101-
var match = userAgent().match(/edge\/(\d+)/);
102-
return match !== null && compareVersion(match[1], range);
103-
}
104-
105-
function isFirefox(range) {
106-
var match = userAgent().match(/(?:firefox|fxios)\/(\d+)/);
107-
return match !== null && compareVersion(match[1], range);
108-
}
109-
110-
var _default = {
111-
supportedBrowsers: supportedBrowsers,
112-
compareVersion: compareVersion,
113-
isSupported: isSupported,
114-
isChrome: isChrome,
115-
isIe: isIe,
116-
isEdge: isEdge,
117-
isFirefox: isFirefox
118-
};
119-
exports.default = _default;

index.js

-83
This file was deleted.

0 commit comments

Comments
 (0)