Documentation
¶
Overview ¶
Package jsrt provides runtime support for TypeScript-to-Go transpiled code.
Index ¶
- func CallMethod(obj any, method string, args ...any) any
- func Entries(v any) []any
- func Flat(v any) []any
- func FromEntries(entries any) map[string]any
- func GetField(v any, name string) any
- func GetFieldAs[T any](v any, name string) T
- func GoExportedName(s string) string
- func Index(v any, key any) any
- func IsArray(v any) bool
- func Keys(v any) []string
- func Len(v any) int
- func OmitFields(obj any, keys ...string) map[string]any
- func OmitKeys(v any, keys ...string) any
- func Ptr[T any](v T) *T
- func SetIndex(v any, key any, val any)
- func Throw(v any)
- func ThrowError(msg string)
- func ThrowTypeError(msg string)
- func ToAnySlice[T any](s []T) []any
- func ToBool(v any) bool
- func TypeOf(v any) string
- func Values(v any) []any
- type JSError
- type JSObject
- func (o *JSObject) Bool() bool
- func (o *JSObject) Call(args ...any) *JSObject
- func (o *JSObject) Float64() float64
- func (o *JSObject) Get(name string) *JSObject
- func (o *JSObject) Index(key any) *JSObject
- func (o *JSObject) Int() int
- func (o *JSObject) IsNil() bool
- func (o *JSObject) Len() int
- func (o *JSObject) Set(name string, value any)
- func (o *JSObject) String() string
- func (o *JSObject) Unwrap() any
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallMethod ¶ added in v0.5.0
CallMethod calls a method on an object by name at runtime using reflection. Returns the first return value, or nil if the method doesn't exist.
func Entries ¶ added in v0.7.0
Entries returns [key, value] pairs from a map or struct (like Object.entries()).
func FromEntries ¶ added in v0.7.0
FromEntries creates a map from [key, value] pairs (like Object.fromEntries()).
func GetField ¶
GetField accesses a field on an any-typed value by name, like JavaScript property access. Supports structs (by exported field name), maps (by original or exported key), and pointers. For maps, tries the original name first, then the exported (PascalCase) name. For structs, tries the exported name first, then the original name.
func GetFieldAs ¶
GetFieldAs is a typed version of GetField that returns a value of the specified type.
func GoExportedName ¶ added in v0.5.0
GoExportedName converts a camelCase JS name to Go exported PascalCase.
func IsArray ¶ added in v0.7.0
IsArray returns true if the value is a slice or array (like Array.isArray()).
func Keys ¶ added in v0.7.0
Keys returns the keys of a map or struct as a string slice (like Object.keys()).
func OmitFields ¶ added in v0.5.0
OmitFields returns a copy of a map[string]any with the specified keys removed.
func OmitKeys ¶ added in v0.7.0
OmitKeys returns a shallow copy of the value with the specified keys removed. Works with maps (string keys) and structs (copies to map, omitting named fields).
func Ptr ¶
func Ptr[T any](v T) *T
Ptr returns a pointer to the given value. Useful for passing literals to *T parameters.
func Throw ¶
func Throw(v any)
Throw panics with a JSError, simulating JavaScript's throw statement.
func ThrowTypeError ¶
func ThrowTypeError(msg string)
ThrowTypeError simulates throw new TypeError(msg).
Types ¶
type JSError ¶
JSError represents a JavaScript error thrown with throw statement.
func CatchValue ¶
CatchValue converts a recovered panic value into a *JSError.
type JSObject ¶
type JSObject struct {
V any // The underlying value
}
JSObject wraps an any value with JavaScript-like dynamic property access and method calls. Used by the transpiler as a fallback when TypeScript types cannot be statically mapped to Go types. When the TypeScript checker provides concrete type information (including narrowed types), the transpiler generates concrete Go types with type assertions instead.
func (*JSObject) Get ¶
Get accesses a property by name, returning a new JSObject. Supports structs (exported fields), maps (string keys), and *JSObject nesting.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package array provides JavaScript Array.prototype method equivalents using Go generics.
|
Package array provides JavaScript Array.prototype method equivalents using Go generics. |
|
compat
|
|
|
lodash
Package lodash provides Go adapters for commonly used lodash/lodash-es functions.
|
Package lodash provides Go adapters for commonly used lodash/lodash-es functions. |
|
uuid
Package uuid provides a Go adapter for the npm "uuid" package.
|
Package uuid provides a Go adapter for the npm "uuid" package. |
|
zod
Package zod provides a Go adapter for the npm "zod" schema validation library.
|
Package zod provides a Go adapter for the npm "zod" schema validation library. |
|
Package console provides console.log/error/warn for transpiled TypeScript code.
|
Package console provides console.log/error/warn for transpiled TypeScript code. |
|
Package fetch provides the fetch() API for transpiled TypeScript code.
|
Package fetch provides the fetch() API for transpiled TypeScript code. |
|
node
|
|
|
crypto
Package crypto provides Node.js crypto module equivalents for transpiled TypeScript code.
|
Package crypto provides Node.js crypto module equivalents for transpiled TypeScript code. |
|
fs
Package fs provides Node.js fs module equivalents for transpiled TypeScript code.
|
Package fs provides Node.js fs module equivalents for transpiled TypeScript code. |
|
http
Package http provides Node.js http module equivalents for transpiled TypeScript code.
|
Package http provides Node.js http module equivalents for transpiled TypeScript code. |
|
path
Package path provides Node.js path module equivalents for transpiled TypeScript code.
|
Package path provides Node.js path module equivalents for transpiled TypeScript code. |
|
Package promise provides a Promise[T] type for transpiled async/await TypeScript code.
|
Package promise provides a Promise[T] type for transpiled async/await TypeScript code. |
|
Package web provides Go struct definitions for Web API types used by transpiled TypeScript code.
|
Package web provides Go struct definitions for Web API types used by transpiled TypeScript code. |