UNPKG

1.73 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.isInitialOrHasNoParents = isInitialOrHasNoParents;
7exports.isInvalidOrder = isInvalidOrder;
8exports.getOrder = getOrder;
9exports.getLoaderObject = getLoaderObject;
10exports.mergeOptions = mergeOptions;
11exports.isString = isString;
12exports.isFunction = isFunction;
13exports.isType = isType;
14function isInitialOrHasNoParents(chunk) {
15 return chunk.isInitial() || chunk.parents.length === 0;
16}
17
18function isInvalidOrder(a, b) {
19 var bBeforeA = a.getPrevModules().indexOf(b) >= 0;
20 var aBeforeB = b.getPrevModules().indexOf(a) >= 0;
21 return aBeforeB && bBeforeA;
22}
23
24function getOrder(a, b) {
25 var aOrder = a.getOrder();
26 var bOrder = b.getOrder();
27 if (aOrder < bOrder) return -1;
28 if (aOrder > bOrder) return 1;
29 var aIndex = a.getOriginalModule().index2;
30 var bIndex = b.getOriginalModule().index2;
31 if (aIndex < bIndex) return -1;
32 if (aIndex > bIndex) return 1;
33 var bBeforeA = a.getPrevModules().indexOf(b) >= 0;
34 var aBeforeB = b.getPrevModules().indexOf(a) >= 0;
35 if (aBeforeB && !bBeforeA) return -1;
36 if (!aBeforeB && bBeforeA) return 1;
37 var ai = a.identifier();
38 var bi = b.identifier();
39 if (ai < bi) return -1;
40 if (ai > bi) return 1;
41 return 0;
42}
43
44function getLoaderObject(loader) {
45 if (isString(loader)) {
46 return { loader };
47 }
48 return loader;
49}
50
51function mergeOptions(a, b) {
52 if (!b) return a;
53 Object.keys(b).forEach(function (key) {
54 a[key] = b[key];
55 });
56 return a;
57}
58
59function isString(a) {
60 return typeof a === 'string';
61}
62
63function isFunction(a) {
64 return typeof a === 'function';
65}
66
67function isType(type, obj) {
68 return Object.prototype.toString.call(obj) === `[object ${type}]`;
69}
\No newline at end of file