Documentation
¶
Overview ¶
Package ts provides utilities for generating TypeScript code in Go.
Index ¶
- type Identifier
- type Property
- type Source
- func Array(elements ...Source) Source
- func AsSource(str string) Source
- func DocComment(comment string) Source
- func ImportedName(module string, name Identifier) Source
- func InvokeFunction(function Source, arguments ...Source) Source
- func InvokeMethod(receiver Source, name Identifier, arguments ...Source) Source
- func NumberLiteral[N constraints.Integer | constraints.Float](value N) Source
- func Object(properties ...Property) Source
- func RegexLiteral(re *regexp.Regexp) Source
- func Sourcef(format string, a ...Source) Source
- func StatementGroups(blankLinesBetweenGroups int, groups ...Source) Source
- func Statements(statements ...Source) Source
- func StringEscape(str string) Source
- func StringLiteral(str string) Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Identifier ¶
type Identifier string
Identifier is a TypeScript identifier string.
It can be used as Source, and since is of string kind it can also be useful as an identifier in code working with TypeScript.
func (Identifier) String ¶
func (i Identifier) String() string
type Source ¶
type Source interface { // String renders the source as TypeScript, complete with import statements. String() string // contains filtered or unexported methods }
Source represents TypeScript source code.
Source tracks imports separately for the rest of the source text so that imports of combined Source values can be deduplicated and hoisted to the top of the source. It is indentation-aware, so that nested Sources produce human-friendly output.
func Array ¶
Array outputs the given elements surrounded by `[` and `]` and interspersed with `,`. It gives reasonable line-breaking, whitespace and indentation.
func DocComment ¶
DocComment renders the given string as a multiline `/** … */`-style doc-comment. It is indentation-aware.
func ImportedName ¶
func ImportedName(module string, name Identifier) Source
ImportedName returns a Source representing a name that has been imported from a module.
func InvokeFunction ¶
InvokeFunction follows the function by a parenthesized comma-separated list of arguments. It gives reasonable line-breaking, whitespace and indentation.
func InvokeMethod ¶
func InvokeMethod(receiver Source, name Identifier, arguments ...Source) Source
InvokeMethod follows the receiver by a `.`, the method name and parenthesized comma-separated list of arguments. It gives reasonable line-breaking, whitespace and indentation.
func NumberLiteral ¶
func NumberLiteral[N constraints.Integer | constraints.Float](value N) Source
NumberLiteral returns literal Source for the given value.
func Object ¶
Object outputs the given properties as `name: value`-pairs surrounded by `{` and `}` and interspersed with `,`. It gives reasonable line-breaking, whitespace and indentation.
func RegexLiteral ¶
RegexLiteral represents the given regexp as a TypeScript regex literal. TODO there is missing escaping.
func Sourcef ¶
Sourcef turns format into indentation-aware source, replacing `%s` placeholders in it with the given arguments in an indentation-aware way.
func StatementGroups ¶
StatementGroups chains groups of statements with the given number of blank lines in between them.
func Statements ¶
Statements chains the given statements together with indentation-aware newlines.
func StringEscape ¶
StringEscape escapes the given string for inclusion in a TypeScript string literal. TODO there is missing escaping.
func StringLiteral ¶
StringLiteral represents the given string as a TypeScript string literal. TODO there is missing escaping.