typescriptify

package
v0.0.0-...-3418263 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfiguration = Configuration{}

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	//GenericStructToFieldMapping maps generic structures (including package name depending on usage) that should be replace by one of it's fields
	// the key is the struct to look for, while the value is the field of that struct we should replace it with. See more in readme.
	//
	// Given the following code, we would map it like `GenericStructToFieldMapping: map[string]string{"typescriptify.GenericField": "value"},`
	//
	//	type GenericField[T any] struct {
	// 		value T
	// 		IsSet bool `json:"-"` // Set means the value has been set
	// 	}
	// 	type Dummy struct {
	//  	 Greeting string `json:"greeting"`
	// 	}
	// 	type GenericAddress struct {
	// 		GenDummy GenericField[Dummy]   `json:"genDummy,omitempty"`
	// 	}
	GenericStructToFieldMapping map[string]string

	// ErrorOnDuplicateNames will return an error when there are duplicates names of symbols.
	// Typescript interfaces actually support multiple interfaces with the same name, but a warning can be helpful in certain operations
	ErrorOnDuplicateNames bool
}

func (Configuration) GetChildFieldFromGenericParent

func (c Configuration) GetChildFieldFromGenericParent(parentName string) string

GetChildFieldFromGenericParent returns empty string if not found

type EnumType

type EnumType struct {
	Type reflect.Type
}

type StructType

type StructType struct {
	Type         reflect.Type
	FieldOptions map[reflect.Type]TypeOptions
}

StructType stores settings for transforming one Golang struct.

func NewStruct

func NewStruct(i interface{}) *StructType

func (*StructType) WithFieldOpts

func (st *StructType) WithFieldOpts(i interface{}, opts TypeOptions) *StructType

type TSNamer

type TSNamer interface {
	TSName() string
}

type TypeOptions

type TypeOptions struct {
	TSType      string
	TSDoc       string
	TSTransform string
}

TypeOptions overrides options set by `ts_*` tags.

type TypeScriptify

type TypeScriptify struct {
	Prefix            string
	Suffix            string
	Indent            string
	CreateFromMethod  bool
	CreateConstructor bool
	BackupDir         string // If empty no backup
	DontExport        bool
	Configuration     Configuration
	CreateInterface   bool
	// contains filtered or unexported fields
}

func New

func New() *TypeScriptify

func (*TypeScriptify) Add

func (t *TypeScriptify) Add(obj interface{}) *TypeScriptify

func (*TypeScriptify) AddEnum

func (t *TypeScriptify) AddEnum(values interface{}) *TypeScriptify

func (*TypeScriptify) AddEnumValues

func (t *TypeScriptify) AddEnumValues(typeOf reflect.Type, values interface{}) *TypeScriptify

AddEnumValues is deprecated, use `AddEnum()`

func (*TypeScriptify) AddImport

func (t *TypeScriptify) AddImport(i string)

func (*TypeScriptify) AddType

func (t *TypeScriptify) AddType(typeOf reflect.Type) *TypeScriptify

func (*TypeScriptify) Convert

func (t *TypeScriptify) Convert(customCode map[string]string) (string, error)

func (TypeScriptify) ConvertToFile

func (t TypeScriptify) ConvertToFile(fileName string) error

func (*TypeScriptify) ManageType

func (t *TypeScriptify) ManageType(fld interface{}, opts TypeOptions) *TypeScriptify

ManageType can define custom options for fields of a specified type.

This can be used instead of setting ts_type and ts_transform for all fields of a certain type.

func (*TypeScriptify) WithBackupDir

func (t *TypeScriptify) WithBackupDir(b string) *TypeScriptify

func (*TypeScriptify) WithConfiguration

func (t *TypeScriptify) WithConfiguration(config Configuration) *TypeScriptify

func (*TypeScriptify) WithConstructor

func (t *TypeScriptify) WithConstructor(b bool) *TypeScriptify

func (*TypeScriptify) WithCreateFromMethod

func (t *TypeScriptify) WithCreateFromMethod(b bool) *TypeScriptify

func (*TypeScriptify) WithIndent

func (t *TypeScriptify) WithIndent(i string) *TypeScriptify

func (*TypeScriptify) WithInterface

func (t *TypeScriptify) WithInterface(b bool) *TypeScriptify

func (*TypeScriptify) WithPrefix

func (t *TypeScriptify) WithPrefix(p string) *TypeScriptify

func (*TypeScriptify) WithSuffix

func (t *TypeScriptify) WithSuffix(s string) *TypeScriptify

Jump to

Keyboard shortcuts

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