typescript-code-generator
v0.0.13
Published
 [](https://gitHub.com/marioke/TypeScript-Code-Generator/releases/
Downloads
50
Readme
TypeScript Code Generator
Example usage
const doc = new CodeDocument()
.addHeadComment("Example file")
.addHeadComment("This is completely auto generated")
.addInterface(
new InterfaceBuilder("HelloWorldOptions").addProperty({
name: "name",
type: "string",
})
)
.addClass(
new ClassBuilder("ExampleClass").addMethod(
new MethodBuilder("hello")
.addDescriptionLine("This is a method")
.addParameter({
name: "options",
type: "HelloWorldOptions",
comment: "Options for the hello method",
})
.addLines([
"if(!options.name) {",
"throw new Error(`YIKES! It looks like you're unknown`);",
"}",
"console.log('Hello ' + options.name);",
])
)
);
console.log(doc.toString())
Example output
// Example file
// This is completely auto generated
interface HelloWorldOptions {
name: string;
}
class ExampleClass {
/**
* This is a method
* @param options Options for the hello method
*/
public hello(options: HelloWorldOptions): void {
if (!options.name) {
throw new Error(`YIKES! It looks like you're unknown`);
}
console.log("Hello " + options.name);
}
}
Get started
npm i typescript-code-generator