Documentation
¶
Index ¶
- func Transpile(reader io.Reader, cfg *Config, opts ...OptionFunc) (string, error)
- func TranspileCtx(ctx context.Context, script io.Reader, cfg *Config, opts ...OptionFunc) (string, error)
- func TranspileString(script string, cfg *Config, opts ...OptionFunc) (string, error)
- type Config
- type OptionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Transpile ¶
Transpile transpiles the bytes read from reader using the provided config and options
func TranspileCtx ¶
func TranspileCtx(ctx context.Context, script io.Reader, cfg *Config, opts ...OptionFunc) (string, error)
TranspileCtx compiles the bytes read from script using the provided context. Note that due to a limitation in goja, context cancellation only works while in JavaScript code, it does not interrupt native Go functions.
func TranspileString ¶
func TranspileString(script string, cfg *Config, opts ...OptionFunc) (string, error)
TranspileString compiles the provided typescript string and returns the
Types ¶
type Config ¶
type Config struct { CompileOptions map[string]interface{} TypescriptSource *goja.Program Runtime *goja.Runtime // contains filtered or unexported fields }
Config defines the behavior of the typescript compiler.
func NewDefaultConfig ¶
func NewDefaultConfig() *Config
NewDefaultConfig creates a new instance of the Config struct with default values and the latest typescript source code.s
func (*Config) Initialize ¶
type OptionFunc ¶
type OptionFunc func(*Config)
OptionFunc allows for easy chaining of pre-built config modifiers such as WithVersion.
func WithCompileOptions ¶
func WithCompileOptions(options map[string]interface{}) OptionFunc
WithCompileOptions sets the compile options that will be passed to the typescript compiler.
func WithRuntime ¶
func WithRuntime(runtime *goja.Runtime) OptionFunc
WithRuntime allows you to over-ride the default runtime
func WithVersion ¶
func WithVersion(tag string) OptionFunc
WithVersion loads the provided tagged typescript source from the default registry