mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-27 14:40:23 +00:00
introduce new option "end_with_newline".
The default value is "false" and this will make sure that the output ends with a newline ("\n")
This commit is contained in:
parent
35c34d8450
commit
210dd48ae7
@ -41,12 +41,14 @@
|
||||
The options are:
|
||||
indent_size (default 4) — indentation size,
|
||||
indent_char (default space) — character to indent with,
|
||||
end_with_newline (default true) - end with a newline
|
||||
|
||||
e.g
|
||||
|
||||
css_beautify(css_source_text, {
|
||||
'indent_size': 1,
|
||||
'indent_char': '\t'
|
||||
'indent_char': '\t',
|
||||
'end_with_newline': false,
|
||||
});
|
||||
*/
|
||||
|
||||
@ -58,6 +60,7 @@
|
||||
options = options || {};
|
||||
var indentSize = options.indent_size || 4;
|
||||
var indentCharacter = options.indent_char || ' ';
|
||||
var endWithNewline = options.end_with_newline || false;
|
||||
|
||||
// compatibility
|
||||
if (typeof indentSize === "string") {
|
||||
@ -250,6 +253,15 @@
|
||||
|
||||
|
||||
var sweetCode = output.join('').replace(/[\n ]+$/, '');
|
||||
|
||||
// establish end_with_newline
|
||||
var should = endWithNewline;
|
||||
var actually = /\n$/.test(sweetCode)
|
||||
if (should && !actually)
|
||||
sweetCode += "\n";
|
||||
else if (!should && actually)
|
||||
sweetCode = sweetCode.slice(0, -1);
|
||||
|
||||
return sweetCode;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user