tsgen

package
v3.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 12 Imported by: 0

README

tsgen

tsgen is devtool to generate dummy typescript code for goja node modules written in golang. These generated typescript code can be compiled to generate .d.ts files to provide intellisense to editors like vscode and documentation for the node modules.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ternary

func Ternary(condition bool, trueVal, falseVal string) string

Ternary is a ternary operator for strings

func TsDefaultValue

func TsDefaultValue(t string) string

Types

type Class

type Class struct {
	Properties  []Property
	Methods     []Method
	Constructor Function
}

Class represents a TypeScript class data structure

type Entity

type Entity struct {
	Name          string
	Value         string
	Type          string // "class", "function", or "object" or "interface" or "const"
	Description   string
	Example       string    // this will be part of description with @example jsdoc tag
	Class         Class     // if Type == "class"
	Function      Function  // if Type == "function"
	Object        Interface // if Type == "object"
	IsConstructor bool      // true if this is a constructor function
}

Define a struct to hold information about your TypeScript entities

type EntityParser

type EntityParser struct {
	// contains filtered or unexported fields
}

EntityParser is responsible for parsing a go file and generating corresponding typescript entities.

func NewEntityParser

func NewEntityParser(dir string) (*EntityParser, error)

NewEntityParser creates a new EntityParser

func (*EntityParser) GetEntities

func (p *EntityParser) GetEntities() []Entity

func (*EntityParser) Parse

func (p *EntityParser) Parse() error

Parse parses the given file and generates corresponding typescript entities

type ExtObject

type ExtObject struct {
	// contains filtered or unexported fields
}

type Function

type Function struct {
	Parameters []Parameter
	Returns    string
	CanFail    bool
	ReturnStmt string
}

Function represents a TypeScript function data structure If CanFail is true, the function returns a Result<T, E> type So modify the function signature to return a Result<T, E> type in this case

type Interface

type Interface struct {
	Properties []Property
}

type Method

type Method struct {
	Name        string
	Description string
	Parameters  []Parameter
	Returns     string
	CanFail     bool
	ReturnStmt  string
}

Method represents a TypeScript method data structure If CanFail is true, the method returns a Result<T, E> type So modify the method signature to return a Result<T, E> type in this case

type Parameter

type Parameter struct {
	Name string
	Type string
}

Parameter represents function or method parameter

type Property

type Property struct {
	Name        string
	Type        string
	Description string
}

Property represent class or object property

func ConvertExtObjectToEntities

func ConvertExtObjectToEntities(extObj *ExtObject, nestedTypes map[string]Entity) []Property

ConvertExtObjectToEntities recursively converts an ExtObject to a list of Entity objects

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL