jz

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 14 Imported by: 0

README

jz

JavaScript / TypeScript ES6 Virtual Machine in pure Go. Based on:

Example

cmd/example1/main.go

package main

import (
  "github.com/andrylavr/jz"
  "log"
)
import _ "embed"

//go:embed example1.js
var example1 string

func main() {
  vm := jz.New()
  vm.ImportMap["three"] = "https://threejs.org/build/three.js"
  vm.ImportMap["three/addons/"] = "https://threejs.org/examples/jsm/"

  _, err := vm.RunScript("example1.js", example1)
  if err != nil {
    log.Println(err)
  }
}

See more docs here: https://github.com/dop251/goja

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetContent

func GetContent(url string) (string, error)

Types

type Cacher added in v1.0.4

type Cacher interface {
	Exists(key string) bool
	Get(key string) string
	Save(key string, s string)
}

type Console added in v1.0.4

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

func (*Console) Error added in v1.0.4

func (console *Console) Error(args ...interface{})

func (*Console) Info added in v1.0.4

func (console *Console) Info(args ...interface{})

func (*Console) Log added in v1.0.4

func (console *Console) Log(args ...interface{})

func (*Console) Warn added in v1.0.4

func (console *Console) Warn(args ...interface{})

type FSCacher added in v1.0.4

type FSCacher struct {
	Dir string
}

func (FSCacher) Exists added in v1.0.4

func (t FSCacher) Exists(key string) bool

func (FSCacher) Get added in v1.0.4

func (t FSCacher) Get(key string) string

func (FSCacher) Save added in v1.0.4

func (t FSCacher) Save(key string, content string)

type ImportMap

type ImportMap map[string]string

type JSModule added in v1.0.4

type JSModule = *Object

type Module added in v1.0.4

type Module struct {
	Exports *Object
	// contains filtered or unexported fields
}

func (*Module) Require added in v1.0.4

func (m *Module) Require(name string) Value

type ModuleCache added in v1.0.1

type ModuleCache map[string][]byte

type Object added in v1.0.1

type Object = goja.Object

type Require added in v1.0.4

type Require struct {
	sync.Mutex
	// contains filtered or unexported fields
}

type Runtime

type Runtime struct {
	*goja.Runtime
	UseBabel      bool
	UseTypeScript bool
	ImportMap
	//require         *Require
	TransformCacher Cacher
	ContentCacher   Cacher
}

func New

func New() *Runtime

func (*Runtime) AddImportMap

func (r *Runtime) AddImportMap(m ImportMap)

func (*Runtime) ClearImportMap

func (r *Runtime) ClearImportMap()

func (*Runtime) RunFile

func (r *Runtime) RunFile(filename string) (Value, error)

func (*Runtime) RunScript

func (r *Runtime) RunScript(name, src string) (Value, error)

func (*Runtime) RunString

func (r *Runtime) RunString(str string) (Value, error)

RunString executes the given string in the global context.

func (*Runtime) Transform

func (r *Runtime) Transform(src string) (string, error)

Transform transforms src from ES6|TS to ES5

type Value

type Value = goja.Value

func NewConsole added in v1.0.4

func NewConsole(vm *Runtime) Value

func NewRequire added in v1.0.4

func NewRequire(vm *Runtime) Value

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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