helpers.js 1.7 KB

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