js

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package js is a thin wrapper around Goja runtime.

Because Goja itself doesn't support most of modern JS features, the source code is transpiled by Babel before executing it, so we can actually write state migrations in ES5.1+.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

func NewRuntime

func NewRuntime() *Runtime

NewRuntime creates a new JavaScript runtime. The runtime is set up to uncapitalize struct fields and methods passed into runtime as objects.

func (*Runtime) Get

func (runtime *Runtime) Get(name string) goja.Value

Get the specified variable in the global context.

func (*Runtime) Script

func (runtime *Runtime) Script(name string, source string, args ...interface{}) *Script

func (*Runtime) Set

func (runtime *Runtime) Set(name string, val interface{}) error

Set the specified variable in the global context.

type Script

type Script struct {
	Name   string
	Source string
	Args   []interface{}
	// contains filtered or unexported fields
}

func (*Script) Run

func (s *Script) Run(opts ...ScriptOption) (interface{}, error)

Run runs a script, and then invokes the function exported by the script ("export default function") with the script's arguments.

type ScriptOption

type ScriptOption func(s *Script) error

func TranspileToES5

func TranspileToES5(val bool) ScriptOption

TranspileToES5 transforms the script source code to ES5.1 using Babel

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL