options.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.normalize = void 0;
  4. var util_1 = require("./util");
  5. var defaults = {
  6. parser: require("../parsers/esprima"),
  7. tabWidth: 4,
  8. useTabs: false,
  9. reuseWhitespace: true,
  10. lineTerminator: (0, util_1.getLineTerminator)(),
  11. wrapColumn: 74,
  12. sourceFileName: null,
  13. sourceMapName: null,
  14. sourceRoot: null,
  15. inputSourceMap: null,
  16. range: false,
  17. tolerant: true,
  18. quote: null,
  19. trailingComma: false,
  20. arrayBracketSpacing: false,
  21. objectCurlySpacing: true,
  22. arrowParensAlways: false,
  23. flowObjectCommas: true,
  24. tokens: true,
  25. };
  26. var hasOwn = defaults.hasOwnProperty;
  27. // Copy options and fill in default values.
  28. function normalize(opts) {
  29. var options = opts || defaults;
  30. function get(key) {
  31. return hasOwn.call(options, key) ? options[key] : defaults[key];
  32. }
  33. return {
  34. tabWidth: +get("tabWidth"),
  35. useTabs: !!get("useTabs"),
  36. reuseWhitespace: !!get("reuseWhitespace"),
  37. lineTerminator: get("lineTerminator"),
  38. wrapColumn: Math.max(get("wrapColumn"), 0),
  39. sourceFileName: get("sourceFileName"),
  40. sourceMapName: get("sourceMapName"),
  41. sourceRoot: get("sourceRoot"),
  42. inputSourceMap: get("inputSourceMap"),
  43. parser: get("esprima") || get("parser"),
  44. range: get("range"),
  45. tolerant: get("tolerant"),
  46. quote: get("quote"),
  47. trailingComma: get("trailingComma"),
  48. arrayBracketSpacing: get("arrayBracketSpacing"),
  49. objectCurlySpacing: get("objectCurlySpacing"),
  50. arrowParensAlways: get("arrowParensAlways"),
  51. flowObjectCommas: get("flowObjectCommas"),
  52. tokens: !!get("tokens"),
  53. };
  54. }
  55. exports.normalize = normalize;