args.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. /**
  3. * The purpose of this function is
  4. * to handle back-backwards compatibility
  5. * @param {Object} args
  6. * @returns {{config: {}, cb: *}}
  7. */
  8. module.exports = function (args) {
  9. var config = {};
  10. var cb;
  11. switch (args.length) {
  12. case 1:
  13. if (isFilesArg(args[0])) {
  14. config.files = args[0];
  15. }
  16. else if (typeof args[0] === "function") {
  17. cb = args[0];
  18. }
  19. else {
  20. config = args[0];
  21. }
  22. break;
  23. case 2:
  24. // if second is a function, first MUST be config
  25. if (typeof args[1] === "function") {
  26. config = args[0] || {};
  27. cb = args[1];
  28. }
  29. else {
  30. if (args[1] === null || args[1] === undefined) {
  31. config = args[0];
  32. }
  33. else {
  34. // finally, second arg could be a plain object for config
  35. config = args[1] || {};
  36. if (!config.files) {
  37. config.files = args[0];
  38. }
  39. }
  40. }
  41. break;
  42. case 3:
  43. config = args[1] || {};
  44. if (!config.files) {
  45. config.files = args[0];
  46. }
  47. cb = args[2];
  48. }
  49. return {
  50. config: config,
  51. cb: cb
  52. };
  53. };
  54. /**
  55. * Files args were only ever strings or arrays
  56. * @param arg
  57. * @returns {*|boolean}
  58. */
  59. function isFilesArg(arg) {
  60. return Array.isArray(arg) || typeof arg === "string";
  61. }
  62. //# sourceMappingURL=args.js.map