LineBuilder
Classes
Useful for generating formatted snippets of code.
Line
Kind: global class
- Line
- new Line(text, indent)
- .text :
string - .indentation :
number
new Line(text, indent)
| Param | Type |
|---|---|
| text | string |
| indent | number |
line.text : string
Kind: instance property of Line
line.indentation : number
Kind: instance property of Line
LineBuilder
Useful for generating formatted snippets of code.
Kind: global class
- LineBuilder
- new LineBuilder()
- instance
- .indentation ⇒
number - .count ⇒
number - .containsSubstring(term) ⇒
boolean - .indent() ⇒
LineBuilder - .dedent() ⇒
LineBuilder - .add(line_text) ⇒
LineBuilder - .extend(text) ⇒
void - .addLines(lines)
- .build() ⇒
string
- .indentation ⇒
- static
new LineBuilder()
Example
const b = new LineBuilder();
b.add("function hello(){");
b.indent();
b.add("return \"hello world\";");
b.dedent();
b.add("}");
b.build();
// function hello(){
// return "hello world";
// }
lineBuilder.indentation ⇒ number
Current indentation level Mainly intended for testing
Kind: instance property of LineBuilder
lineBuilder.count ⇒ number
Number of lines
Kind: instance property of LineBuilder
lineBuilder.containsSubstring(term) ⇒ boolean
Substring test on a per-line basis. A match can only span a single line, so multi-line matches will not be found.
Kind: instance method of LineBuilder
Returns: boolean - true if the term was found at least once, false otherwise
| Param | Type |
|---|---|
| term | string |
lineBuilder.indent() ⇒ LineBuilder
Kind: instance method of LineBuilder
lineBuilder.dedent() ⇒ LineBuilder
NOTE: clamps indentation to 0 (can't go negative)
Kind: instance method of LineBuilder
lineBuilder.add(line_text) ⇒ LineBuilder
Adds an entire new line with a given text. Inherits the current indentation level.
Kind: instance method of LineBuilder
| Param | Type |
|---|---|
| line_text | string |
lineBuilder.extend(text) ⇒ void
Appends text to the last line.
Kind: instance method of LineBuilder
| Param | Type |
|---|---|
| text | string |
Example
const b = new LineBuilder();
b.add("hello");
b.extend(" world");
b.build(); // "hello world"
lineBuilder.addLines(lines)
Kind: instance method of LineBuilder
| Param | Type |
|---|---|
| lines | LineBuilder |
lineBuilder.build() ⇒ string
Renders out an indented string of lines
Kind: instance method of LineBuilder
LineBuilder.fromText(text, [line_separator]) ⇒ LineBuilder
Kind: static method of LineBuilder
| Param | Type | Default | Description |
|---|---|---|---|
| text | string | ||
| [line_separator] | string | "\n" | defaults to new-line character |