README
¶
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 ¶
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 AppendChild ¶
func CreateButton ¶
Create a button element with an onclick callback
func CreateElement ¶
func CreateElementNS ¶
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 ¶
32-bit variation of the FNV-1a non-cryptographic hashing algorithm which immediately/synchonously returns the hash as a JS ArrayBuffer
func FNV1a64 ¶
64-bit variation of the FNV-1a non-cryptographic hashing algorithm which immediately/synchonously returns the hash as a JS ArrayBuffer
func GetElementById ¶
func Permissions ¶
Takes a permission descriptor, such as "camera", "microphone", "geolocation", etc., and a callback to handle the returned PermissionStatus object
func SHA256 ¶
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 ¶
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 ¶
512-bit variation of SHA-2 which takes the data byte slice and callback to asynchonrously handle the hash as a JS ArrayBuffer
func SetSimpleFunc ¶
Expose a Go function which has no arguments to JS globally
func SetSimpleProc ¶
Expose a Go procedure which has no arguments to JS globally
func SimpleFuncOf ¶
Wrap a Go function which has no arguments so it can be used by JS
func SimpleProcOf ¶
Wrap a Go procedure which has no arguments so it can be used by JS
Types ¶
This section is empty.