prettier/src/options.js

40 lines
1017 B
JavaScript
Raw Normal View History

"use strict";
var defaults = {
2017-01-10 07:22:58 +03:00
// Number of spaces the pretty-printer should use per tab
tabWidth: 2,
2017-01-10 07:22:58 +03:00
// Fit code within this line limit
printWidth: 80,
2017-01-05 18:01:43 +03:00
// If true, will use single instead of double quotes
singleQuote: false,
2017-01-10 07:22:58 +03:00
// Controls the printing of trailing commas wherever possible
trailingComma: false,
// Controls the printing of spaces inside array and objects
bracketSpacing: true,
// Which parser to use. Valid options are 'flow' and 'babylon'
parser: 'babylon'
};
// Copy options and fill in default values.
function normalize(options) {
const normalized = Object.assign({}, options || {});
// For backward compatibility. Deprecated in 0.0.10
if ('useFlowParser' in normalized) {
normalized.parser = normalized.useFlowParser ? 'flow' : 'babylon';
delete normalized.useFlowParser;
}
Object.keys(defaults).forEach(k => {
2017-01-13 23:03:53 +03:00
if (normalized[k] == null) {
normalized[k] = defaults[k];
}
});
return normalized;
};
module.exports = {
normalize
};