Skip to main content

LineBuilder

Classes

Useful for generating formatted snippets of code.

Line

Kind: global class

new Line(text, indent)

ParamType
textstring
indentnumber

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

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

ParamType
termstring

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

ParamType
line_textstring

lineBuilder.extend(text) ⇒ void

Appends text to the last line.

Kind: instance method of LineBuilder

ParamType
textstring

Example

const b = new LineBuilder();
b.add("hello");
b.extend(" world");
b.build(); // "hello world"

lineBuilder.addLines(lines)

Kind: instance method of LineBuilder

ParamType
linesLineBuilder

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

ParamTypeDefaultDescription
textstring
[line_separator]string"\n"defaults to new-line character