index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var merge2 = require("merge2");
  4. var optionsManager = require("./managers/options");
  5. var taskManager = require("./managers/tasks");
  6. var reader_async_1 = require("./providers/reader-async");
  7. var reader_stream_1 = require("./providers/reader-stream");
  8. var reader_sync_1 = require("./providers/reader-sync");
  9. var arrayUtils = require("./utils/array");
  10. /**
  11. * Synchronous API.
  12. */
  13. function sync(source, opts) {
  14. var works = getWorks(source, reader_sync_1.default, opts);
  15. return arrayUtils.flatten(works);
  16. }
  17. exports.sync = sync;
  18. /**
  19. * Asynchronous API.
  20. */
  21. function async(source, opts) {
  22. var works = getWorks(source, reader_async_1.default, opts);
  23. return Promise.all(works).then(arrayUtils.flatten);
  24. }
  25. exports.async = async;
  26. /**
  27. * Stream API.
  28. */
  29. function stream(source, opts) {
  30. var works = getWorks(source, reader_stream_1.default, opts);
  31. return merge2(works);
  32. }
  33. exports.stream = stream;
  34. /**
  35. * Return a set of tasks based on provided patterns.
  36. */
  37. function generateTasks(source, opts) {
  38. var patterns = [].concat(source);
  39. var options = optionsManager.prepare(opts);
  40. return taskManager.generate(patterns, options);
  41. }
  42. exports.generateTasks = generateTasks;
  43. /**
  44. * Returns a set of works based on provided tasks and class of the reader.
  45. */
  46. function getWorks(source, _Reader, opts) {
  47. var patterns = [].concat(source);
  48. var options = optionsManager.prepare(opts);
  49. var tasks = taskManager.generate(patterns, options);
  50. var reader = new _Reader(options);
  51. return tasks.map(reader.read, reader);
  52. }