Categorygithub.com/clarkmcc/go-typescript
modulepackage
0.7.0
Repository: https://github.com/clarkmcc/go-typescript.git
Documentation: pkg.go.dev

# README

This package provides a thin wrapper around goja (a native Javascript runtime for Go). There are no direct dependencies besides goja, and testify (for testing only). This package supports the following features:

  • Typescript compilation and evaluation.
  • A context-aware evaluation API to support cancellation.
  • AMD-style modules using the built-in Almond module loader.
  • Custom Typescript version registration with built-in support for versions 3.8.3, 3.9.9, 4.1.2, 4.1.3, 4.1.4, 4.1.5, 4.2.2, 4.2.3, 4.2.4, and 4.7.2.
  • 90%+ test coverage

Installation

go get github.com/clarkmcc/go-typescript

Examples

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

Evaluate calls EvaluateCtx using the default background context.
EvaluateCtx evaluates the provided src using the specified options and returns the goja value result or an error.
NewDefaultConfig creates a new instance of the Config struct with default values and the latest typescript source code.s.
Transpile transpiles the bytes read from reader using the provided config and options.
TranspileCtx compiles the bytes read from script using the provided context.
TranspileString compiles the provided typescript string and returns the.
WithAlmondModuleLoader adds the almond module loader to the list of scripts that should be evaluated first.
WithCompileOptions sets the compile options that will be passed to the typescript compiler.
WithEvaluateBefore adds scripts that should be evaluated before evaluating the provided script.
WithEvaluationRuntime allows callers to use their own runtimes with the evaluator.
WithModuleName determines the module name applied to the typescript module if applicable.
WithPreventCancellation prevents the transpiler runtime from handling its own context cancellation.
WithRuntime allows you to over-ride the default runtime.
WithScriptHook adds a script hook that should be evaluated immediately before the actual script evaluation.
WithScriptPreTranspileHook adds a script hook that should be evaluated immediately before transpiling the script.
WithTranspile indicates whether the provided script should be transpiled before it is evaluated.
WithTranspileOptions adds options to be passed to the transpiler if the transpiler is applicable.
WithTypescriptSource configures a Typescript source from the provided typescript source string which is compiled by goja when the config is initialized.
WithVersion loads the provided tagged typescript source from the default registry.

# Structs

Config defines the behavior of the typescript compiler.
No description provided by the author

# Type aliases

No description provided by the author
TranspileOptionFunc allows for easy chaining of pre-built config modifiers such as WithVersion.