3 Helpers to manipulate [rocambole](https://github.com/millermedeiros/rocambole)
6 Used mainly by [esformatter](https://github.com/millermedeiros/esformatter/) and its plugins.
10 - positive integer (`1` till `99`): "add or keep `[n]` line breaks".
11 - `-1`: keep original line breaks.
12 - `">2"`: add linebreaks until it's over `2`.
13 - `">=1"`: add line breaks until it's equal or greater than `1`.
14 - `"<2"`: remove linebreaks until it's smaller than `2`.
15 - `"<=1"`: remove/add line breaks until it's smaller or equal to `1`.
20 var br = require('rocambole-linebreak');
25 `setOptions` is just a way to store some constants so later on the
26 `limit`/`limitBefore`/`limitAfter` you can reference the values by Id.
30 // sets "value" used by `LineBreak` tokens (defaults to `"\n"`)
33 // values inside "before" are used by `limitBefore`
35 // setting to `0` will remove all line breaks before the token
39 // values inside "after" are used by `limitAfter`
41 // setting to `1` will add/keep a single `LineBreak` after the token
47 **Important:** calling this method will override **all** the options.
49 ### limitBefore(token, typeOrValue)
51 limits the amount of `LineBreak` before a given token.
54 // remove all line breaks before `node.startToken`
55 limitBefore(node.startToken, 0);
56 // add/keep 2 line breaks before `node.startToken`
57 limitBefore(node.startToken, 2);
58 // add/keep more than 1 line break
59 limitBefore(node.startToken, '>1');
60 // keep 2 line breaks or more
61 limitBefore(node.startToken, '>=2');
62 // keep less than 3 line breaks
63 limitBefore(node.startToken, '<3');
64 // will use value stored on `setOptions` for `before.parenthesis`
65 limitBefore(node.startToken, 'parenthesis');
66 // values smaller than zero are ignored (this won't change anything)
67 limitBefore(node.startToken, -1);
70 ### limitAfter(token, typeOrValue)
72 limits the amount of `LineBreak` after a given token.
75 // remove all line breaks after `node.startToken`
76 limitAfter(node.startToken, 0);
77 // add/keep 1 line break after `node.startToken`
78 limitAfter(node.startToken, 1);
79 // add/keep more than 1 line break
80 limitAfter(node.startToken, '>1');
81 // keep 2 line breaks or more
82 limitAfter(node.startToken, '>=2');
83 // keep less than 3 line breaks
84 limitAfter(node.startToken, '<3');
85 // will use value stored on `setOptions` for `after.parenthesis`
86 limitAfter(node.startToken, 'parenthesis');
87 // values smaller than zero are ignored (this won't change anything)
88 limitAfter(node.startToken, -1);
91 ### limit(token, typeOrValue)
93 limits the amount of `LineBreak` around a given token.
96 // add/keep 1 line break before and after `node.startToken`
97 limit(node.startToken, 1);
99 // it's just an alias to
100 limitBefore(node.startToken, 1);
101 limitAfter(node.startToken, 1);
104 ### limitBeforeEndOfFile(ast[, typeOrValue])
106 limits the amount of line breaks at the end of the AST.
109 // at least one line break at the end of the file
110 limitBeforeEndOfFile(ast, 1);
111 // if you don't pass the `typeOrValue` it will use "EndOfFile" as the type
112 limitBeforeEndOfFile(ast);
115 ### expectedBefore(type)
117 reads value stored during `setOptions` for a given `type`, or returns `-1` if
121 assert( expectedBefore('parenthesis') === 0 );
124 ### expectedAfter(type)
126 reads value stored during `setOptions` for a given `type`, or returns `-1` if
130 assert( expectedAfter('parenthesis') === 1 );
135 This module uses [debug](https://www.npmjs.com/package/debug) internally. To
136 make it easier to identify what is wrong we sometimes run the esformatter tests
137 with a `DEBUG` flag, like:
140 DEBUG=rocambole:br:* npm test
145 Released under the MIT License