breakline

break your JS code into valid multilines as many as possible


License
MIT
Install
npm install breakline@0.1.4

Documentation

breakline

break your JS code into valid multilines as many as possible.

Travis branch AppVeyor branch Coveralls branch npm

Usage

Demo

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:

function getScienceFiction () {
  return 'The Three-Body Problem'
}
console.log(getScienceFiction())

output:

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.

Usage

breakline [options]

Optioins

--help, -h
Show help info.
-d
Output directory.
--nosuffix
don't add '.breakline' suffix to the output files.

Example

$ breakline your.js

This command will create a file named 'your.js.breakline'.

License

MIT © flowmemo