invoke-callback.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.build = void 0;
  4. const onlyCountsSync = (state) => {
  5. return state.counts;
  6. };
  7. const groupsSync = (state) => {
  8. return state.groups;
  9. };
  10. const defaultSync = (state) => {
  11. return state.paths;
  12. };
  13. const limitFilesSync = (state) => {
  14. return state.paths.slice(0, state.options.maxFiles);
  15. };
  16. const onlyCountsAsync = (state, error, callback) => {
  17. report(error, callback, state.counts, state.options.suppressErrors);
  18. return null;
  19. };
  20. const defaultAsync = (state, error, callback) => {
  21. report(error, callback, state.paths, state.options.suppressErrors);
  22. return null;
  23. };
  24. const limitFilesAsync = (state, error, callback) => {
  25. report(error, callback, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
  26. return null;
  27. };
  28. const groupsAsync = (state, error, callback) => {
  29. report(error, callback, state.groups, state.options.suppressErrors);
  30. return null;
  31. };
  32. function report(error, callback, output, suppressErrors) {
  33. if (error && !suppressErrors)
  34. callback(error, output);
  35. else
  36. callback(null, output);
  37. }
  38. function build(options, isSynchronous) {
  39. const { onlyCounts, group, maxFiles } = options;
  40. if (onlyCounts)
  41. return isSynchronous
  42. ? onlyCountsSync
  43. : onlyCountsAsync;
  44. else if (group)
  45. return isSynchronous
  46. ? groupsSync
  47. : groupsAsync;
  48. else if (maxFiles)
  49. return isSynchronous
  50. ? limitFilesSync
  51. : limitFilesAsync;
  52. else
  53. return isSynchronous
  54. ? defaultSync
  55. : defaultAsync;
  56. }
  57. exports.build = build;