0.0.3 • Published 7 months ago
@cdklabs/typewriter v0.0.3
@cdklabs/typewriter
Write code with an AST builder instead of string concatenation.
Example
import { code, FreeFunction, Module, TypeScriptRenderer } from '@cdklabs/typewriter';
// Create a new module
const scope = new Module('my-package');
// Add a function to the module ...
const fn = new FreeFunction(scope, {
name: 'myFunction',
});
// ... add statements to the function body
fn.addBody(code.stmt.ret(code.expr.lit(1)));
// Emit the code
const renderer = new TypeScriptRenderer();
console.log(renderer.render(scope));
/**
* Prints:
*
* function myFunction(): void {
* return 1;
* }
*/