0.0.3 • Published 7 months ago

@cdklabs/typewriter v0.0.3

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
7 months ago

@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;
 * }
 */
0.0.3

7 months ago

0.0.2

8 months ago

0.0.1

10 months ago

0.0.0

11 months ago