break your JS code into valid multilines as many as possible
npm install breakline



js
const breakline = require('breakline')
const code = 'var a = 1'
console.log(breakline(code))
/* the result is:
var
a
=
1
*/
`It uses acorn to parse code. You can pass
acorn's options object as the second argument of breakline, like breakline(sourceCode, {ecmaVersion: 5}). The default
options of breakline is {ecmaVersion: 6, allowHashBang: true}.How
This tool does nothing except inserts line feeds \n in appropriate positions, which would not trigger Automatic Semicolon Insertion. It won't delete anything or modify the AST(Abstrac Syntax Tree) of your code. It just inserts \n.
Example
input:`js
function getScienceFiction () {
return 'The Three-Body Problem'
}
console.log(getScienceFiction())
`
output:`js
function
getScienceFiction
(
)
{
return 'The Three-Body Problem'
}
console
.
log
(
getScienceFiction
(
)
)
`
CLI
This tool can be used from the command line. Install it globally by npm install breakline -g.$3
breakline [options]$3
--help, -h
Show help info.
-d
Output directory.
--nosuffix
don't add '.breakline' suffix to the output files. $3
`shell
$ breakline your.js
``