formatter-config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.createFormatterConfig = void 0;
  4. const basic_formatter_1 = require("./basic-formatter");
  5. const code_frame_formatter_1 = require("./code-frame-formatter");
  6. function createFormatterConfig(options) {
  7. if (typeof options === 'function') {
  8. return {
  9. format: options,
  10. pathType: 'relative',
  11. };
  12. }
  13. const type = options
  14. ? typeof options === 'object'
  15. ? options.type || 'codeframe'
  16. : options
  17. : 'codeframe';
  18. const pathType = options && typeof options === 'object' ? options.pathType || 'relative' : 'relative';
  19. if (!type || type === 'basic') {
  20. return {
  21. format: (0, basic_formatter_1.createBasicFormatter)(),
  22. pathType,
  23. };
  24. }
  25. if (type === 'codeframe') {
  26. const config = options && typeof options === 'object'
  27. ? options.options || {}
  28. : {};
  29. return {
  30. format: (0, code_frame_formatter_1.createCodeFrameFormatter)(config),
  31. pathType,
  32. };
  33. }
  34. throw new Error(`Unknown "${type}" formatter. Available types are: "basic", "codeframe" or a custom function.`);
  35. }
  36. exports.createFormatterConfig = createFormatterConfig;