options.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var defaults = {
  4. parser: require("../parsers/esprima"),
  5. tabWidth: 4,
  6. useTabs: false,
  7. reuseWhitespace: true,
  8. lineTerminator: require("os").EOL || "\n",
  9. wrapColumn: 74,
  10. sourceFileName: null,
  11. sourceMapName: null,
  12. sourceRoot: null,
  13. inputSourceMap: null,
  14. range: false,
  15. tolerant: true,
  16. quote: null,
  17. trailingComma: false,
  18. arrayBracketSpacing: false,
  19. objectCurlySpacing: true,
  20. arrowParensAlways: false,
  21. flowObjectCommas: true,
  22. tokens: true
  23. };
  24. var hasOwn = defaults.hasOwnProperty;
  25. // Copy options and fill in default values.
  26. function normalize(opts) {
  27. var options = opts || defaults;
  28. function get(key) {
  29. return hasOwn.call(options, key)
  30. ? options[key]
  31. : 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;
  56. ;