Documentation ¶
Index ¶
- func Prettier(b []byte) ([]byte, error)
- type Code
- type Dict
- type File
- func (f *File) GoString() string
- func (f *File) HeaderComment(comment string)
- func (f *File) Import(path, name string)
- func (f *File) ImportAlias(path, name, alias string)
- func (f *File) ImportDefault(path, name string)
- func (f *File) Render(w io.Writer) error
- func (f *File) Save(filename string) error
- type Group
- func (g *Group) Add(code ...Code) *Statement
- func (g *Group) Any() *Statement
- func (g *Group) Assert(typ Code) *Statement
- func (g *Group) Bigint() *Statement
- func (g *Group) Block(statements ...Code) *Statement
- func (g *Group) BlockFunc(f func(*Group)) *Statement
- func (g *Group) Boolean() *Statement
- func (g *Group) Break() *Statement
- func (g *Group) Call(params ...Code) *Statement
- func (g *Group) CallFunc(f func(*Group)) *Statement
- func (g *Group) Case(cases ...Code) *Statement
- func (g *Group) CaseFunc(f func(*Group)) *Statement
- func (g *Group) Class() *Statement
- func (g *Group) Const() *Statement
- func (g *Group) Continue() *Statement
- func (g *Group) Default() *Statement
- func (g *Group) Defs(definitions ...Code) *Statement
- func (g *Group) DefsFunc(f func(*Group)) *Statement
- func (g *Group) Do(f func(*Statement)) *Statement
- func (g *Group) Dot(name string) *Statement
- func (g *Group) Else() *Statement
- func (g *Group) Empty() *Statement
- func (g *Group) Export() *Statement
- func (g *Group) For(conditions ...Code) *Statement
- func (g *Group) ForFunc(f func(*Group)) *Statement
- func (g *Group) Function() *Statement
- func (g *Group) GoString() string
- func (g *Group) Id(name string) *Statement
- func (g *Group) If(conditions ...Code) *Statement
- func (g *Group) IfFunc(f func(*Group)) *Statement
- func (g *Group) Import() *Statement
- func (g *Group) Index(items ...Code) *Statement
- func (g *Group) IndexFunc(f func(*Group)) *Statement
- func (g *Group) Interface() *Statement
- func (g *Group) Len(v Code) *Statement
- func (g *Group) Let() *Statement
- func (g *Group) Line() *Statement
- func (g *Group) List(items ...Code) *Statement
- func (g *Group) ListFunc(f func(*Group)) *Statement
- func (g *Group) Lit(v interface{}) *Statement
- func (g *Group) LitByte(v byte) *Statement
- func (g *Group) LitByteFunc(f func() byte) *Statement
- func (g *Group) LitFunc(f func() interface{}) *Statement
- func (g *Group) LitRune(v rune) *Statement
- func (g *Group) LitRuneFunc(f func() rune) *Statement
- func (g *Group) Method(name Code) *Statement
- func (g *Group) Namespace() *Statement
- func (g *Group) New() *Statement
- func (g *Group) Null() *Statement
- func (g *Group) Number() *Statement
- func (g *Group) Op(op string) *Statement
- func (g *Group) Params(params ...Code) *Statement
- func (g *Group) ParamsFunc(f func(*Group)) *Statement
- func (g *Group) Parens(item Code) *Statement
- func (g *Group) Print(args ...Code) *Statement
- func (g *Group) PrintFunc(f func(*Group)) *Statement
- func (g *Group) Qual(path, name string) *Statement
- func (g *Group) Render(writer io.Writer) error
- func (g *Group) RenderWithFile(writer io.Writer, file *File) error
- func (g *Group) Return(result Code) *Statement
- func (g *Group) Semicolon() *Statement
- func (g *Group) String() *Statement
- func (g *Group) Switch(conditions ...Code) *Statement
- func (g *Group) SwitchFunc(f func(*Group)) *Statement
- func (g *Group) Type() *Statement
- func (g *Group) Types(types ...Code) *Statement
- func (g *Group) TypesFunc(f func(*Group)) *Statement
- func (g *Group) Undefined() *Statement
- func (g *Group) Union(types ...Code) *Statement
- func (g *Group) UnionFunc(f func(*Group)) *Statement
- func (g *Group) Values(values ...Code) *Statement
- func (g *Group) ValuesFunc(f func(*Group)) *Statement
- func (g *Group) Var() *Statement
- type Option
- type Statement
- func Add(code ...Code) *Statement
- func Any() *Statement
- func Assert(typ Code) *Statement
- func Bigint() *Statement
- func Block(statements ...Code) *Statement
- func BlockFunc(f func(*Group)) *Statement
- func Boolean() *Statement
- func Break() *Statement
- func Call(params ...Code) *Statement
- func CallFunc(f func(*Group)) *Statement
- func Case(cases ...Code) *Statement
- func CaseFunc(f func(*Group)) *Statement
- func Class() *Statement
- func Const() *Statement
- func Continue() *Statement
- func Default() *Statement
- func Defs(definitions ...Code) *Statement
- func DefsFunc(f func(*Group)) *Statement
- func Do(f func(*Statement)) *Statement
- func Dot(name string) *Statement
- func Else() *Statement
- func Empty() *Statement
- func Export() *Statement
- func For(conditions ...Code) *Statement
- func ForFunc(f func(*Group)) *Statement
- func Function() *Statement
- func Id(name string) *Statement
- func If(conditions ...Code) *Statement
- func IfFunc(f func(*Group)) *Statement
- func Import() *Statement
- func Index(items ...Code) *Statement
- func IndexFunc(f func(*Group)) *Statement
- func Interface() *Statement
- func Len(v Code) *Statement
- func Let() *Statement
- func Line() *Statement
- func List(items ...Code) *Statement
- func ListFunc(f func(*Group)) *Statement
- func Lit(v interface{}) *Statement
- func LitByte(v byte) *Statement
- func LitByteFunc(f func() byte) *Statement
- func LitFunc(f func() interface{}) *Statement
- func LitRune(v rune) *Statement
- func LitRuneFunc(f func() rune) *Statement
- func Method(name Code) *Statement
- func Namespace() *Statement
- func New() *Statement
- func Null() *Statement
- func Number() *Statement
- func Op(op string) *Statement
- func Params(params ...Code) *Statement
- func ParamsFunc(f func(*Group)) *Statement
- func Parens(item Code) *Statement
- func Print(args ...Code) *Statement
- func PrintFunc(f func(*Group)) *Statement
- func Qual(path, name string) *Statement
- func Return(result Code) *Statement
- func Semicolon() *Statement
- func String() *Statement
- func Switch(conditions ...Code) *Statement
- func SwitchFunc(f func(*Group)) *Statement
- func Type() *Statement
- func Types(types ...Code) *Statement
- func TypesFunc(f func(*Group)) *Statement
- func Undefined() *Statement
- func Union(types ...Code) *Statement
- func UnionFunc(f func(*Group)) *Statement
- func Values(values ...Code) *Statement
- func ValuesFunc(f func(*Group)) *Statement
- func Var() *Statement
- func (s *Statement) Add(code ...Code) *Statement
- func (s *Statement) Any() *Statement
- func (s *Statement) Assert(typ Code) *Statement
- func (s *Statement) Bigint() *Statement
- func (s *Statement) Block(statements ...Code) *Statement
- func (s *Statement) BlockFunc(f func(*Group)) *Statement
- func (s *Statement) Boolean() *Statement
- func (s *Statement) Break() *Statement
- func (s *Statement) Call(params ...Code) *Statement
- func (s *Statement) CallFunc(f func(*Group)) *Statement
- func (s *Statement) Case(cases ...Code) *Statement
- func (s *Statement) CaseFunc(f func(*Group)) *Statement
- func (s *Statement) Class() *Statement
- func (s *Statement) Clone() *Statement
- func (s *Statement) Const() *Statement
- func (s *Statement) Continue() *Statement
- func (s *Statement) Default() *Statement
- func (s *Statement) Defs(definitions ...Code) *Statement
- func (s *Statement) DefsFunc(f func(*Group)) *Statement
- func (s *Statement) Do(f func(*Statement)) *Statement
- func (s *Statement) Dot(name string) *Statement
- func (s *Statement) Else() *Statement
- func (s *Statement) Empty() *Statement
- func (s *Statement) Export() *Statement
- func (s *Statement) For(conditions ...Code) *Statement
- func (s *Statement) ForFunc(f func(*Group)) *Statement
- func (s *Statement) Function() *Statement
- func (s *Statement) Id(name string) *Statement
- func (s *Statement) If(conditions ...Code) *Statement
- func (s *Statement) IfFunc(f func(*Group)) *Statement
- func (s *Statement) Import() *Statement
- func (s *Statement) Index(items ...Code) *Statement
- func (s *Statement) IndexFunc(f func(*Group)) *Statement
- func (s *Statement) Interface() *Statement
- func (s *Statement) Len(v Code) *Statement
- func (s *Statement) Let() *Statement
- func (s *Statement) Line() *Statement
- func (s *Statement) List(items ...Code) *Statement
- func (s *Statement) ListFunc(f func(*Group)) *Statement
- func (s *Statement) Lit(v interface{}) *Statement
- func (s *Statement) LitByte(v byte) *Statement
- func (s *Statement) LitByteFunc(f func() byte) *Statement
- func (s *Statement) LitFunc(f func() interface{}) *Statement
- func (s *Statement) LitRune(v rune) *Statement
- func (s *Statement) LitRuneFunc(f func() rune) *Statement
- func (s *Statement) Method(name Code) *Statement
- func (s *Statement) Namespace() *Statement
- func (s *Statement) New() *Statement
- func (s *Statement) Null() *Statement
- func (s *Statement) Number() *Statement
- func (s *Statement) Op(op string) *Statement
- func (s *Statement) Params(params ...Code) *Statement
- func (s *Statement) ParamsFunc(f func(*Group)) *Statement
- func (s *Statement) Parens(item Code) *Statement
- func (s *Statement) Print(args ...Code) *Statement
- func (s *Statement) PrintFunc(f func(*Group)) *Statement
- func (s *Statement) Qual(path, name string) *Statement
- func (s *Statement) Render(writer io.Writer) error
- func (s *Statement) RenderWithFile(writer io.Writer, file *File) error
- func (s *Statement) Return(result Code) *Statement
- func (s *Statement) Semicolon() *Statement
- func (s *Statement) String() *Statement
- func (s *Statement) Switch(conditions ...Code) *Statement
- func (s *Statement) SwitchFunc(f func(*Group)) *Statement
- func (s *Statement) Type() *Statement
- func (s *Statement) Types(types ...Code) *Statement
- func (s *Statement) TypesFunc(f func(*Group)) *Statement
- func (s *Statement) TypescriptString() string
- func (s *Statement) Undefined() *Statement
- func (s *Statement) Union(types ...Code) *Statement
- func (s *Statement) UnionFunc(f func(*Group)) *Statement
- func (s *Statement) Values(values ...Code) *Statement
- func (s *Statement) ValuesFunc(f func(*Group)) *Statement
- func (s *Statement) Var() *Statement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type File ¶
type File struct { *Group // contains filtered or unexported fields }
func (*File) HeaderComment ¶
func (*File) ImportAlias ¶
func (*File) ImportDefault ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func (*Group) Assert ¶
Assert renders a period followed by a single item enclosed by parenthesis. Use for type assertions.
func (*Group) Block ¶
Block renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.
func (*Group) BlockFunc ¶
BlockFunc renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.
func (*Group) Call ¶
Call renders a comma separated list enclosed by parenthesis. Use for function calls.
func (*Group) CallFunc ¶
CallFunc renders a comma separated list enclosed by parenthesis. Use for function calls.
func (*Group) Defs ¶
Defs renders a statement list enclosed in parenthesis. Use for definition lists.
func (*Group) DefsFunc ¶
DefsFunc renders a statement list enclosed in parenthesis. Use for definition lists.
func (*Group) Do ¶
Do calls the provided function with the statement as a parameter. Use for embedding logic.
func (*Group) Empty ¶
Empty adds an empty item. Empty items render nothing but are followed by a separator in lists.
func (*Group) Index ¶
Index renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.
func (*Group) IndexFunc ¶
IndexFunc renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.
func (*Group) ListFunc ¶
ListFunc renders a comma separated list. Use for multiple return functions.
func (*Group) Lit ¶
Lit renders a literal. Lit supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Passing any other type will panic.
func (*Group) LitByteFunc ¶
LitByteFunc renders a byte literal. LitByteFunc generates the value to render by executing the provided function.
func (*Group) LitFunc ¶
LitFunc renders a literal. LitFunc generates the value to render by executing the provided function. LitFunc supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Returning any other type will panic.
func (*Group) LitRuneFunc ¶
LitRuneFunc renders a rune literal. LitRuneFunc generates the value to render by executing the provided function.
func (*Group) Null ¶
Null adds a null item. Null items render nothing and are not followed by a separator in lists.
func (*Group) Params ¶
Params renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.
func (*Group) ParamsFunc ¶
ParamsFunc renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.
func (*Group) Parens ¶
Parens renders a single item in parenthesis. Use for type conversion or to specify evaluation order.
func (*Group) Qual ¶
Qual renders a qualified identifier. Imports are automatically added when used with a File. If the path matches the local path, the package name is omitted. If package names conflict they are automatically renamed. Note that it is not possible to reliably determine the package name given an arbitrary package path, so a sensible name is guessed from the path and added as an alias. The names of all standard library packages are known so these do not need to be aliased. If more control is needed of the aliases, see [File.ImportName](#importname) or File.ImportAlias(#importalias).
func (*Group) RenderWithFile ¶
RenderWithFile renders the Group to the provided writer, using imports from the provided file.
func (*Group) SwitchFunc ¶
SwitchFunc renders the keyword followed by a semicolon separated list.
func (*Group) Types ¶
Types renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.
func (*Group) TypesFunc ¶
TypesFunc renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.
func (*Group) Values ¶
Values renders a comma separated list enclosed by curly braces. Use for slice or composite literals.
func (*Group) ValuesFunc ¶
ValuesFunc renders a comma separated list enclosed by curly braces. Use for slice or composite literals.
type Option ¶
func WithPrettierFormatter ¶
func WithPrettierFormatter() Option
type Statement ¶
type Statement []Code
func Assert ¶
Assert renders a period followed by a single item enclosed by parenthesis. Use for type assertions.
func Block ¶
Block renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.
func BlockFunc ¶
BlockFunc renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.
func CallFunc ¶
CallFunc renders a comma separated list enclosed by parenthesis. Use for function calls.
func DefsFunc ¶
DefsFunc renders a statement list enclosed in parenthesis. Use for definition lists.
func Do ¶
Do calls the provided function with the statement as a parameter. Use for embedding logic.
func Empty ¶
func Empty() *Statement
Empty adds an empty item. Empty items render nothing but are followed by a separator in lists.
func Index ¶
Index renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.
func IndexFunc ¶
IndexFunc renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.
func Lit ¶
func Lit(v interface{}) *Statement
Lit renders a literal. Lit supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Passing any other type will panic.
func LitByteFunc ¶
LitByteFunc renders a byte literal. LitByteFunc generates the value to render by executing the provided function.
func LitFunc ¶
func LitFunc(f func() interface{}) *Statement
LitFunc renders a literal. LitFunc generates the value to render by executing the provided function. LitFunc supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Returning any other type will panic.
func LitRuneFunc ¶
LitRuneFunc renders a rune literal. LitRuneFunc generates the value to render by executing the provided function.
func Null ¶
func Null() *Statement
Null adds a null item. Null items render nothing and are not followed by a separator in lists.
func Params ¶
Params renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.
func ParamsFunc ¶
ParamsFunc renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.
func Parens ¶
Parens renders a single item in parenthesis. Use for type conversion or to specify evaluation order.
func Qual ¶
Qual renders a qualified identifier. Imports are automatically added when used with a File. If the path matches the local path, the package name is omitted. If package names conflict they are automatically renamed. Note that it is not possible to reliably determine the package name given an arbitrary package path, so a sensible name is guessed from the path and added as an alias. The names of all standard library packages are known so these do not need to be aliased. If more control is needed of the aliases, see [File.ImportName](#importname) or File.ImportAlias(#importalias).
func SwitchFunc ¶
SwitchFunc renders the keyword followed by a semicolon separated list.
func Types ¶
Types renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.
func TypesFunc ¶
TypesFunc renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.
func Values ¶
Values renders a comma separated list enclosed by curly braces. Use for slice or composite literals.
func ValuesFunc ¶
ValuesFunc renders a comma separated list enclosed by curly braces. Use for slice or composite literals.
func (*Statement) Assert ¶
Assert renders a period followed by a single item enclosed by parenthesis. Use for type assertions.
func (*Statement) Block ¶
Block renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.
func (*Statement) BlockFunc ¶
BlockFunc renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.
func (*Statement) Call ¶
Call renders a comma separated list enclosed by parenthesis. Use for function calls.
func (*Statement) CallFunc ¶
CallFunc renders a comma separated list enclosed by parenthesis. Use for function calls.
func (*Statement) Clone ¶
Clone makes a copy of the Statement, so further tokens can be appended without affecting the original.
func (*Statement) Defs ¶
Defs renders a statement list enclosed in parenthesis. Use for definition lists.
func (*Statement) DefsFunc ¶
DefsFunc renders a statement list enclosed in parenthesis. Use for definition lists.
func (*Statement) Do ¶
Do calls the provided function with the statement as a parameter. Use for embedding logic.
func (*Statement) Dot ¶
Dot renders a period followed by an identifier. Use for fields and selectors.
func (*Statement) Empty ¶
Empty adds an empty item. Empty items render nothing but are followed by a separator in lists.
func (*Statement) Index ¶
Index renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.
func (*Statement) IndexFunc ¶
IndexFunc renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.
func (*Statement) ListFunc ¶
ListFunc renders a comma separated list. Use for multiple return functions.
func (*Statement) Lit ¶
Lit renders a literal. Lit supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Passing any other type will panic.
func (*Statement) LitByteFunc ¶
LitByteFunc renders a byte literal. LitByteFunc generates the value to render by executing the provided function.
func (*Statement) LitFunc ¶
LitFunc renders a literal. LitFunc generates the value to render by executing the provided function. LitFunc supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Returning any other type will panic.
func (*Statement) LitRuneFunc ¶
LitRuneFunc renders a rune literal. LitRuneFunc generates the value to render by executing the provided function.
func (*Statement) Null ¶
Null adds a null item. Null items render nothing and are not followed by a separator in lists.
func (*Statement) Params ¶
Params renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.
func (*Statement) ParamsFunc ¶
ParamsFunc renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.
func (*Statement) Parens ¶
Parens renders a single item in parenthesis. Use for type conversion or to specify evaluation order.
func (*Statement) Qual ¶
Qual renders a qualified identifier. Imports are automatically added when used with a File. If the path matches the local path, the package name is omitted. If package names conflict they are automatically renamed. Note that it is not possible to reliably determine the package name given an arbitrary package path, so a sensible name is guessed from the path and added as an alias. The names of all standard library packages are known so these do not need to be aliased. If more control is needed of the aliases, see [File.ImportName](#importname) or File.ImportAlias(#importalias).
func (*Statement) RenderWithFile ¶
RenderWithFile renders the Statement to the provided writer, using imports from the provided file.
func (*Statement) SwitchFunc ¶
SwitchFunc renders the keyword followed by a semicolon separated list.
func (*Statement) Types ¶
Types renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.
func (*Statement) TypesFunc ¶
TypesFunc renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.
func (*Statement) TypescriptString ¶
GoString renders the Statement for testing. Any error will cause a panic.
func (*Statement) UnionFunc ¶
UnionFunc renders a pipe separated list. Use for union type constraints.
func (*Statement) Values ¶
Values renders a comma separated list enclosed by curly braces. Use for slice or composite literals.
func (*Statement) ValuesFunc ¶
ValuesFunc renders a comma separated list enclosed by curly braces. Use for slice or composite literals.