coldstitch
Version:
A code generation library, that helps you craft code snippets in code for multiple languages
49 lines (48 loc) • 1.5 kB
TypeScript
import { CodeFormatOptions } from "./format";
import { TypeRef } from "./types";
/**
* A symbol that can be used in a code template to indicate that the line should be omitted.
* Useful when doing logic that may or not include a line in the output.
*
* ```ts
* const code = code`
* ${isStrict ? "'useStrict';" : omitLine()}
* console.log("Hello, world!");
* `;
*
* @returns symbol that omits the line when present.
*/
export declare function omitLine(): symbol;
/**
* The interface that represents a code template public API.
*/
export interface Code {
readonly imports: TypeRef[];
toString(): string;
toCodeString(options?: CodeFormatOptions): string;
}
export declare class CodeImpl implements Code {
private literals;
private values;
constructor(literals: TemplateStringsArray, values?: any[]);
static fromString(value: string): Code;
get imports(): TypeRef[];
private resolveNestedCode;
private resolveValues;
private get unindent();
toString(): string;
toCodeString(options?: CodeFormatOptions): string;
}
/**
* A tagged template literal that represents code templates.
*
* ```ts
* const code = code`
* console.log("hello coldsnip!");
* `;
*
* @param literals The template literals.
* @param values The values to interpolate.
* @returns a `Code` instance that can be serialized to string using `toCodeString` or `toString`.
*/
export declare function code(literals: TemplateStringsArray, ...values: any[]): Code;