js

package
v2.4.9 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExitCode    = errors.New("script returned with non-zero exit code")
	ErrMainMissing = errors.New("main function not found")
	ErrMainInvalid = errors.New("main function is invalid")
)
View Source
var PanicOnError = false

Functions

func Base64 added in v2.4.6

func Base64() *_base64

func JSON added in v2.4.6

func JSON() *_json

func WithConsole

func WithConsole(s *Command)

Types

type Command

type Command struct {
	// The name of the main function to run.
	Main string
	// contains filtered or unexported fields
}

func NewScript

func NewScript(mainFunc string, options ...OptFunc) (cmd *Command)

func (*Command) AddFunc

func (s *Command) AddFunc(f ...VMFunc)

func (*Command) Run

func (s *Command) Run(scriptSource string) (result *CommandResult, err error)

type CommandError added in v2.4.6

type CommandError struct {
	Importance int
	Message    string
	Wrapped    error
}

func (*CommandError) Error added in v2.4.6

func (e *CommandError) Error() string

func (*CommandError) ExitCode added in v2.4.6

func (e *CommandError) ExitCode() int

func (*CommandError) Unwrap added in v2.4.6

func (e *CommandError) Unwrap() error

type CommandResult added in v2.4.6

type CommandResult struct {
	Importance int    `json:"importance"`
	Message    string `json:"message"`
}

type JSConsole

type JSConsole struct {
	Debug func(...any) `json:"debug"`
	Log   func(...any) `json:"log"`
	Info  func(...any) `json:"info"`
	Warn  func(...any) `json:"warn"`
	Error func(...any) `json:"error"`
	Fatal func(...any) `json:"fatal"`
}

func Console

func Console() *JSConsole

type OptFunc

type OptFunc func(*Command)

func WithGlobal

func WithGlobal(key string, value any) OptFunc

func WithGlobals

func WithGlobals(globals map[string]any) OptFunc

func WithVM added in v2.4.6

func WithVM(vm *goja.Runtime) OptFunc

type VMFunc

type VMFunc func(*goja.Runtime) error

Jump to

Keyboard shortcuts

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