GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Why Go
  • Case Studies
  • Use Cases
  • Security
  • Learn
  • Effective Go
  • Go User Manual
  • Standard library
  • Release Notes
  • API
  • Packages
  • Recorded Talks
  • Meetups
  • Conferences

This view

  • Original page
  • New address

GeezerVison is showing pkg.go.dev — jsGo package - github.com/ScriptTiger/jsGo - Go Packages

Details

  • checked Valid go.mod file

    The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.

  • checked Redistributable license

    Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.

  • unchecked Tagged version

    Modules with tagged versions give importers more predictable builds.

  • unchecked Stable version

    When a project reaches major version v1 it is considered stable.

  • Learn more about best practices

Repository

github.com/ScriptTiger/jsGo

Links

  • Open Source Insights Logo Open Source Insights

README ¶

Say Thanks!

DISCLAIMER!!!: THIS MODULE IS STILL IN ITS EARLY DEVELOPMENT, SO USE AT YOUR OWN RISK!

jsGo

The jsGo package is a collection of convenience functions and variables to make working with the standard Go syscall/js package in both GopherJS and Go/TinyGo WASM a bit more natural. For the most part, most code should be easily transferable from GopherJS to Go/TinyGo WASM, and vice versa, with minimal changes needed, if any.

For Go/TinyGo WASM, jsGo requires the "glue code" to be loaded so that it can use the defined Go class when instantiating the WASM module, and also so that the WASM module can make call-outs to it should it need to access the JS APIs outside of the WASM sandbox.

To import jsGo into your project:
go get github.com/ScriptTiger/jsGo
Then just import "github.com/ScriptTiger/jsGo" and get started with using its functions and variables.

Please refer to the dev package docs and reference implementation for more details and ideas on how to integrate jsGo into your project.

Dev package docs:
https://pkg.go.dev/github.com/ScriptTiger/jsGo

Reference implementation:
https://github.com/ScriptTiger/jsGo/blob/main/ref

Other projects using jsGo

TigerChat:
https://github.com/ScriptTiger/TigerChat

TigerShare:
https://github.com/ScriptTiger/TigerShare

More About ScriptTiger

For more ScriptTiger scripts and goodies, check out ScriptTiger's GitHub Pages website:
https://scripttiger.github.io/

Documentation ¶

Index ¶

  • Variables
  • func Append(child js.Value)
  • func AppendChild(child js.Value)
  • func CreateButton(str string, onclick func()) (button js.Value)
  • func CreateElement(tag string) js.Value
  • func CreateElementNS(ns, tag string) js.Value
  • func CreateLoadFileButton(text, accept string, multiple bool, onchange func(loadFiles js.Value)) (span js.Value)
  • func CreateSaveFileButton(text string, options map[string]any, saveFileCallback func(saveFile js.Value)) (button js.Value)
  • func FNV1a32(data []byte) js.Value
  • func FNV1a64(data []byte) js.Value
  • func FuncOf(fn func(args []js.Value) any) js.Func
  • func GetElementById(id string) js.Value
  • func HasOwn(object js.Value, str string) bool
  • func IsError(err js.Value) bool
  • func LoadJS(src string, onload func()) (classic js.Value)
  • func LoadWASM(str string, then func(), methods ...func(err js.Value) any)
  • func Permissions(str string, permissionsCallback func(permissionStatus js.Value))
  • func Prepend(child js.Value)
  • func ProcOf(fn func(args []js.Value)) js.Func
  • func SHA256(data []byte, shaCallback func(hash js.Value))
  • func SHA384(data []byte, shaCallback func(hash js.Value))
  • func SHA512(data []byte, shaCallback func(hash js.Value))
  • func SetFunc(str string, fn func(args []js.Value) any) js.Func
  • func SetProc(str string, fn func(args []js.Value)) js.Func
  • func SetSimpleFunc(str string, fn func() any) js.Func
  • func SetSimpleProc(str string, fn func()) js.Func
  • func SimpleFuncOf(fn func() any) js.Func
  • func SimpleProcOf(fn func()) js.Func
  • func ThenableChain(thenable js.Value, thenFunc func(arg js.Value) any, ...) any

Constants ¶

This section is empty.

Variables ¶

View Source
var (
	// Global aliases
	Global = js.Global()
	Set    = Global.Set
	Get    = Global.Get
	Call   = Global.Call

	// Global property aliases
	DevicePixelRatio = Get("devicePixelRatio")
	InnerHeight      = Get("innerHeight")
	InnerWidth       = Get("innerWidth")
	OuterHeight      = Get("outerHeight")
	OuterWidth       = Get("outerWidth")

	// Constructor aliases
	Array           = Get("Array")
	AudioContext    = Get("AudioContext")
	Blob            = Get("Blob")
	Date            = Get("Date")
	Error           = Get("Error")
	EventSource     = Get("EventSource")
	FileReader      = Get("FileReader")
	Number          = Get("Number")
	Object          = Get("Object")
	Promise         = Get("Promise")
	String          = Get("String")
	TextDecoder     = Get("TextDecoder")
	TextEncoder     = Get("TextEncoder")
	Uint8Array      = Get("Uint8Array")
	URL             = Get("URL")
	URLSearchParams = Get("URLSearchParams")

	// BOM namespace object aliases
	Crypto      = Get("crypto")
	History     = Get("history")
	IndexedDB   = Get("indexedDB")
	Intl        = Get("Intl")
	IDBKeyRange = Get("IDBKeyRange")
	JSON        = Get("JSON")
	Location    = Get("location")
	Math        = Get("Math")
	Navigator   = Get("navigator")
	Performance = Get("performance")
	Screen      = Get("screen")
	Subtle      = Crypto.Get("subtle")
	WebAssembly = Get("WebAssembly")

	// DOM aliases
	Document = Get("document")
	Head     = Document.Get("head")
	Body     = Document.Get("body")

	// Method aliases
	Alert              = Get("alert").Invoke
	Atob               = Get("atob").Invoke
	Btoa               = Get("btoa").Invoke
	ClearInterval      = Get("clearInterval").Invoke
	ClearTimeout       = Get("clearTimeout").Invoke
	Fetch              = Get("fetch").Invoke
	GetRandomValues    = Crypto.Get("getRandomValues").Invoke
	Log                = Get("console").Get("log").Invoke
	MatchMedia         = Get("matchMedia").Invoke
	ParseInt           = Get("parseInt").Invoke
	SetInterval        = Get("setInterval").Invoke
	SetTimeout         = Get("setTimeout").Invoke
	ShowSaveFilePicker = Get("showSaveFilePicker").Invoke

	// Convenience variables
	Params = URLSearchParams.New(Location.Get("search").String())
)

Functions ¶

func Append ¶

func Append(child js.Value)

func AppendChild ¶

func AppendChild(child js.Value)

func CreateButton ¶

func CreateButton(str string, onclick func()) (button js.Value)

Create a button element with an onclick callback

func CreateElement ¶

func CreateElement(tag string) js.Value

func CreateElementNS ¶

func CreateElementNS(ns, tag string) js.Value

func CreateLoadFileButton ¶

func CreateLoadFileButton(text, accept string, multiple bool, onchange func(loadFiles js.Value)) (span js.Value)

Create a span element containing both a hidden input element of type file with an onchange callback and also a button to trigger it

func CreateSaveFileButton ¶

func CreateSaveFileButton(text string, options map[string]any, saveFileCallback func(saveFile js.Value)) (button js.Value)

Create a button which calls showSaveFilePicker with a callback

func FNV1a32 ¶

func FNV1a32(data []byte) js.Value

32-bit variation of the FNV-1a non-cryptographic hashing algorithm which immediately/synchonously returns the hash as a JS ArrayBuffer

func FNV1a64 ¶

func FNV1a64(data []byte) js.Value

64-bit variation of the FNV-1a non-cryptographic hashing algorithm which immediately/synchonously returns the hash as a JS ArrayBuffer

func FuncOf ¶

func FuncOf(fn func(args []js.Value) any) js.Func

Wrap a Go function so it can be used by JS

func GetElementById ¶

func GetElementById(id string) js.Value

func HasOwn ¶

func HasOwn(object js.Value, str string) bool

func IsError ¶

func IsError(err js.Value) bool

func LoadJS ¶

func LoadJS(src string, onload func()) (classic js.Value)

Load a classic JS script with an onload callback

func LoadWASM ¶

func LoadWASM(str string, then func(), methods ...func(err js.Value) any)

Load a WASM module with a thenable chain

func Permissions ¶

func Permissions(str string, permissionsCallback func(permissionStatus js.Value))

Takes a permission descriptor, such as "camera", "microphone", "geolocation", etc., and a callback to handle the returned PermissionStatus object

func Prepend ¶

func Prepend(child js.Value)

func ProcOf ¶

func ProcOf(fn func(args []js.Value)) js.Func

Wrap a Go procedure so it can be used by JS

func SHA256 ¶

func SHA256(data []byte, shaCallback func(hash js.Value))

256-bit variation of SHA-2 which takes the data byte slice and callback to asynchonrously handle the hash as a JS ArrayBuffer

func SHA384 ¶

func SHA384(data []byte, shaCallback func(hash js.Value))

384-bit variation of SHA-2 which takes the data byte slice and callback to asynchonrously handle the hash as a JS ArrayBuffer

func SHA512 ¶

func SHA512(data []byte, shaCallback func(hash js.Value))

512-bit variation of SHA-2 which takes the data byte slice and callback to asynchonrously handle the hash as a JS ArrayBuffer

func SetFunc ¶

func SetFunc(str string, fn func(args []js.Value) any) js.Func

Expose a Go function to JS globally

func SetProc ¶

func SetProc(str string, fn func(args []js.Value)) js.Func

Expose a Go procedure to JS globally

func SetSimpleFunc ¶

func SetSimpleFunc(str string, fn func() any) js.Func

Expose a Go function which has no arguments to JS globally

func SetSimpleProc ¶

func SetSimpleProc(str string, fn func()) js.Func

Expose a Go procedure which has no arguments to JS globally

func SimpleFuncOf ¶

func SimpleFuncOf(fn func() any) js.Func

Wrap a Go function which has no arguments so it can be used by JS

func SimpleProcOf ¶

func SimpleProcOf(fn func()) js.Func

Wrap a Go procedure which has no arguments so it can be used by JS

func ThenableChain ¶

func ThenableChain(thenable js.Value, thenFunc func(arg js.Value) any, funcs ...func(arg js.Value) any) any

Function to handle the then, catch, and finally methods for a given thenable's thenable chain

Types ¶

This section is empty.

Source Files ¶

View all Source files
  • jsGo.go

Directories ¶

Path Synopsis
ref
Click to show internal directories.
Click to hide internal directories.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.