1 | "use strict";
|
---|
2 | var __read = (this && this.__read) || function (o, n) {
|
---|
3 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
---|
4 | if (!m) return o;
|
---|
5 | var i = m.call(o), r, ar = [], e;
|
---|
6 | try {
|
---|
7 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
---|
8 | }
|
---|
9 | catch (error) { e = { error: error }; }
|
---|
10 | finally {
|
---|
11 | try {
|
---|
12 | if (r && !r.done && (m = i["return"])) m.call(i);
|
---|
13 | }
|
---|
14 | finally { if (e) throw e.error; }
|
---|
15 | }
|
---|
16 | return ar;
|
---|
17 | };
|
---|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
19 | exports.isSameCondition = exports.isUndefined = exports.isPlainObject = exports.isFunction = exports.isRegex = void 0;
|
---|
20 | var flat_1 = require("flat");
|
---|
21 | function isRegex(o) {
|
---|
22 | return o instanceof RegExp;
|
---|
23 | }
|
---|
24 | exports.isRegex = isRegex;
|
---|
25 | // https://stackoverflow.com/a/7356528/228885
|
---|
26 | function isFunction(functionToCheck) {
|
---|
27 | return (functionToCheck && {}.toString.call(functionToCheck) === "[object Function]");
|
---|
28 | }
|
---|
29 | exports.isFunction = isFunction;
|
---|
30 | function isPlainObject(a) {
|
---|
31 | if (a === null || Array.isArray(a)) {
|
---|
32 | return false;
|
---|
33 | }
|
---|
34 | return typeof a === "object";
|
---|
35 | }
|
---|
36 | exports.isPlainObject = isPlainObject;
|
---|
37 | function isUndefined(a) {
|
---|
38 | return typeof a === "undefined";
|
---|
39 | }
|
---|
40 | exports.isUndefined = isUndefined;
|
---|
41 | /**
|
---|
42 | * According to Webpack docs, a "test" should be the following:
|
---|
43 | *
|
---|
44 | * - A string
|
---|
45 | * - A RegExp
|
---|
46 | * - A function
|
---|
47 | * - An array of conditions (may be nested)
|
---|
48 | * - An object of conditions (may be nested)
|
---|
49 | *
|
---|
50 | * https://webpack.js.org/configuration/module/#condition
|
---|
51 | */
|
---|
52 | function isSameCondition(a, b) {
|
---|
53 | var _a, _b;
|
---|
54 | if (!a || !b) {
|
---|
55 | return a === b;
|
---|
56 | }
|
---|
57 | if (typeof a === "string" ||
|
---|
58 | typeof b === "string" ||
|
---|
59 | isRegex(a) ||
|
---|
60 | isRegex(b) ||
|
---|
61 | isFunction(a) ||
|
---|
62 | isFunction(b)) {
|
---|
63 | return a.toString() === b.toString();
|
---|
64 | }
|
---|
65 | var entriesA = Object.entries((0, flat_1.flatten)(a));
|
---|
66 | var entriesB = Object.entries((0, flat_1.flatten)(b));
|
---|
67 | if (entriesA.length !== entriesB.length) {
|
---|
68 | return false;
|
---|
69 | }
|
---|
70 | for (var i = 0; i < entriesA.length; i++) {
|
---|
71 | entriesA[i][0] = entriesA[i][0].replace(/\b\d+\b/g, "[]");
|
---|
72 | entriesB[i][0] = entriesB[i][0].replace(/\b\d+\b/g, "[]");
|
---|
73 | }
|
---|
74 | function cmp(_a, _b) {
|
---|
75 | var _c = __read(_a, 2), k1 = _c[0], v1 = _c[1];
|
---|
76 | var _d = __read(_b, 2), k2 = _d[0], v2 = _d[1];
|
---|
77 | if (k1 < k2)
|
---|
78 | return -1;
|
---|
79 | if (k1 > k2)
|
---|
80 | return 1;
|
---|
81 | if (v1 < v2)
|
---|
82 | return -1;
|
---|
83 | if (v1 > v2)
|
---|
84 | return 1;
|
---|
85 | return 0;
|
---|
86 | }
|
---|
87 | entriesA.sort(cmp);
|
---|
88 | entriesB.sort(cmp);
|
---|
89 | if (entriesA.length !== entriesB.length) {
|
---|
90 | return false;
|
---|
91 | }
|
---|
92 | for (var i = 0; i < entriesA.length; i++) {
|
---|
93 | if (entriesA[i][0] !== entriesB[i][0] ||
|
---|
94 | ((_a = entriesA[i][1]) === null || _a === void 0 ? void 0 : _a.toString()) !== ((_b = entriesB[i][1]) === null || _b === void 0 ? void 0 : _b.toString())) {
|
---|
95 | return false;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | return true;
|
---|
99 | }
|
---|
100 | exports.isSameCondition = isSameCondition;
|
---|
101 | //# sourceMappingURL=utils.js.map |
---|