@cdklabs/typewriter
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @cdklabs/typewriter

Weekly Downloads

5,622

Version

0.0.4

License

Apache-2.0

Unpacked Size

388 kB

Total Files

79

Last publish

Collaborators

  • aws-cdk-team
  • amzn-oss