package
TsCodeGenerator ===============
npm install ts-code-generatorGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 2 packages.
112.5 kB
Includes dependencies.
This library separates out the code generation side of ts-type-info and doesn't have a dependency on the typescript compiler. It will be the future base of ts-type-info.
Still needs a major refactoring. Not intended for use yet.
import {createFile} from "ts-code-generator";
// create whatever you like at the start
const file = createFile({
classes: [{
name: "MyClass",
methods: [{
name: "myMethod",
parameters: [{ name: "myParam", type: "string" }],
onBeforeWrite: writer => writer.write("// myMethod is here"),
onWriteFunctionBody: writer => {
writer.write(`if (myParam != null && myParam.length > 40)`).block(() => {
writer.write("alert(myParam)");
});
Outputs:
@MyDecorator
abstract class MyClass {
myProperty1: string;
myProperty2 = 4;
// myMethod is here
myMethod(myParam: string) {
if (myParam != null && myParam.length > 40) {
alert(myParam);
}
return myParam;
}
}