0.0.12 • Published 1 year ago

typescript-code-generator v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

TypeScript Code Generator

build release

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
0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago