Skip to content

Latest commit

 

History

History
364 lines (260 loc) · 14.9 KB

API.md

File metadata and controls

364 lines (260 loc) · 14.9 KB

Classes

CodeWriter

Provides methods to build code blocks.

OptionsLibrary

Provides pre-defined option sets for common languages and language families.

CodeWriter

Provides methods to build code blocks.

Kind: global class

new CodeWriter(options)

Creates an instance of the CodeWriter class.

Param Type Description
options CodeWriterOptions Options used to configure the CodeWriter instance. If not specified, default options are used.

codeWriter.indent(code) ⇒ CodeWriter

Indents the current indent level.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
code string If specified, code is added after indenting

codeWriter.unindent(code) ⇒ CodeWriter

Unindents the current indent level.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
code string If specified, code is added after unindenting.

codeWriter.startBlock(code) ⇒ CodeWriter

Writes an opening block. The logic to write the block is language-specific and should be configured in the options.startBlock property.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
code string Optional code that can be part of the block. This may be used for certain languages and ignored for others.

codeWriter.endBlock(code) ⇒ CodeWriter

Writes a closing block. The logic to write the block is language-specific and should be configured in the options.endBlock property.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
code string Optional code that can be part of the block. This may be used for certain languages and ignored for others.

codeWriter.line(...code) ⇒ CodeWriter

Writes one or more lines of indented code.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
...code Array.<string> One or more lines of code to write.

codeWriter.lineIf(condition, ...code) ⇒ CodeWriter

Writes one or more lines of indented code, only if the specified condition is satisfied.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
condition boolean The condition to satisfy
...code Array.<string> One or more lines of code to write

codeWriter.inline(code, condition) ⇒ CodeWriter

Adds code to the current line, optionally based on a condition. Calls to inline can be chained until done() is called at which point the line is written.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
code string The code to add to the current line
condition boolean The condition upon which the code will be added

codeWriter.done() ⇒ CodeWriter

Indicates the completion of one or more inline() calls and writes the current line.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

codeWriter.blank(condition) ⇒ CodeWriter

Writes a blank line.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Description
condition Optional condition to write the blank line

codeWriter.repeat(arr, fn) ⇒ CodeWriter

Iterates over an array and executes the given function that builds code based on each item.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
arr Array The array to iterate over.
fn function The function to call for each item. The parameters are the CodeWriter instance, the item and the index of the item in the array.

codeWriter.iterate(obj, fn) ⇒ CodeWriter

Iterates over the properties of an object and executes the given function that builds code based on each property.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
obj Object The object to iterate over
fn function The function to call for each item. The parameters are the CodeWriter instance, the item and the index of the item in the array.

codeWriter.func(builderFn, ...args) ⇒ CodeWriter

Calls a function passing in the CodeWriter instance and additional arguments. Allows you to generate code based on complex logic, which is not possible using the fluent API.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
builderFn function The function to call. The parameters are the CodeWriter instance and the additional arguments.
...args Array.<Object> The additional arguments to pass to the function.

codeWriter.funcIf(builderFn, ...args) ⇒ CodeWriter

Calls a function passing in the CodeWriter instance and additional arguments. The function is called only if the specified boolean condition is met. Allows you to generate code based on complex logic, which is not possible using the fluent API.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
builderFn function The function to call. The parameters are the CodeWriter instance and the additional arguments.
...args Array.<Object> The additional arguments to pass to the function.

codeWriter.comment(...comments) ⇒ CodeWriter

Constructs a single line comment string and generates code for it. The options.singleLineComment property must be assigned for the CodeWriter to know how to construct the comment string.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
...comments Array.<string> Comment strings to generate

codeWriter.multiLineComment(...comments) ⇒ CodeWriter

Constructs a multi line comment string and generates code for it. The options.multiLineComment property must be assigned for the CodeWriter to know how to construct the comment string. If the option property is not assigned, the method attempts to use the options.singleLineComment property to generate multiple single line comments.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
...comments Array.<string> Comment strings to generate

codeWriter.docComment(...comments) ⇒ CodeWriter

Constructs a documentation comment string and generates code for it. The options.docComment property must be assigned for the CodeWriter to know how to construct the comment string.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Type Description
...comments Array.<string> Comment strings to generate

codeWriter.if(condition) ⇒ CodeWriter

Starts a condition block. Any CodeWriter methods called in this block will only be executed if the condition is true. To exit the condition block, call the endIf method.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

Param Description
condition Condition to evaluate

codeWriter.else() ⇒ CodeWriter

Inverts the condition in a condition block.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

codeWriter.endIf() ⇒ CodeWriter

Exits a condition block.

Kind: instance method of CodeWriter
Returns: CodeWriter - Instance of the CodeWriter

codeWriter.toCode() ⇒ string

Returns the currently built code as a string

Kind: instance method of CodeWriter
Returns: string - Currently built code

OptionsLibrary

Provides pre-defined option sets for common languages and language families.

Kind: global class

OptionsLibrary.c

Returns options that apply to the C language

Kind: static property of OptionsLibrary

OptionsLibrary.cpp

Returns options that apply to the C++ language

Kind: static property of OptionsLibrary

OptionsLibrary.csharp

Returns options that apply to the C# language

Kind: static property of OptionsLibrary

OptionsLibrary.java

Returns options that apply to the Java language

Kind: static property of OptionsLibrary

OptionsLibrary.javascript

Returns options that apply to the JavaScript language

Kind: static property of OptionsLibrary

OptionsLibrary.python

Returns options that apply to the Python language

Kind: static property of OptionsLibrary

OptionsLibrary.typescript

Returns options that apply to the Typescript language

Kind: static property of OptionsLibrary

OptionsLibrary.cLanguageFamily(prefs)

Returns options that apply to the C family of languages, including C/C++, C#, Java, etc.

Kind: static method of OptionsLibrary

Param Type Description
prefs Object Fine-grained preferences for generating the options