de-heredoc
Transform "heredoc call" to "string literal" in JavaScript source code before minifications.
Install
$ npm install de-heredoc
Usage
heredoc
is a function to make multiline strings in JavaScript, there are already some libraries you can use e.g. heredoc and multiline.
$ cat test.jsvar heredoc = require;var html = <div id="test"> <span>foo</span> <span>bar</span> </div>*/});$ node> var deHeredoc = require> deHeredoc>$ cat test.jsvar html='<div id="test">\n <span>foo</span>\n <span>bar</span>\n</div>';
Options
options
has 4 properties, from
dependency
beautify
and whitespace
.
from
Control file
's type.
"file" (default)
file
is a file path, change this file in place and return undefined
.
If the value of from
is "file", then the file
parameter can be an array.
"string"
file
is a string of JS source code, return the new source code.
// 'var foo="foo";'
"ast"
file
is an UglifyJS AST object, return the new AST object.
var ast = UglifyJSvar newAst = newAst // 'var foo="foo";'
dependency
The heredoc
library's name.
"heredoc" (default)
// 'var foo="foo";'
beautify
Beautify output source code or not.
false (default)
/*if (1 + 1) { var foo = "foo";}*/
whitespace
Control whitespaces in output string literals, see Whitespaces
"indent" (default), "raw" and "oneline".
// 'var foo="foo";'
Whitespaces
You can use parameter name to control whitespaces in output string literals.
indent
Strip the redundant leading whitespaces, and preserve other indents.
var html = ;
will be transformed to
var html='<div id="test">\n <span>foo</span>\n <span>bar</span>\n</div>';
raw
Preserve all whitespaces.
var html = ;
will be transformed to
var html=' <div id="test">\n <span>foo</span>\n <span>bar</span>\n </div>';
oneline
Remove all leading and trailing whitespaces.
var html = ;
will be transformed to
var html='<div id="test"><span>foo</span><span>bar</span></div>';
License
MIT