curlyfy adds curly brackets to a whitespace indented string like this:
/* input */
a
b
c
d
e
f
/* output */
a {
b {
c {
d
e
}
}
f
}
It also handles some exceptions:
/* input and output, no curly brackets added */
// trailing opening curly bracket
a = {
b: c
}
// trailing opening square bracket
a = [
b,
c
]
// trailing opening parentheses
fn(
a,
b,
c)
// trailing comma
fn(a,
b,
c)
npm install --save curlyfy
var curlyfy = require('curlyfy');
var output = curlyfy(input [, options]);
npm install --global curlyfy
curlyfy --help
File input as argument:
curlyfy file [options]
Standard input:
cat file | curlyfy [options]
blockOpeningException (default: '[{\\[\\(,]'
):
If this regular expression is found at the end of a block opening line, curly brackets are not added to that block.
insertSemicolons (default: false
):
Support [JavaScript semicolon-less style] (https://docs.npmjs.com/misc/coding-style#semicolons) gotchas. Because we guess that if you ditched braces you will probably ditch semicolons too ;)
For example:
var output = curlyfy(input, {insertSemicolons: true})
/* input */
++i
--i
(x || y).doSomething()
[a, b, c].forEach(doSomething)
/* output */
;++i
;--i
;(x || y).doSomething()
;[a, b, c].forEach(doSomething)
- Handle trailing comments
- Handle multiline comments
- Normalize indentations